Reference
srvdb.rebuild_checksums
Recompute missing or damaged checksum files of a closed database.
Recompute missing or damaged checksum files (*.crc) of a closed database, so it opens again.
srvdb.rebuild_checksums(path: str) -> list[str]Parameters
Section titled “Parameters”- path : str Directory of a closed database.
Returns
Section titled “Returns”The names of the checksum files that were rewritten, such as ["vectors.bin.crc"]. Empty if every checksum file was intact.
Raises
Section titled “Raises”-
FileNotFoundError
pathis not a directory, or holds no SrvDB vector file. -
BlockingIOError The database is open, in this process or another. Close it first.
-
OSError A file could not be read or written.
-
RuntimeError A checksum file is intact but the data or header does not match it, or the data is truncated: the data is damaged. Nothing is rewritten; restore from a backup.
- It never runs on its own. Call it when
srvdb.openfails because a.crcfile is missing or damaged, for example after copying onlyvectors.bin. - A checksum file that is intact but disagrees with the vector file header (record size or block count) means the header is damaged: RuntimeError, nothing rewritten.
- A checksum file that is missing or fails its own check is recomputed from the data as found. A rebuilt checksum cannot detect damage that was already in the data. If the data itself may be damaged, restore a backup instead.
- Each checksum file is replaced atomically (temporary file, fsync, rename). After a crash, run the call again. Vectors, metadata and indexes are not changed.
Examples
Section titled “Examples”import osimport srvdb
with srvdb.create("./vectors", dimension=128, index="flat") as db: db.add(["a"], [[1.0] + [0.0] * 127], ["{}"])os.remove("./vectors/vectors.bin.crc")rebuilt = srvdb.rebuild_checksums("./vectors")with srvdb.open("./vectors") as db: count = db.count()print(rebuilt)print(count)# ['vectors.bin.crc']# 1See also
Section titled “See also”srvdb.open: Open an existing database.- Handling errors
Was this page helpful? Tell us in Discussions.