Skip to content

BM25Index

new BM25Index(options?): BM25Index;
Parameter Type

options?

BM25IndexOptions

BM25Index

get size(): number;

Number of documents in the index.

number

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).

Parameter Type

documents

BM25Document[]

void


clear(): void;

Remove all documents and reset the index.

void


remove(id): boolean;

Remove a document from the index by ID. Returns true if the document existed and was removed.

Parameter Type

id

string

boolean


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

Search the index for documents matching the query.

Parameter Type Default value Description

query

string

undefined

Natural language query (tokenized the same way as documents).

topK

number

10

Maximum number of results. Default: 10.

BM25SearchResult[]

Scored results sorted by BM25 score descending.