Skip to main content

Python client for the LSM-Vec vector database HTTP API

Project description

lsmvec-client — Python client for LSM-Vec

A thin, dependency-free Python client for the LSM-Vec vector database HTTP API. Uses only the Python standard library; numpy is optional (a convenience for bulk_build).

Install

pip install lsmvec-client            # core, zero dependencies
pip install lsmvec-client[numpy]     # + numpy for bulk_build convenience

Or run straight from the repo without installing:

import sys; sys.path.insert(0, "sdk/python")
from lsmvec_client import Client

Quickstart

from lsmvec_client import Client

client = Client(
    api_key="sk-live-...",                 # sent as Bearer token
    base_url="https://api.lsmvec.com",     # or http://localhost:8000 for local
)

# Insert with optional metadata
client.insert(1, [0.10, 0.20, 0.30, ...], metadata={"title": "intro"})

# Search
hits = client.search([0.10, 0.20, 0.30, ...], k=10)
for h in hits:
    print(h.id, h.distance)

# Filtered search (metadata predicate, same syntax as the HTTP API)
hits = client.search(
    [0.10, 0.20, ...], k=10,
    filter={"$and": [{"category": {"$eq": "docs"}}]},
)

Bulk build (initial load)

The fastest way to populate a new, empty database. Builds the whole index in memory (RNN-Descent) and writes it in one pass — 2-3× faster than per-vector inserts and higher recall. Initial-load only; the DB must be empty.

import numpy as np
from lsmvec_client import Client

client = Client(base_url="http://localhost:8000")

vectors = np.random.rand(100_000, 128).astype(np.float32)
report = client.bulk_build(vectors, threads=4)
print(report)   # {'n': 100000, 'elapsed_ms': ..., 'vectors_per_sec': ..., 'threads': 4}

bulk_build also accepts a plain list of equal-length float lists (no numpy required):

rows = [[0.1, 0.2, 0.3, 0.4], [0.5, 0.6, 0.7, 0.8], ...]
client.bulk_build(rows)

For incremental updates on an already-built index, use insert() / upsert() instead — bulk_build rejects a non-empty DB.

API

Method HTTP Notes
insert(id, vector, metadata=None) POST /v1/vectors metadata is any JSON object
upsert(id, vector) PUT /v1/vectors/:id insert-or-replace vector
get(id) -> dict GET /v1/vectors/:id {"id", "vector"}
delete(id) DELETE /v1/vectors/:id
get_payload(id) -> dict GET /v1/vectors/:id/payload
set_payload(id, payload) PUT /v1/vectors/:id/payload replace
merge_payload(id, partial) PATCH /v1/vectors/:id/payload RFC 7396 merge
search(vector, k=10, ef_search=None, filter=None) -> [SearchResult] POST /v1/search
bulk_build(vectors, dim=None, threads=0) -> dict POST /v1/build/bulk empty DB only
stats() -> dict GET /v1/stats tombstone / bloom counters
health() -> bool GET /health
ready() -> bool GET /ready DB open + responsive

search returns a list of SearchResult(id: int, distance: float).

Errors

HTTP status codes map to typed exceptions (all subclass LSMVecError):

Status Exception
400 InvalidArgument
401 Unauthorized
404 NotFound
413 PayloadTooLarge
429 RateLimited
5xx ServerError
from lsmvec_client import NotFound

try:
    client.get(999999)
except NotFound:
    print("no such id")

Notes

  • Vectors are stored with 8-bit scalar quantization (SQ8). get() returns the dequantized vector, which differs from the input by up to ~range/255 per element. Distances and recall are computed on the quantized form.
  • id is a 64-bit unsigned integer.
  • The client is synchronous and connection-per-request (stdlib urllib). For high-throughput batch ingestion, prefer bulk_build over a loop of insert.

Testing

Against a running server:

LSMVEC_TEST_URL=http://localhost:8000 LSMVEC_TEST_DIM=8 \
    python3 sdk/python/tests/test_client.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lsmvec_client-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lsmvec_client-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file lsmvec_client-0.1.0.tar.gz.

File metadata

  • Download URL: lsmvec_client-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for lsmvec_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0ac6a314a1ffe0ad608399299de47094255f9863f637a2e4e1a3c3bafc6a0ff
MD5 92fe0f532d3d6d3400454cc92247cc1c
BLAKE2b-256 1de2a1d003c23a32f3fc578d6489dc67ae6d6354e706a49be746a2e49177921c

See more details on using hashes here.

File details

Details for the file lsmvec_client-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lsmvec_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for lsmvec_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 afeca64783baed701902dc761bbd3b97749fc293c4fa7836c20ec11ae9f181e3
MD5 6b1860fba2f971687e6483977cb3bf19
BLAKE2b-256 4042df8d2a60e1219546fac4972c3f772d4b273cec3df349e1e9a591472895a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page