Skip to main content

langchain-opensolr

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

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 — locations us (Chicago), de (Germany), fi (Finland). Pass location= to choose.
  • 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.0.tar.gz (11.7 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.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langchain_opensolr-0.1.0.tar.gz
  • Upload date:
  • Size: 11.7 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.0.tar.gz
Algorithm Hash digest
SHA256 a36131aadb84bb0eba02c87c9197f4b8925a550c841b5460ae7fc0c6d2197bc2
MD5 5cce92ae48c4c9ea88179a8cc31d2bbb
BLAKE2b-256 4d495f83744fd0e8c85602de4d1207c96be1fae2ff79148964f337a57aaf3b10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_opensolr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f1b74482af6f7ac3835a945b1f878207ac78c91fed19d5f3b29b4d2ba0e889c
MD5 71b57c1533e73cb9fc96474f39bb2e13
BLAKE2b-256 0c546ea668e2a775fca6b374ae25a0f9f9128fc3d7e2949fc68667802590a36d

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