Python client¶
A server, used from Python with the same calls as Vectrix. Needs the
client extra: pip install "vectrixdb[client]". See
Use it from Python, TypeScript, Go or Rust for the
walk-through and the other languages.
vectrixdb.client
¶
Talk to a VectrixDB server from Python, with the same calls as Vectrix.
from vectrixdb import connect
db = connect("https://vectors.example.com", key="...")
db.add_document("handbook", open("handbook.pdf", "rb").read(), "handbook.pdf")
for hit in db.search("handbook", "how long do refunds take"):
print(hit.score, hit.citation, hit.text)
Code written for a local Vectrix moves to a server by changing the line
that opens it: search returns the same Results with the same
Result objects, citations included. AsyncVectrixClient is the same
surface with await.
The client needs httpx (pip install "vectrixdb[client]"). It sends
the key in the api-key header, or a company sign-in token as a bearer
token, retries a 429 or a 503 up to three times honouring Retry-After,
and raises one refusal type per status, all of them RequestError:
try:
db.describe("nope")
except NotFoundError as refused:
print(refused.status, refused.message)
Behind a company's gateway, proxy or private CA:
db = connect(
"https://gateway.example.com",
key=KEY,
key_header="Ocp-Apim-Subscription-Key",
prefix="/acme",
gateway_paths="api/v1=/files/search, auth=/files/auth",
verify="/etc/ssl/company-ca.pem",
)
A key never travels over plain HTTP to another machine (allow_http=True
says it may), and no redirect is followed, so a key goes only to the address
it was given for. HTTPS_PROXY and NO_PROXY are honoured.
Every language's client offers this surface; sdk/CONTRACT.md in the
repository is the shared description.
VectrixClient
¶
Bases: _Calls
A VectrixDB server, used from Python.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Where the server is, |
required |
key
|
Optional[str]
|
An API key, sent in the |
None
|
token
|
Optional[str]
|
A company sign-in token, sent as a bearer token instead of a key. |
None
|
timeout
|
float
|
Seconds to wait for each request. |
30.0
|
transport
|
Any
|
An httpx transport, for tests that talk to an app in-process. |
None
|
allow_http
|
bool
|
Send the key or token over plain HTTP to another machine.
Off, only |
False
|
key_header
|
str
|
The header the key goes in, for a gateway with its own:
|
'api-key'
|
token_header
|
str
|
The header the token goes in, as |
'authorization'
|
headers
|
Optional[Mapping[str, str]]
|
More headers for every request, such as a gateway's subscription key alongside a person's token. |
None
|
prefix
|
Optional[str]
|
The path every route lives under, as the server's |
None
|
gateway_paths
|
Union[None, str, Mapping[str, str]]
|
Each route's gateway path, as the server's
|
None
|
verify
|
Any
|
A CA bundle to trust, for a private CA; |
True
|
cert
|
Any
|
A client certificate for a gateway that asks for one: a path,
or |
None
|
user_agent
|
Optional[str]
|
A wrapper's name and version, |
None
|
health()
¶
Whether the process answers.
ready()
¶
Whether the models are loaded; health() on a server with no /ready.
whoami()
¶
Who the server takes this client for.
collections()
¶
The collections this key may see.
describe(name)
¶
One collection.
create_collection(name, dimension=384, text_index=True, metric='cosine', description=None)
¶
A new collection; text_index makes hybrid search possible.
add_document(collection, data, filename=None, *, doc_id=None, metadata=None, chunk=None, chunk_size=None, overlap=None)
¶
Send a file's bytes; the server reads, cuts and embeds it.
add_texts(collection, points)
¶
Add texts the server embeds: [{"id": ..., "text": ..., "metadata": {...}}].
search(collection, query, limit=10, filter=None, rerank=False, mode='meaning')
¶
Search by meaning, or mode="hybrid" for meaning and exact words.
documents(collection)
¶
The documents the server keeps for a collection.
open_document(collection, doc_id)
¶
The Markdown a document was indexed from.
delete_document(collection, doc_id)
¶
Remove a document; returns how many chunks went.
add_source(collection, address, kind=None, every=None)
¶
A page or feed the collection keeps in sync with.
AsyncVectrixClient
¶
Bases: _Calls
VectrixClient with await; see that class for the arguments.
Collection
dataclass
¶
A collection as the server describes it.
Document
dataclass
¶
A document the server keeps, as documents() lists it.
Added
dataclass
¶
What add_document did.
Source
dataclass
¶
A place a collection keeps in sync with.
Refreshed
dataclass
¶
What refresh_sources did.
RequestError
¶
AuthError
¶
ForbiddenError
¶
NotFoundError
¶
ConflictError
¶
TooLargeError
¶
InvalidError
¶
BusyError
¶
ConnectionFailed
¶
Bases: VectrixError
The server could not be reached at all.
connect(url, key=None, token=None, *, timeout=30.0, **options)
¶
A server, by address and key: connect("https://vectors.example.com", key="...").
options are VectrixClient's: key_header, prefix,
gateway_paths, verify, cert, headers, allow_http,
user_agent.