/** * Search result containing document index and relevance score */ interface SearchResult { /** Index of the matched document */ index: number; /** BM25 relevance score */ score: number; } /** * Options for configuring the BM25 algorithm */ interface BM25Options { /** Term frequency saturation parameter (default: 1.5) */ k1?: number; /** Length normalization factor (default: 0.75) */ b?: number; /** Minimum token length to consider (default: 2) */ minLength?: number; /** Set of stop words to filter out */ stopWords?: Set; /** Enable word stemming (default: false) */ stemming?: boolean; /** Custom word stemming function */ stemWords?: (word: string) => string; } /** * Field boost factors to control importance of different fields */ interface FieldBoosts { /** Field name to boost factor mapping */ [field: string]: number; } /** * Document structure where each field contains text content */ interface Document { /** Field name to text content mapping */ [field: string]: string; } /** * Implementation of the Okapi BM25 ranking algorithm with field boosting support */ declare class BM25 { private readonly termFrequencySaturation; private readonly lengthNormalizationFactor; private readonly tokenizer; private documentLengths; private averageDocLength; private readonly termToIndex; private documentFrequency; private readonly termFrequencies; private readonly fieldBoosts; private readonly workerOptions; private documents; /** * Creates a new BM25 search instance * @param docs - Optional array of documents to index * @param options - BM25 algorithm options and field boost settings */ constructor(docs?: Document[], options?: BM25Options & { fieldBoosts?: FieldBoosts; }); private processDocuments; /** * Adds multiple documents to the index using parallel processing * @param docs - Array of documents to add */ addDocumentsParallel(docs: Document[]): Promise; private updateDocumentFrequency; private recalculateAverageLength; /** * Searches the indexed documents using BM25 ranking * @param query - Search query text * @param limit - Maximum number of results to return * @returns Array of search results sorted by relevance score */ search(query: string, topK?: number): SearchResult[]; searchPhrase(phrase: string, topK?: number): SearchResult[]; private calculatePhraseScore; /** * Adds a new document to the index * @param doc - Document to add */ addDocument(doc: Document): Promise; private calculateIDF; private getTermFrequency; private getDocument; clearDocuments(): void; getDocumentCount(): number; addDocuments(docs: Document[]): Promise; } export { BM25 };