Client library for the Casper Vector Database
Project description
Casper Python client
Python client library for the Casper Vector Database.
Installation
pip install casper-client
Quick start
import math
import os
import random
import time
from casper_client import CasperClient, VectorPoint
def gen_vec(dim: int) -> list[float]:
vec = [random.uniform(-1.0, 1.0) for _ in range(dim)]
norm = math.sqrt(sum(x * x for x in vec)) or 1.0
return [x / norm for x in vec]
def main() -> None:
host = os.getenv("CASPER_HOST", "http://127.0.0.1")
http_port = int(os.getenv("CASPER_HTTP_PORT", "8080"))
with CasperClient(host=host, http_port=http_port) as client:
client.health()
collection = "example_collection"
dim = 128
client.create_collection(collection, dim=dim, max_size=10_000)
# Upsert vectors (batch)
points = [VectorPoint(id=vid, vector=gen_vec(dim)) for vid in range(1, 6)]
client.upsert_vectors(collection, points)
# Mixed insert + delete
batch = [VectorPoint(id=vid, vector=gen_vec(dim)) for vid in range(6, 11)]
client.batch_update(collection, insert=batch, delete=[])
# Create HNSW index — build is asynchronous on the server.
client.create_hnsw_index(
collection,
metric="inner-product",
quantization="i8",
m=16,
m0=32,
ef_construction=200,
normalization=True,
)
# Wait until the index is ready before searching.
while not client.get_collection(collection).has_index:
time.sleep(0.2)
hits = client.search(collection, query=gen_vec(dim), limit=10)
for i, h in enumerate(hits[:5], start=1):
print(f" {i}. id={h.id} score={h.score}")
client.delete_vectors(collection, [10])
client.delete_index(collection)
client.delete_collection(collection)
if __name__ == "__main__":
main()
Examples
Run the example provided in this repository:
python examples/example.py
The example demonstrates:
- Collection management (create, delete, list, info)
- Vector operations:
upsert_vectors(batch PUT),delete_vectors(batch by id),batch_update(mixed insert+delete),get_vector - Mute / unmute (
mute_collection,unmute_collection) - Index management (
create_hnsw_index,delete_index) — the index build is asynchronous; the server returns 202 and the client should pollget_collection().has_index - Search (
search, with optionalef_searchoverride). Binary response format is decoded automatically.
License
Licensed under the Apache License Version 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
casper_client-0.1.1.tar.gz
(11.3 kB
view details)
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 casper_client-0.1.1.tar.gz.
File metadata
- Download URL: casper_client-0.1.1.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.7 Linux/6.17.0-23-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c452e0d62a0ded71436550ab8160a9e74d1534629cbd40c64bb60762bae489b
|
|
| MD5 |
2c53fc42bac22dc43e786bb8780d3bd8
|
|
| BLAKE2b-256 |
3cbff867dfbf4ca18dcf28480fd48c079e6ffef0c449d193fd70536135a1ea42
|
File details
Details for the file casper_client-0.1.1-py3-none-any.whl.
File metadata
- Download URL: casper_client-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.7 Linux/6.17.0-23-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bcbfe5b5b0a254768d21b7579eae800d6e9ab69718b275e93e4840674c76334
|
|
| MD5 |
ee76a5b26a5a48ef63ec4ac145df9e6d
|
|
| BLAKE2b-256 |
281f7b4c68487a1ec45ec404db80b2e118ba81d12c43df56e5d89517e96581fd
|