KeywordIndex
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.
Properties
Section titled “Properties”readonly size: number;Number of documents in the index.
Methods
Section titled “Methods”add(documents): void;Add documents. A document with an existing ID is overwritten.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
Returns
Section titled “Returns”void
clear()
Section titled “clear()”clear(): void;Remove all documents.
Returns
Section titled “Returns”void
remove()
Section titled “remove()”remove(id): boolean;Remove a document by ID. Returns true if it existed.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”boolean
search()
Section titled “search()”search(query, topK?): BM25SearchResult[];Search for documents matching the query, BM25-scored, descending.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
|