Skip to content

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.

readonly size: number;

Number of documents in the index.

add(documents): void;

Add documents. A document with an existing ID is overwritten.

Parameter Type

documents

BM25Document[]

void


clear(): void;

Remove all documents.

void


remove(id): boolean;

Remove a document by ID. Returns true if it existed.

Parameter Type

id

string

boolean


search(query, topK?): BM25SearchResult[];

Search for documents matching the query, BM25-scored, descending.

Parameter Type

query

string

topK?

number

BM25SearchResult[]