UNPKG

@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

54 lines (53 loc) • 1.93 kB
/** * Hybrid Search Implementation * * Combines vector (dense) search with BM25 (sparse) search for improved retrieval. * Supports multiple fusion methods: Reciprocal Rank Fusion (RRF) and Linear Combination. */ import type { BM25Result, HybridSearchConfig, HybridSearchResult, BM25Index, HybridSearchOptions } from "../../types/index.js"; /** * In-memory BM25 implementation for testing and development */ export declare class InMemoryBM25Index implements BM25Index { private documents; private avgDocLength; private k1; private b; search(query: string, topK?: number): Promise<BM25Result[]>; addDocuments(documents: Array<{ id: string; text: string; metadata?: Record<string, unknown>; }>): Promise<void>; private tokenize; private countTermFrequency; private countDocumentsWithTerm; } /** * Reciprocal Rank Fusion * Combines rankings from multiple retrieval methods * * @param rankings - Array of ranking lists, each with id and rank * @param k - RRF constant (default: 60) * @returns Map of document IDs to fused scores */ export declare function reciprocalRankFusion(rankings: Array<Array<{ id: string; rank: number; }>>, k?: number): Map<string, number>; /** * Linear Combination of normalized scores * * @param vectorScores - Vector search scores * @param bm25Scores - BM25 search scores * @param alpha - Weight for vector scores (0-1), bm25 gets 1-alpha * @returns Map of document IDs to combined scores */ export declare function linearCombination(vectorScores: Map<string, number>, bm25Scores: Map<string, number>, alpha?: number): Map<string, number>; /** * Create a hybrid search function * * @param options - Search options * @returns Hybrid search function */ export declare function createHybridSearch(options: HybridSearchOptions): (query: string, config?: HybridSearchConfig) => Promise<HybridSearchResult[]>;