Reference
srvdb.delete
Delete a database from disk.
Delete a database from disk: every SrvDB file, then the directory.
srvdb.delete(path: str) -> NoneParameters
Section titled “Parameters”- path : str Directory of a closed database.
Returns
Section titled “Returns”None.
Raises
Section titled “Raises”-
FileNotFoundError
pathdoes not exist or is not a directory. -
ValueError
pathis a symbolic link (pass the real directory), or holds files SrvDB did not create (the message names one), a subdirectory, or no SrvDB database at all. Nothing is deleted. -
BlockingIOError The database is open, in this process or another. Close it first.
-
OSError A file could not be removed.
- Safety: only a directory that is provably a SrvDB database is removed. Every entry must be a file SrvDB writes, and at least one must start with a SrvDB header (magic number). A mistyped path that points at your home directory or a project folder is refused, and so is a symbolic link, even one that points at a database.
- With the database locked, the directory is first renamed to a hidden sibling
.<name>.srvdb-deleting-<pid>, then emptied and removed, so no other process can open the database while it is being deleted. A crash part way can leave that hidden directory; remove it by hand. Deleted data cannot be recovered. - To delete vectors rather than the whole database, use
db.delete.
Examples
Section titled “Examples”import osimport srvdb
with srvdb.create("./vectors", dimension=128) as db: db.add(["a"], [[1.0] + [0.0] * 127], ["{}"])srvdb.delete("./vectors")print(os.path.exists("./vectors"))# Falseimport srvdb
db = srvdb.create("./vectors", dimension=128)try: srvdb.delete("./vectors")except BlockingIOError: print("close it first")# close it firstdb.close()srvdb.delete("./vectors")See also
Section titled “See also”srvdb.create: Create a new database with its index and options.db.close: Release the database and its lock.
Was this page helpful? Tell us in Discussions.