| title | SDK Reference |
|---|---|
| description | Complete Python SDK API documentation |
Complete API documentation for the VortexDB Python client.
pip install vortexdbThe main client class for interacting with VortexDB.
from vortexdb import VortexDBVortexDB(
*,
grpc_url: str | None = None,
api_key: str | None = None,
timeout: float | None = None,
)Example:
# Explicit configuration
db = VortexDB(
grpc_url="localhost:50051",
api_key="secret",
timeout=60.0,
)
# Using environment variables
import os
os.environ["VORTEXDB_GRPC_URL"] = "localhost:50051"
os.environ["VORTEXDB_API_KEY"] = "secret"
db = VortexDB()Insert a vector with its payload into the database.
def insert(
self,
*,
vector: DenseVector,
payload: Payload,
) -> strExample:
point_id = db.insert(
vector=DenseVector([0.1, 0.2, 0.3, 0.4]),
payload=Payload.text("My document"),
)Insert multiple vectors in a single request.
def batch_insert(
self,
*,
items: list[tuple[DenseVector, Payload]],
) -> list[str]Example:
ids = db.batch_insert(items=[
(DenseVector([0.1, 0.2, 0.3]), Payload.text("doc one")),
(DenseVector([0.4, 0.5, 0.6]), Payload.text("doc two")),
])Retrieve a point by its ID.
def get(
self,
*,
point_id: str,
) -> Point | NoneExample:
point = db.get(point_id="550e8400-e29b-41d4-a716-446655440000")
if point:
print(f"Vector: {point.vector.to_list()}")
print(f"Payload: {point.payload.content}")Search for the k nearest neighbors to a query vector.
def search(
self,
*,
vector: DenseVector | None = None,
similarity: Similarity | None = None,
limit: int | None = None,
query: SearchQuery | None = None,
ef: int | None = None,
) -> List[str]Example:
# Using a SearchQuery
query = SearchQuery(DenseVector([0.1, 0.2, 0.3, 0.4]), Similarity.COSINE, 10)
results = db.search(query=query)
# Using individual args with ef
results = db.search(
vector=DenseVector([0.1, 0.2, 0.3, 0.4]),
similarity=Similarity.COSINE,
limit=10,
ef=200,
)Search against multiple query vectors in a single request.
def batch_search(
self,
*,
queries,
similarity: Similarity | None = None,
limit: int | None = None,
ef: int | None = None,
) -> List[List[str]]Accepts List[SearchQuery], List[(DenseVector, Similarity, int)], or bare List[DenseVector] with global similarity and limit.
Example:
results = db.batch_search(queries=[
SearchQuery(DenseVector([0.1, 0.2, 0.3]), Similarity.COSINE, 5),
(DenseVector([0.4, 0.5, 0.6]), Similarity.EUCLIDEAN, 3),
])Delete a point by its ID.
def delete(
self,
*,
point_id: str,
) -> NoneExample:
db.delete(point_id="550e8400-e29b-41d4-a716-446655440000")Close the gRPC connection.
def close(self) -> NoneExample:
db = VortexDB(grpc_url="localhost:50051", api_key="secret")
# ... use the client ...
db.close()The client supports the context manager protocol for automatic cleanup:
with VortexDB(grpc_url="localhost:50051", api_key="secret") as db:
point_id = db.insert(
vector=DenseVector([0.1, 0.2, 0.3]),
payload=Payload.text("Hello"),
)
# Connection automatically closedAn immutable dense vector of floating-point values.
from vortexdb import DenseVectorDenseVector(values: List[float] | Tuple[float, ...] | array | tensor)Raises:
TypeError: If values is not a supported sequence, array, or tensorValueError: If values is not one-dimensionalValueError: If values is emptyTypeError: If any value is not numeric
Example:
# From list
vec = DenseVector([0.1, 0.2, 0.3, 0.4])
# From tuple
vec = DenseVector((0.1, 0.2, 0.3, 0.4))
# Integers are converted to floats
vec = DenseVector([1, 2, 3, 4]) # -> [1.0, 2.0, 3.0, 4.0]
# NumPy arrays and tensors can be passed directly
vec = DenseVector(numpy_array)
vec = DenseVector(torch_tensor)
vec = DenseVector(tensorflow_tensor)
vec = DenseVector(jax_array)Convert the vector to a Python list.
def to_list(self) -> list[float]Example:
vec = DenseVector([0.1, 0.2, 0.3])
values = vec.to_list() # [0.1, 0.2, 0.3]Convert the vector to an array or tensor from an installed framework.
numpy_array = vec.to_numpy()
torch_tensor = vec.to_torch()
tensorflow_tensor = vec.to_tensorflow()
jax_array = vec.to_jax()The framework libraries are optional and are imported only when their conversion methods are called.
Access the vector values (read-only).
vec = DenseVector([0.1, 0.2, 0.3])
print(vec.values) # (0.1, 0.2, 0.3)Metadata associated with a vector.
from vortexdb import PayloadCreate a text payload.
@staticmethod
def text(content: str) -> PayloadExample:
payload = Payload.text("This is my document content")Create an image payload.
@staticmethod
def image(content: str) -> PayloadExample:
payload = Payload.image("path/to/image.jpg")Payload(content_type: ContentType, content: str)| Property | Type | Description |
|---|---|---|
content_type |
ContentType |
Type of payload |
content |
str |
Content string |
A point returned from the database (vector + payload + ID).
from vortexdb.models import Point| Property | Type | Description |
|---|---|---|
id |
str |
Point UUID |
vector |
DenseVector |
The vector values |
payload |
Payload |
Associated metadata |
Return a formatted string representation.
def pretty(self) -> strExample:
point = db.get(point_id="...")
print(point.pretty())
# Output:
# Point ID: 550e8400-e29b-41d4-a716-446655440000
# Vector: [0.1, 0.2, 0.3, 0.4]
# Payload Type: Text
# Payload Content: My documentEnum for distance/similarity metrics.
from vortexdb import Similarity| Value | Description |
|---|---|
Similarity.EUCLIDEAN |
L2 distance (straight line) |
Similarity.MANHATTAN |
L1 distance (city block) |
Similarity.HAMMING |
Count of differing elements |
Similarity.COSINE |
Angular distance |
Example:
from vortexdb import Similarity
# Use in search
results = db.search(
vector=DenseVector([0.1, 0.2, 0.3]),
similarity=Similarity.COSINE,
limit=5,
)Enum for payload content types.
from vortexdb.models import ContentType| Value | Description |
|---|---|
ContentType.TEXT |
Text content |
ContentType.IMAGE |
Image reference |
Bundles a search's parameters into a single object.
from vortexdb import SearchQuery
query = SearchQuery(DenseVector([0.1, 0.2, 0.3]), Similarity.COSINE, 10)
results = db.search(query=query)| Param | Type | Description |
|---|---|---|
vector |
DenseVector |
Query vector |
similarity |
Similarity |
Distance metric |
limit |
int |
Max results |
All exceptions inherit from VortexDBError.
from vortexdb import (
VortexDBError,
AuthenticationError,
NotFoundError,
InvalidArgumentError,
TimeoutError,
ServiceUnavailableError,
InternalServerError,
)| Exception | Description |
|---|---|
VortexDBError |
Base exception for all errors |
AuthenticationError |
Invalid or missing API key |
NotFoundError |
Requested resource not found |
InvalidArgumentError |
Invalid input parameters |
TimeoutError |
Request timed out |
ServiceUnavailableError |
Server is unavailable |
InternalServerError |
Server-side error |
Example:
from vortexdb.exceptions import (
AuthenticationError,
NotFoundError,
VortexDBError,
)
try:
point = db.get(point_id="nonexistent")
except NotFoundError:
print("Point does not exist")
except AuthenticationError:
print("Check your API key")
except VortexDBError as e:
print(f"Unexpected error: {e}")Internal configuration class (usually not used directly).
from vortexdb.config import VortexDBConfig
config = VortexDBConfig.from_env(
grpc_url="localhost:50051",
api_key="secret",
timeout=30.0,
)| Variable | Description | Default |
|---|---|---|
VORTEXDB_GRPC_URL |
Server address | localhost:50051 |
VORTEXDB_API_KEY |
Authentication key | None |
VORTEXDB_TIMEOUT |
Request timeout (seconds) | 30.0 |
The SDK is fully typed. Import types for type hints:
from typing import List, Optional
from vortexdb import VortexDB, DenseVector, Payload, Similarity
from vortexdb.models import Point, ContentType
def search_documents(
db: VortexDB,
query_vector: List[float],
limit: int = 10,
) -> List[Optional[Point]]:
results = db.search(
vector=DenseVector(query_vector),
similarity=Similarity.COSINE,
limit=limit,
)
return [db.get(point_id=pid) for pid in results]