Python: Vectors and embeddings
Embed text, store vectors with metadata and run similarity search with the Python SDK.
await sovaria.vector_upsert("articles", [
{"id": "a1", "text": "How to reset your password", "metadata": {"lang": "en"}},
{"id": "a2", "text": "Exporting invoices as PDF", "metadata": {"lang": "en"}},
])
hits = await sovaria.vector_search("articles", "forgot my login", top_k=3, metadata_filter={"lang": "en"})#Methods
sovaria.vector_delete_collection
Delete an entire vector collection.
await sovaria.vector_delete_collection(
collection: str,
) -> dict[str, Any]Parameters
collectionstrrequired
Returns
dict[str, Any]
sovaria.vector_delete_record
Delete a record from a vector collection.
await sovaria.vector_delete_record(
collection: str,
record_id: str,
) -> dict[str, Any]Parameters
collectionstrrequiredrecord_idstrrequired
Returns
dict[str, Any]
sovaria.vector_embed
Generate embeddings for one or more texts.
await sovaria.vector_embed(texts: list[str]) -> dict[str, Any]Parameters
textslist[str]required
Returns
dict[str, Any]
{
"vectors": [
[
0.012,
-0.044,
"…"
],
[
0.031,
0.007,
"…"
]
],
"dim": 1536,
"count": 2,
"model": "openai/text-embedding-3-small@1536"
}sovaria.vector_list_collections
List vector collections in the current project scope.
await sovaria.vector_list_collections() -> dict[str, Any]Returns
dict[str, Any]
{
"collections": [
{
"name": "help-articles",
"dim": 1536,
"size": 2,
"model": "openai/text-embedding-3-small@1536",
"app_search": false
}
],
"model": "openai/text-embedding-3-small@1536",
"semantic": true
}sovaria.vector_list_records
List records stored in a vector collection.
await sovaria.vector_list_records(
collection: str,
*, limit: int | None = None,
offset: int | None = None,
) -> dict[str, Any]Parameters
collectionstrrequiredlimitint | NoneoptionaldefaultNoneoffsetint | NoneoptionaldefaultNone
Returns
dict[str, Any]
{
"collection": "help-articles",
"dim": 1536,
"total": 2,
"records": [
{
"id": "a1",
"text": "How to reset your password",
"metadata": {
"lang": "en"
}
}
]
}sovaria.vector_search
Search a vector collection.
await sovaria.vector_search(
collection: str,
query: str,
*, top_k: int = 5,
metadata_filter: dict[str, Any] | None = None,
mode: str | None = None,
) -> dict[str, Any]mode: "vector" (meaning), "keyword" (the words, BM25) or "hybrid" (both, fused); default vector with a real embedding model, hybrid with local hashing.
Parameters
collectionstrrequired- Collection name.
querystrrequired- Text to search for.
top_kintoptionaldefault5- How many results.
metadata_filterdict[str, Any] | NoneoptionaldefaultNone- Exact matches on metadata.
modestr | NoneoptionaldefaultNone
Returns
dict[str, Any]
{
"results": [
{
"id": "a1",
"text": "How to reset your password",
"metadata": {
"lang": "en"
},
"score": 0.83
}
],
"count": 1,
"mode": "vector",
"model": "openai/text-embedding-3-small@1536",
"semantic": true
}sovaria.vector_upsert
Embed and upsert documents into a vector collection.
await sovaria.vector_upsert(
collection: str,
docs: list[dict[str, Any]],
) -> dict[str, Any]Parameters
collectionstrrequireddocslist[dict[str, Any]]required
Returns
dict[str, Any]
{
"inserted": 2,
"updated": 0,
"dim": 1536,
"size": 2
}