Skip to main content

langchain-polign

LangChain vector store for polign_db.

pip install langchain-polign

Usage

from langchain_openai import OpenAIEmbeddings
from langchain_polign import PolignVectorStore

store = PolignVectorStore(
    embedding=OpenAIEmbeddings(),
    collection="docs",
    url="http://localhost:23000",   # api_key="plgn_..." when the server requires one
)

store.add_texts(
    ["cats purr", "dogs bark"],
    metadatas=[{"lang": "en", "score": 0.9}, {"lang": "en", "score": 0.4}],
)

store.similarity_search("purring", k=1, filter={"score": {"$gte": 0.5}})
store.similarity_search_with_relevance_scores("barking", k=2)
store.max_marginal_relevance_search("animals", k=2, fetch_k=10)
store.get_by_ids(["..."])
store.delete(["..."])
store.delete(filter={"lang": "fr"})

retriever = store.as_retriever(search_kwargs={"k": 4, "filter": {"lang": "en"}})

Collections are created on the first write and take their dimension from the first vector. filter is polign's metadata predicate language: a plain mapping is equality ANDed across keys; $eq, $ne, $in, $gt, $gte, $lt, $lte, $exists and the composers $and, $or, $not build richer predicates.

Pass client= with an existing polign.Client or polign.GrpcClient to reuse a connection or to use the gRPC transport (pip install "langchain-polign[grpc]").

How documents are stored

  • The polign record id is the document id.
  • page_content is stored in the metadata key text. That is the field the server's BM25 index reads, so hybrid search needs no extra setup. Change it with text_key= only if the server is configured for another field.
  • Every other metadata entry is stored as polign metadata. Strings, numbers, booleans, and flat lists of those pass through unchanged and can be filtered on. Nested objects, None, and lists of objects are JSON-encoded as strings and their keys are recorded in the reserved _lc_json_keys entry, so reads restore the original value. Those keys cannot be filtered on.
  • text and _lc_json_keys are reserved; using them in metadata raises ValueError.

Scores

similarity_search_with_score returns the collection distance, smaller is closer. similarity_search_with_relevance_scores maps it to [0, 1] using the metric the server reports: 1 - d for cosine, 1 / (1 + d) for L2. Pass relevance_score_fn= to the constructor to use your own mapping.

store.lexical_search("brown fox", k=5)            # BM25 only
store.hybrid_search("brown fox", k=5, alpha=0.6)  # vector + BM25, linear fusion
store.hybrid_search("brown fox", k=5)             # reciprocal rank fusion

Both return (document, score) with larger meaning better. They need a server with a segment store (polign-server -store ...); an in-memory server raises polign.InvalidArgumentError.

The BM25 index is built when the server persists a segment, so records are lexically searchable only after the next segment is written and the cold searchers pick it up (-segment-refresh, 30 seconds by default). Expect roughly half a minute between a write and its first lexical or hybrid hit with default settings; vector search sees the write immediately.

Limits

  • Deleting a whole collection needs the server's -byo-store collection API; delete(filter=...) removes matching records instead.
  • MMR reads the candidates' vectors back with one batch call, because search hits do not carry vectors.
  • Writes are sent in batches of 5,000 records, the server's limit.

Development

pip install -e ".[grpc]" pytest langchain-tests
pytest tests/unit_tests
pytest tests/integration_tests      # boots a polign-server; see tests/integration_tests/conftest.py

License

Apache License 2.0. See LICENSE.

Metadata

Release files for langchain-polign 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-polign 0.1.0
File Size Uploaded Provenance Actions
langchain_polign-0.1.0.tar.gz 14.4 kB With provenance Details for langchain_polign-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-polign 0.1.0
File Interpreter ABI Platform Actions
langchain_polign-0.1.0-py3-none-any.whl Python 3 none any Details for langchain_polign-0.1.0-py3-none-any.whl

Total release size: 26.9 kB

Release files / langchain_polign-0.1.0.tar.gz

Download URL langchain_polign-0.1.0.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f96d7b191c33844ae7772b7ced2fcdde06c6009354896bfa1af06215779d40ee
BLAKE2b-256 checksum
How to use checksums
aa858fd15f5e1a2fa1b6ce69695ffe5126a0e96c9beb1be5fd13a4dbc8079648
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / langchain_polign-0.1.0-py3-none-any.whl

Download URL langchain_polign-0.1.0-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8926882488765b5995bd59b0db547003196e92b851b6e37351d5bfcc67ae7636
BLAKE2b-256 checksum
How to use checksums
4220eb332785923b066382f3754422d074804ac878239d0eb96d4e647f361573
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Security for langchain-polign 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for langchain_polign-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page