Skip to content

Reference

db.get

Return the metadata stored for an id.

db.get(id: str) -> str | None
  • id : str The vector’s id.

str | None: the metadata as a JSON object string, including the id under the key "__id__" (parse it with json.loads), or None if no live vector has this id: it never existed or was deleted. Like dict.get, an unknown id is not an error.

  • OSError Reading the metadata failed.

  • RuntimeError An internal fault occurred.

  • 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.
import json
import srvdb
db = srvdb.create("./vectors", dimension=128)
v = [1.0] + [0.0] * 127 # tiny 128-dimension vectors
w = [0.0, 1.0] + [0.0] * 126
db.add(["a"], [v], [json.dumps({"title": "A"})])
print(json.loads(db.get("a")))
# {'__id__': 'a', 'title': 'A'}
print(db.get("missing"))
# None