Reference
db.search_batch
Run several searches in one call.
db.search_batch(queries: Sequence[Sequence[float]], k: int, *, where: dict | None = None) -> list[list[tuple[str, float]]]Parameters
Section titled “Parameters”-
queries : sequence of sequences of float Query vectors, each as for
search. -
k : int Maximum number of results, at least 1.
-
where : dict, optional, keyword-only Metadata filter, for example
{"genre": "jazz"}or{"year": {"$gte": 1950}}. Operators:$eq,$ne,$gt,$gte,$lt,$lte,$in,$nin,$and,$or,$not;"a.b"names a nested field. See Filtered search. Evaluated once for the whole batch. DefaultNonesearches every vector.
Returns
Section titled “Returns”list[list[tuple[str, float]]]: one search result list per query, in query order. No queries gives [].
Raises
Section titled “Raises”-
ValueError
kis 0, or a query does not match the database dimension or contains NaN or infinity, orwhereis not a valid filter. Also raised for a negativek. -
RuntimeError An internal fault occurred.
- The queries run in parallel inside Rust.
- Thread safety: releases the GIL and takes a shared lock, so calls from several threads run in parallel; they wait while a write is running. See Threads and processes.
Examples
Section titled “Examples”import srvdb
db = srvdb.create("./vectors", dimension=128)v = [1.0] + [0.0] * 127 # tiny 128-dimension vectorsw = [0.0, 1.0] + [0.0] * 126db.add(["a", "b"], [v, w], ["{}", "{}"])print(db.search_batch([v, w], k=1))# [[('a', 0.9999999403953552)], [('b', 0.9999999403953552)]]See also
Section titled “See also”db.search: Find the k nearest vectors to a query.
Was this page helpful? Tell us in Discussions.