BM25Index
Contract for a BM25-ranked keyword index — the keyword tier of hybrid
retrieval. Implementations: BM25Index (in-memory, rebuilt per process)
and Fts5KeywordIndex (SQLite FTS5, persistent — survives Durable
Object hibernation with zero rebuild).
All methods are synchronous: the in-memory index is pure computation and
DO SQLite’s sql.exec is synchronous, so the contract stays sync to keep
FusionRetriever / KnowledgeFs hot paths allocation-free.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new BM25Index(options?): BM25Index;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
Returns
Section titled “Returns”BM25Index
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get size(): number;Number of active (non-removed) documents in the index.
Returns
Section titled “Returns”number
Number of documents in the index.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”add(documents): void;Add documents to the index. If a document with the same ID already exists, it is overwritten (old entry is logically removed first).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”clear()
Section titled “clear()”clear(): void;Remove all documents and reset the index.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”remove()
Section titled “remove()”remove(id): boolean;Remove a document from the index by ID. Returns true if the document existed and was removed.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”search()
Section titled “search()”search(query, topK?): BM25SearchResult[];Search the index for documents matching the query.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
|
|
|
|
Natural language query (tokenized the same way as documents). |
|
|
|
|
Maximum number of results. Default: 10. |
Returns
Section titled “Returns”Scored results sorted by BM25 score descending.