Reference
db.set_mode
Switch the index mode of an open database.
db.set_mode(mode: str) -> NoneParameters
Section titled “Parameters”- mode : str
Case-insensitive:
"flat","hnsw","sq8"(alias"scalar"),"ivf"or"auto".
Returns
Section titled “Returns”None.
Raises
Section titled “Raises”- ValueError
Unknown mode, including
"pq", which is chosen when the database is created withsrvdb.create.
- The mode is recorded by the next
save(); later opens use it. - After
set_mode("ivf"), calltrain_ivf. - 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.
Examples
Section titled “Examples”import srvdb
db = srvdb.create("./vectors", dimension=128, index="flat")v = [1.0] + [0.0] * 127 # tiny 128-dimension vectorsw = [0.0, 1.0] + [0.0] * 126db.add(["a"], [v], ["{}"])db.set_mode("hnsw")print(db.info())# SrvDB(dimension=128, mode='hnsw', vectors=1)See also
Section titled “See also”srvdb.open: Open an existing database by path.db.train_ivf: Train the IVF index on the stored vectors.db.set_ef_search: Set HNSW’s search candidate list size.
Was this page helpful? Tell us in Discussions.