polign — Python client for polign_db
A thin Python client for polign with two interchangeable transports:
- HTTP (
polign.Client) — zero dependencies, pure stdlib. Talks JSON to the server's HTTP listener (default:23000). - gRPC (
polign.GrpcClient) — install with the[grpc]extra. Talks to the gRPC listener (default:23001).
Both expose the same operations with identical semantics: the data plane
(put, put_many, get, get_many, list, delete, search) and
collection management (create_collection, get_collection,
list_collections, delete_collection, verify_collection).
Install
pip install polign # HTTP client, no dependencies
pip install 'polign[grpc]' # + gRPC transport (grpcio, protobuf)
Quick start
from polign import Client
client = Client("http://localhost:23000")
# Upsert. Collections are auto-created on first put, inferring their
# dimension from the vector. Values accept lists or numpy arrays.
client.put("docs", "doc-1", embedding, metadata={"title": "Cats", "url": "/cats"})
# Nearest-neighbour search (distance: smaller = closer)
for hit in client.search("docs", values=query_embedding, k=10):
print(hit.id, hit.distance, hit.metadata)
Swap in gRPC by changing two lines — the rest of the code is identical:
from polign import GrpcClient
client = GrpcClient("localhost:23001")
Operations
client.put("docs", "doc-1", values, metadata={"k": "v"}) # upsert, returns id
client.put_many("docs", [Vector(id="a", values=va), Vector(id="b", values=vb)])
# batch upsert, one request
v = client.get("docs", "doc-1") # Vector(id, values, metadata)
vs = client.get_many("docs", ["a", "b"]) # batch read, byte-exact values:
# never a compressed reconstruction
# (get may return one on a cold-
# flushed collection); unknown ids
# omitted, request order kept
page = client.list("docs", limit=100, offset=0) # page.vectors, page.total
page = client.list("docs", filter={"user_id": "u1"})
# filtered listing: same dict
# language as search; offset and
# page.total count matches only,
# so pagination works unchanged
client.delete("docs", "doc-1") # True; False if absent (no error)
hits = client.search("docs", values=q, k=10) # [Hit(id, distance, score, metadata)]
Search options
from polign import Fusion
client.search(
"docs",
values=q, # vector leg (either values or text required)
k=10,
ef=64, # HNSW beam width override (0 = server default)
filter={"lang": "en"}, # metadata predicate (see below)
text="quick brown fox", # BM25 leg (needs a segment index server-side)
fusion=Fusion(method="linear", alpha=0.6), # hybrid fusion; default RRF
cold=True, nprobe=8, # serve from object-store segments
)
text alone runs a pure BM25 search; values + text runs hybrid search
fused server-side. hit.score is the BM25/fused relevance (larger = better)
and is 0.0 on a pure vector search.
filter takes the same dict language on both transports: bare values are equality
(ANDed across keys); per-key operator objects ($eq, $ne, $in, $gt,
$gte, $lt, $lte, $exists) and the composers $and/$or/$not
express richer predicates:
filter={
"tenant": "acme",
"score": {"$gte": 0.5},
"$or": [{"lang": "en"}, {"lang": {"$exists": False}}],
}
Collection management
Collections are auto-created on first put, so most applications never touch
these. On a server started with -byo-store, the collection API additionally
binds collections to customer-owned buckets — and it takes an API key:
from polign import CollectionBackend
client = Client("https://db.example.com:23000", api_key="plgn_<key_id>_<secret>")
info = client.create_collection(
"docs", CollectionBackend(uri="s3://my-bucket/docs", role_arn="arn:aws:iam::…")
) # info.status: "active" or "pending"
info = client.get_collection("docs") # describe one collection
cols = client.list_collections() # every registered collection
client.verify_collection("docs") # re-run bucket verification now
client.delete_collection("docs") # unregister; bucket data is untouched
A pending collection activates automatically (within ~30s) once you finish
your side: write info.claim_token to info.claim_path in the bucket, or
attach the trust policy from client.backend_setup(uri) to the role. Without
-byo-store these endpoints raise NotEnabledError.
Auth
client = Client(
"https://db.example.com:23000",
api_key="plgn_<key_id>_<secret>", # sent as Authorization: Bearer
)
The data plane takes no credential; the API key guards the collection API on
-byo-store servers. With TLS enabled server-side, use an https:// URL
(HTTP) or pass credentials=grpc.ssl_channel_credentials() (gRPC).
Errors
All errors subclass polign.PolignError:
| Exception | HTTP | gRPC |
|---|---|---|
InvalidArgumentError |
400 | INVALID_ARGUMENT |
AuthenticationError |
401 | UNAUTHENTICATED |
PermissionDeniedError |
403 | PERMISSION_DENIED |
NotFoundError |
404 | NOT_FOUND |
NotOwnerError |
421 | FAILED_PRECONDITION |
RateLimitError |
429 | RESOURCE_EXHAUSTED |
ServerError |
5xx | INTERNAL |
ConnectionError |
— | UNAVAILABLE |
NotOwnerError.owner names the owning node in fleet mode — reconnect there
and retry.
Notes & caveats
Caveats shared by both transports:
- Embed documents and queries with the same model — distances are only meaningful within one embedding space.
- Auto-created collections use the server's default metric (L2) and hybrid IVF index; metric and index tuning are not yet exposed over the wire.
- Bulk loads should use
put_many— one request per batch instead of one per vector. The server validates the whole batch up front (id, non-empty values, uniform dimension, at most 5000 vectors per batch: an invalid batch applies nothing); on a rarer mid-batch failure earlier vectors remain applied, and since puts are idempotent upserts you simply retry the batch. Chunk larger loads into batches of 5000. - Metadata is
str -> stronly; filter scalars (numbers, booleans) compare against the stored string by their literal form ("0.5","true").
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 polign-0.2.1.tar.gz.
File metadata
- Download URL: polign-0.2.1.tar.gz
- Upload date:
- Size: 27.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d44a10b85105d9a6e394d8dc202f24b15d8df5a1b3fe415c2547ec386b01f31
|
|
| MD5 |
a0b128ba61ddd299456cfc1add1eac2f
|
|
| BLAKE2b-256 |
bd97a418b48b70b9ba67c7f8bb9e51e19f6eb13368e7ef09f0c295b67f954f41
|
Provenance
The following attestation bundles were made for polign-0.2.1.tar.gz:
Publisher:
release.yml on Polign/polign_db
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polign-0.2.1.tar.gz -
Subject digest:
1d44a10b85105d9a6e394d8dc202f24b15d8df5a1b3fe415c2547ec386b01f31 - Sigstore transparency entry: 2469286722
- Sigstore integration time:
-
Permalink:
Polign/polign_db@649e73c553da54fa4ab73712d0f22762bac918ce -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Polign
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@649e73c553da54fa4ab73712d0f22762bac918ce -
Trigger Event:
push
-
Statement type:
File details
Details for the file polign-0.2.1-py3-none-any.whl.
File metadata
- Download URL: polign-0.2.1-py3-none-any.whl
- Upload date:
- Size: 26.2 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 |
0031d478122c66b1ceab23733fb33c5d8c03bfee21202356e4639bab1d45604c
|
|
| MD5 |
f40f2862b2acde5883bebe51f96bfb19
|
|
| BLAKE2b-256 |
67241de75b6f400741a7f1856008be6c3dcd8de0c77f1105058099ab4ec83ae5
|
Provenance
The following attestation bundles were made for polign-0.2.1-py3-none-any.whl:
Publisher:
release.yml on Polign/polign_db
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polign-0.2.1-py3-none-any.whl -
Subject digest:
0031d478122c66b1ceab23733fb33c5d8c03bfee21202356e4639bab1d45604c - Sigstore transparency entry: 2469286779
- Sigstore integration time:
-
Permalink:
Polign/polign_db@649e73c553da54fa4ab73712d0f22762bac918ce -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Polign
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@649e73c553da54fa4ab73712d0f22762bac918ce -
Trigger Event:
push
-
Statement type: