Skip to content

Fts5KeywordIndex

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.

new Fts5KeywordIndex(options): Fts5KeywordIndex;
Parameter Type

options

Fts5KeywordIndexOptions

Fts5KeywordIndex

get size(): number;

Number of documents in the index.

number

Number of documents in the index.

KeywordIndex.size

add(documents): void;

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

Parameter Type

documents

BM25Document[]

void

KeywordIndex.add


clear(): void;

Remove all documents.

void

KeywordIndex.clear


remove(id): boolean;

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

Parameter Type

id

string

boolean

KeywordIndex.remove


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

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

Parameter Type Default value

query

string

undefined

topK

number

10

BM25SearchResult[]

KeywordIndex.search