Skip to content

Reference

db.configure_ivf

Set the IVF partition parameters.

db.configure_ivf(nlist: int = 100, nprobe: int = 10) -> None
  • nlist : int, default 100 Number of partitions (centroids).

  • nprobe : int, default 10 Partitions searched per query: higher is more accurate, slower.

None.

  • Call before set_mode("ivf") so the index is created with these values. In "ivf" mode it replaces the index with an untrained one. Either way, call train_ivf afterwards.
  • Values are not range-checked; use positive values with nprobe <= nlist.
  • Thread safety: a database object is safe to share between threads. This method releases the GIL; writes (add, upsert, delete, save, compact, mode and IVF changes) take an exclusive lock and wait for each other and for running searches instead of failing. See Threads and processes.
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", "b"], [v, w], ["{}", "{}"])
db.configure_ivf(nlist=2, nprobe=1)
db.set_mode("ivf")
db.train_ivf()
print(db.search(v, k=1))
# [('a', 0.9999999403953552)]