@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
42 lines (41 loc) • 1.98 kB
TypeScript
/**
* In-memory knowledge index construction.
*
* Index construction is an application-process lifecycle operation, not a
* per-session one. A complete `KnowledgeIndexSnapshot` is built once from the
* normalized entries and then queried by every turn.
*
* The lexical scorer is a compact field-aware BM25 (BM25F-style): each of the
* five text fields is scored independently and combined with per-field
* weights, retaining the per-field breakdown so a retrieval decision is
* explainable in traces. No embedding model or vector store is involved.
*/
import type { IndexedKnowledgeDocument, KnowledgeFieldWeights, KnowledgeIndexSnapshot, KnowledgeLexicalMatch, NormalizedKnowledgeEntry } from "../types/index.js";
/**
* Field-aware BM25 over the document set. Query text is scored per field and
* the weighted per-field scores are summed. Satisfies the structural
* `KnowledgeLexicalSearcher` type held by a snapshot.
*/
export declare class KnowledgeLexicalIndex {
private readonly weights;
private readonly postings;
private readonly fieldLengths;
private readonly fieldTokenTotals;
private readonly avgFieldLength;
private docCount;
constructor(weights: KnowledgeFieldWeights);
add(document: IndexedKnowledgeDocument): void;
finalize(): void;
search(queryTokens: string[], topK: number, eligibleEntryIds?: ReadonlySet<string>): KnowledgeLexicalMatch[];
}
/**
* Build the internal search document from a normalized entry. `exactKeys`
* carry whole-phrase identifiers (entry id and title); each
* text field is tokenized for the field-aware scorer.
*/
export declare const buildDocument: (entry: NormalizedKnowledgeEntry) => IndexedKnowledgeDocument;
/**
* Build the complete immutable snapshot: entry map, exact/alias/relation
* indexes, and the field-aware lexical index.
*/
export declare const buildIndexSnapshot: (entries: NormalizedKnowledgeEntry[], weights: KnowledgeFieldWeights) => KnowledgeIndexSnapshot;