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_contentis stored in the metadata keytext. That is the field the server's BM25 index reads, so hybrid search needs no extra setup. Change it withtext_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_keysentry, so reads restore the original value. Those keys cannot be filtered on. textand_lc_json_keysare reserved; using them in metadata raisesValueError.
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.
Lexical and hybrid search
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-storecollection 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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_polign-0.1.0.tar.gz.
File metadata
- Download URL: langchain_polign-0.1.0.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f96d7b191c33844ae7772b7ced2fcdde06c6009354896bfa1af06215779d40ee
|
|
| MD5 |
98da1fecf6a7a805bf9792f8014071b1
|
|
| BLAKE2b-256 |
aa858fd15f5e1a2fa1b6ce69695ffe5126a0e96c9beb1be5fd13a4dbc8079648
|
Provenance
The following attestation bundles were made for langchain_polign-0.1.0.tar.gz:
Publisher:
python-publish.yml on Polign/polign
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_polign-0.1.0.tar.gz -
Subject digest:
f96d7b191c33844ae7772b7ced2fcdde06c6009354896bfa1af06215779d40ee - Sigstore transparency entry: 2790171404
- Sigstore integration time:
-
Permalink:
Polign/polign@7fe73d077924e5605104c1df33469c4e22a7e80e -
Branch / Tag:
refs/tags/langchain/v0.1.0 - Owner: https://github.com/Polign
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7fe73d077924e5605104c1df33469c4e22a7e80e -
Trigger Event:
push
-
Statement type:
File details
Details for the file langchain_polign-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_polign-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8926882488765b5995bd59b0db547003196e92b851b6e37351d5bfcc67ae7636
|
|
| MD5 |
f343490c5b0ab7cf7814f2dfec10b3a7
|
|
| BLAKE2b-256 |
4220eb332785923b066382f3754422d074804ac878239d0eb96d4e647f361573
|
Provenance
The following attestation bundles were made for langchain_polign-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on Polign/polign
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_polign-0.1.0-py3-none-any.whl -
Subject digest:
8926882488765b5995bd59b0db547003196e92b851b6e37351d5bfcc67ae7636 - Sigstore transparency entry: 2790171460
- Sigstore integration time:
-
Permalink:
Polign/polign@7fe73d077924e5605104c1df33469c4e22a7e80e -
Branch / Tag:
refs/tags/langchain/v0.1.0 - Owner: https://github.com/Polign
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7fe73d077924e5605104c1df33469c4e22a7e80e -
Trigger Event:
push
-
Statement type: