Reference
db.save
Make every earlier write durable (crash-safe commit).
db.save() -> Nonedb.persist() -> None # aliasParameters
Section titled “Parameters”None.
Returns
Section titled “Returns”None.
Raises
Section titled “Raises”-
OSError Writing or syncing the files failed.
-
RuntimeError An internal fault occurred.
- Guarantee: when
save()returns, every earlieradd,upsertanddeletesurvives a process crash or power loss. After a crash the database reopens in exactly the state of the last successfulsave(); later writes are absent, never partially present. See Durability and save(). - Writes not followed by
save()are lost when the process exits or the object is garbage-collected. persist()is the same method under its 0.3 name.- A
withblock callssave()when it ends without an exception; see the database object. save()fsyncs, so it costs real time: call it per batch or at checkpoints, not per vector.- 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)v = [1.0] + [0.0] * 127 # tiny 128-dimension vectorsw = [0.0, 1.0] + [0.0] * 126db.add(["a"], [v], ["{}"])db.save()db.close() # releases the lockprint(srvdb.open("./vectors").count())# 1See also
Section titled “See also”db.add: Add new vectors with their ids and metadata.db.compact: Remove deleted and replaced vectors from disk.
Was this page helpful? Tell us in Discussions.