Reference
db.enable_keyword_search
Index a metadata field for keyword (BM25) search.
Index a metadata field for keyword (BM25) search with db.search(text=...).
db.enable_keyword_search(field: str = "text") -> NoneParameters
Section titled “Parameters”- field : str, default
"text"Name of a string field in each record’s metadata JSON."a.b"names a nested field; a list of strings is indexed as one text.
Raises
Section titled “Raises”-
ValueError
fieldis empty or has an empty part ("a..b"), or is longer than 256 bytes. -
OSError Reading the metadata failed.
- Reuses the saved index when it covers the same field; otherwise builds it from metadata, reading every record once.
- The index is written by the next
save()and used again aftersrvdb.open()without calling this again. - Records without a string value in the field are not indexed.
- Call it again to rebuild a damaged index file.
Examples
Section titled “Examples”import srvdb
db = srvdb.create("./docs", dimension=128)v = [1.0] + [0.0] * 127db.add(["a"], [v], ['{"text": "error E0308"}'])db.enable_keyword_search("text")print(db.search(None, k=1, text="e0308")[0][0])# aSee also
Section titled “See also”Was this page helpful? Tell us in Discussions.