BM25Index
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 documents in the index.
Returns
Section titled “Returns”number
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
clear()
Section titled “clear()”clear(): void;Remove all documents and reset the index.
Returns
Section titled “Returns”void
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
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.