# BM25Index

**Kind:** Class

**Source:** [`atloria-monorepo/libs/agent-core/src/semantic/bm25.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/libs/agent-core/src/semantic/bm25.ts#L59)

## Methods

| Method | Signature | Returns |
|---|---|---|
| `addDocument` | `addDocument(id: string, text: string)` | `void` |
| `removeDocument` | `removeDocument(id: string)` | `void` |
| `search` | `search(query: string, topK: undefined)` | `Array<{ id: string; score: number }>` |
| `clear` | `clear()` | `void` |
| `serialize` | `serialize()` | `SerializedIndex` |
| `deserialize` | `deserialize(data: object)` | `BM25Index` |

## Where it refuses work

- `BM25Index` stops the work with an early return when `docLen === undefined`.
- `BM25Index` stops the work with an early return when `queryTokens.length === 0 || this.documentCount === 0`.
- `BM25Index` stops the work with an early return when `!d.terms || !d.docLengths`.
