import type { ChunkMetadata, IndexMetadata } from "../types.js"; import type { IndexedChunk } from "../vectordb/base.js"; import { type MetadataFilter } from "./filter.js"; export declare const KEYWORD_INDEX_FORMAT = 1; export declare const BM25_K1 = 1.2; export declare const BM25_B = 0.75; export interface KeywordHit { id: string; text: string; metadata: ChunkMetadata; /** BM25 score. */ score: number; } /** Layout of `keyword.json`. Both SDKs read and write this same format. */ export interface KeywordIndexFile { format: number; tokenizer: string; /** Identifies the vector index this keyword index was built for. */ index: { sourceHash: string; createdAt: string; chunkCount: number; }; chunks: IndexedChunk[]; /** Number of terms in each chunk. */ lengths: number[]; /** term -> flat [chunkIndex, termFrequency, chunkIndex, termFrequency, ...]. */ postings: Record; } /** * BM25 keyword index over a document's chunks. It is built from the chunk * texts alone, so it never needs extra embedding calls, and it is kept in a * sidecar file next to the vector index so it works with every store. */ export declare class KeywordIndex { private readonly chunks; private readonly lengths; private readonly postings; private readonly avgLength; private constructor(); static build(chunks: IndexedChunk[]): KeywordIndex; static fromFile(data: KeywordIndexFile): KeywordIndex; toFile(metadata: IndexMetadata): KeywordIndexFile; /** Chunks matching any query term, best BM25 score first, ties broken by chunk id. */ search(query: string, topK: number, filter?: MetadataFilter): KeywordHit[]; } export declare function byScoreThenId(a: { id: string; score: number; }, b: { id: string; score: number; }): number; /** True when a keyword index file was built for exactly this vector index. */ export declare function keywordFileMatches(data: KeywordIndexFile, metadata: IndexMetadata): boolean; /** Reads a keyword index file, or returns null if it is missing or unreadable. */ export declare function readKeywordFile(path: string): Promise; export declare function writeKeywordFile(path: string, data: KeywordIndexFile): Promise;