RAG on managed Apache Solr — one pip install
Opensolr is now a native LangChain vector store. Server-side GPU embeddings, hybrid BM25 + kNN search, and a managed Solr 9.00 to 10.00 index behind every retriever — with zero embedding models to configure.
The whole tutorial
This is not a teaser — this is the entire integration. No embedding model, no API key juggling, no schema design.
from langchain_opensolr import OpensolrVectorStore vs = OpensolrVectorStore( index="mysite__dense", # vector-enabled Opensolr index email="you@example.com", api_key="YOUR_OPENSOLR_API_KEY", create_if_missing=True, # provisions the index on first use ) vs.add_texts(["Hybrid search fuses BM25 with vector similarity", "Cats sleep sixteen hours a day"]) docs = vs.similarity_search("how do lexical and semantic search combine?")
No embedding model was configured, because embedding happens server-side — on Opensolr's GPU infrastructure, at both index and query time.
Try it without an account
A public demo account, so the quickstart above runs before you decide anything.
export OPENSOLR_EMAIL=mcp@opensolr.com export OPENSOLR_API_KEY=420b8b23e7b12dc8ab838932145a5065
The index mcp_demo_d1__dense is already loaded with 300 news articles, so search, filtering and grounded answers work the moment you connect. You also get the write path: create your own index on the account, ingest into it and query it. Deletion is not available on this shared key — no index here can be deleted or reconfigured by hand. Whatever you create is removed automatically after 3 days.
- Anything you create there is deleted after 3 days. Automatically, without warning or export — indexes you created included.
- The account is shared with everyone reading this page. Your index is visible to them and they can add documents to it, as you can to theirs. Nobody can delete or reconfigure an index here — that is switched off for this key — but never put anything real, private or client-owned in it.
- The limits are per index, and deliberately small. 200 MB of bandwidth and 50 MB of disk per index. Bandwidth is the one you will hit first: it covers a demo, a tutorial and a proof of concept, and it will not carry an application.
When you want an index that is private, yours and still there next week, get your own key — the free plan is free forever, no card — and change the two variables above. Nothing else in your code changes.
What happens under the hood
Your app talks to one package. The package talks to a managed pipeline that already exists.
Why this is different
Most vector stores in the LangChain directory make you bring your own embedding model and run your own database. This one doesn't.
Zero embedding config
The shortest constructor in the directory: api_key + index. Texts and queries are embedded server-side on GPU — no OpenAI key, no local model, no sentence-transformers install.
True hybrid search
Pure vector search fails on exact identifiers; pure BM25 fails on meaning. hybrid=True fuses both scores per document, with four modes and a tunable alpha balance.
Lossless metadata + filters
Metadata round-trips exactly as you stored it, and filters work both ways: filter={"category": "docs"} or any raw Solr fq expression when you need real power.
Auto index provisioning
create_if_missing=True provisions a vector-enabled Opensolr Index on first use, in a vector region from the live list (client.vector_regions()) — name the environment, or a short form like us. No servers, no schema files, no ZooKeeper.
Drops into any chain
vs.as_retriever() and it's a standard LangChain retriever — RAG tutorials, agents, LangGraph, LCEL pipelines. Everything that accepts a retriever accepts this.
Plain Apache Solr underneath
Every index is also a real Solr core with the native /select API — facets, highlighting, spellcheck, stats. When you outgrow the vector-store interface, nothing is locked away.
Two lines you'll actually use
Hybrid retrieval with metadata filters, and the retriever that plugs into every RAG example ever written.
Hybrid search, filtered
docs = vs.similarity_search(
"affordable restaurants",
k=5,
hybrid=True, # BM25 + kNN, fused
mode="union", # or keywords_required,
# meaning_required,
# intersection
alpha=0.5, # semantic ↔ lexical
filter={"city": "Cluj"},
)As a retriever, in any chain
retriever = vs.as_retriever(
search_kwargs={"k": 5, "hybrid": True}
)
# now use it anywhere LangChain
# expects a retriever:
chain = (
{"context": retriever, "question": ...}
| prompt | llm
)Search with a photo
Hand the store a picture instead of a query. Opensolr reads it three ways — what it depicts, the text printed on it, and any barcode or QR code — then searches with those words. Nothing new is stored in Solr; the image simply becomes a query.
# What the picture reads as — labels, OCR text, barcodes. No search yet: read = vs.image_to_words("shelf-photo.jpg") # path, bytes, or base64 # {'text': 'red running shoe', 'mode': 'clip', # 'labels': ['running shoe', 'sneaker'], 'codes': ['0123456789012']} # Search the index with the picture — pick which reading drives it: docs = vs.search_by_image("shelf-photo.jpg", k=4) # engine's choice docs = vs.search_by_image("shelf-photo.jpg", using="meaning") # what it depicts docs = vs.search_by_image("shelf-photo.jpg", using="text") # OCR text only docs = vs.search_by_image("shelf-photo.jpg", using="code") # exact barcode / QR docs = vs.search_by_image("shelf-photo.jpg", using="all") # labels + OCR + codes
Every tuning option similarity_search takes — hybrid, mode, alpha, fresh_bias, filter — applies here too: an image query runs through the exact same pipeline a text query does.
Local files, PDFs page by page
Each file is read on Opensolr’s servers — its text, the text in its pictures (OCR, more than 100 languages), a short description of the pictures without text — and a PDF becomes one document per page, so a search lands on the page that answers it instead of a 200-page file that mentions it somewhere. Word, RTF, OpenDocument, text, HTML and scanned pictures are one document each. In search results each PDF then comes back once, as its best page, with a link that opens it right there.
from langchain_opensolr import OpensolrLoader # Files read on Opensolr: one Document per PDF page, scans through OCR loader = OpensolrLoader("./contracts", index="mysite__dense", email="you@example.com", api_key="...", pattern="*.pdf") docs = loader.load() # metadata: source, page, is_ocr, language # Or straight into the store — no splitter, PDFs page by page: vs.add_files("./contracts", pattern="*.pdf", metadata={"team": "legal"}, wait=True) # A PDF comes back as its best page, with a link to it; a period narrows the search docs = vs.similarity_search("termination notice period", k=4, hybrid=True, date_from="2025-01-01") docs[0].metadata["page_url"] # https://.../msa.pdf#page=14 (+ more_pages, document_id)
The bytes travel once: a file the account already sent is not uploaded again, and sending the same files again replaces their documents. Pictures read by OCR count 0.5 of an AI request each; a file read before is free. Big files are read in the background: whatever is still being read comes back as pending — run again to finish them.
Index requirements, checked for you
Data Ingestion, vector and hybrid search and PDF pages need an index in a vector region that runs the Opensolr vector schema. Every index the package creates has it. On any other index the package checks once, with one request — never on every search — and tells you exactly what the index cannot do and how to fix it.
from langchain_opensolr import OpensolrSchemaError vs.check_schema() # ready, capabilities, problems, fix vs.apply_schema() # installs the Opensolr vector schema (force=True if it holds documents) try: vs.add_files("./contracts") except OpensolrSchemaError as e: print(e) # Index 'my_index' cannot take documents or files through Data Ingestion. Index my_index is on # IT-SOLR-9-6 (Milano, Italy), which is not a vector region: ... Create a new index in one of # the vector regions (...), for example with create_index, and send your documents there.
- Only what cannot work is stopped. Data Ingestion on an index outside the vector regions, and vector or hybrid search on an index without the vector field, are refused with the exact reason before anything is uploaded or embedded. Keyword search runs on any index that has
title,descriptionandtextfields. vs.check_schema()answers whether the index is ready, what it can do (ingestion, vector search, PDF pages, keyword search), what differs from the Opensolr vector schema, and the fix.vs.apply_schema()installs the Opensolr vector schema, the configuration every Opensolr vector index runs, so everything above works on the index. It replaces the index configuration: on an index that already holds documents it needsforce=True, and those documents must be sent again.- An index outside the vector regions cannot take it. Create a new index (
create_index) in one of the regions ofclient.vector_regions()and send your documents there.
Your Search Tuning follows you
Relevance is configured once, in your Control Panel — not re-implemented in every codebase.
- Saved per index: everything you set in Index Settings → Search Tuning (semantic↔lexical balance, field weights, minimum match, search mode, vector candidate pool, content quality boost) is stored with your index.
- Applies automatically here: every search and every RAG answer from this integration runs through the same tuned pipeline as your hosted search page — change a slider in the Control Panel and the very next query uses it. No redeploy, no code change.
- Overridable per call:
tuning={"search_mode": "keywords_required", "fw_title": 0.2, "mm": "strict"}beats the saved settings for that one request. Defaults match the platform exactly when you send nothing. - Fresh Results Bias: pass
fresh_biasto rank newer documents higher — scores are multiplied by a recency curve oncreation_date. It re-orders and never filters: the hit count is unchanged and undated documents keep their place. This is the same control visitors get as the Fresh toggle on the hosted search page. Not to be confused withfreshness_boost, which is a hard date window in days and does remove results.
Tested on our own production index
Every release runs a live end-to-end suite against real Opensolr infrastructure — no mocks.
- Full write path through the async Data Ingestion queue: queued → server-side embeddings & enrichment → searchable, with metadata and id round-trips verified. Metadata lands in typed Solr fields; the suffixes and what they enable are in the Site Search Schema Reference.
- Real-corpus retrieval against a replica of opensolr.com's own search index: pure-semantic hits with zero keyword overlap („how do I get my data back after a disaster” → backup docs), cross-lingual queries (non-English → English content), all hybrid modes and the full alpha range.
- PDF ingestion via
rtf:true: server-side text extraction and content-type detection, then semantic retrieval from the extracted content. - Grounded RAG answers: one call runs hybrid retrieval and feeds the top hits to the LLM (configurable docs/words, custom instruction) — verified with a question answerable only from the ingested PDF.
Open source
This integration is free, MIT licensed and maintained in the open. Browse the code, open an issue, or sponsor the work that keeps it current.
Build your first RAG pipeline tonight
Free forever plan, no credit card. The included AI quota comfortably covers the whole tutorial — index, embed, search, and retrieve.
Need a vector-enabled environment in another region? We deploy them on request — dedicated, in the region you choose (paid add-on).