Skip to main content

langchain-opensolr

LangChain integration for Opensolr — managed Apache Solr with server-side embeddings and native hybrid (BM25 + kNN) search.

Product page: opensolr.com/langchain · Platform: opensolr.com (managed Solr hosting since 2011 — free 15-day trial, no card)

No local embedding model. No third-party embedding API key. One set of credentials, and the vectors are computed on Opensolr's GPU infrastructure (multilingual E5-large-instruct, 1024 dimensions, cosine).

pip install langchain-opensolr

The whole tutorial

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"],
    metadatas=[{"category": "search"}, {"category": "animals"}],
)

docs = vs.similarity_search("how do lexical and semantic search combine?", k=1)
print(docs[0].page_content)

That's it — no embedding model was configured, because embedding happens on the server at both index and query time.

Hybrid search

Pure vector search fails on exact identifiers; pure BM25 fails on meaning. Opensolr's {!hybrid} query parser fuses both scores per document:

docs = vs.similarity_search(
    "affordable restaurants",
    k=5,
    hybrid=True,
    mode="union",     # union | keywords_required | meaning_required | intersection
    alpha=0.5,        # 0 = all semantic … 1 = all lexical
)

Metadata filters

vs.similarity_search("search engines", k=5, filter={"category": "search"})
vs.similarity_search("anything", k=5, filter='meta_rank:[2 TO *]')   # raw Solr fq

Metadata round-trips losslessly (stored as JSON alongside filterable meta_* fields).

As a retriever, in any chain

retriever = vs.as_retriever(search_kwargs={"k": 5, "hybrid": True})

Standalone embeddings

Use Opensolr's embedding endpoint with any other LangChain component:

from langchain_opensolr import OpensolrEmbeddings

emb = OpensolrEmbeddings(email="you@example.com", api_key="...", index="mysite__dense")
emb.embed_query("budget-friendly dining")   # -> 1024 floats

Notes

  • Vector-enabled indexes run on Opensolr's Solr 9.x environments — currently us (Chicago), de (Germany), fi (Finland). Pass location= to choose. The list is fetched live from the platform, so new regions work without a package upgrade — and additional dedicated regions can be deployed on request (paid add-on): support@opensolr.com.
  • A free Opensolr account (15-day trial, no card) includes an AI quota that comfortably covers this README end to end: opensolr.com.
  • Full platform docs: AI & Vector Search.

Development

pip install -e . pytest
pytest tests/unit_tests
OPENSOLR_EMAIL=... OPENSOLR_API_KEY=... OPENSOLR_INDEX=... pytest tests/integration_tests

MIT license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_opensolr-0.1.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_opensolr-0.1.1-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file langchain_opensolr-0.1.1.tar.gz.

File metadata

  • Download URL: langchain_opensolr-0.1.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.12

File hashes

Hashes for langchain_opensolr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f88a4e1d00b4926c15b82acca92ead22a8d955fbefd40afa03eb20ed437e1cb9
MD5 4f083f9392002fc06cd1e56a25e29b68
BLAKE2b-256 bcb819b255c586836ce67278cf6884576b8091587db25327c379203710f43008

See more details on using hashes here.

File details

Details for the file langchain_opensolr-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_opensolr-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da6c90181d8e4c2d75053c0328b3997cb0fa0b538f6c6a5fd9730e20405e34fa
MD5 888e3cea2a001e60a4f28c5c25d79662
BLAKE2b-256 a85a47960e8ffcc2add14a1bcfde6c6e08cbb1185aa8dcd07f3ad1cedb11c694

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page