/** * Automatic RAG retriever for injecting relevant context before Claude invocation. * Runs hybrid search (keyword + semantic) on history and content stores. */ import { ContentStore, ContentSearchCandidate } from './content-store.js'; import { HistoryStore, Message } from './history.js'; import { ScoredSummaryResult } from './summaries.js'; /** Max missing embeddings to backfill synchronously on the search path; the rest go to the background. */ export declare const MAX_INLINE_BACKFILL = 16; /** Whether a background embedding backfill is currently running for a thread. */ export declare function isBackfillInFlight(threadPath: string): boolean; /** * Decide how much missing-embedding backfill to do inline vs. in the background. * Pure (no I/O) so the bounding policy is trivially testable. */ export declare function planEmbeddingBackfill(missingCount: number, inFlight: boolean): { inlineCount: number; scheduleBackground: boolean; }; /** * Backfill missing embeddings off the search critical path. Deduplicated per * thread so successive searches don't stack full re-embeds. Never throws into * the caller. The runner is injectable for testing. */ export declare function scheduleBackgroundBackfill(threadPath: string, messages: Array<{ id: string; content: string; }>, runner?: (tp: string, msgs: Array<{ id: string; content: string; }>) => Promise): void; /** Default budget fraction for retrieved context (40% of effective limit) */ export declare const RETRIEVAL_BUDGET_FRACTION = 0.4; export interface RetrievalResult { /** Formatted context string ready for injection into system prompt */ context: string; /** Number of history messages included */ historyCount: number; /** Number of content items included */ contentCount: number; /** Number of segment summaries included */ summaryCount: number; /** Total tokens used by retrieved context */ tokensUsed: number; /** Debug info about what was retrieved */ debug: { historyResults: Array<{ index: number; role: string; score: number; snippet: string; }>; contentResults: Array<{ id: string; score: number; snippet: string; }>; sessionResults: Array<{ sessionId: string; score: number; snippet: string; }>; summaryResults: Array<{ segmentStart: number; segmentEnd: number; score: number; topics: string[]; }>; queryType?: string; }; } export interface RetrieverOptions { /** Token budget for retrieved context */ budgetTokens: number; /** Current session ID (to boost current session results) */ currentSessionId?: string; /** Sessions path for session document search */ sessionsPath?: string; /** Recent conversation messages for query expansion */ recentMessages?: Array<{ role: string; content: string; }>; /** Total number of messages in history (for segment building) */ totalMessages?: number; } interface ScoredHistoryResult { message: Message; index: number; score: number; keywordScore: number; semanticScore: number; } interface ScoredSessionResult { sessionId: string; chunkIndex: number; content: string; score: number; } /** * Format retrieved results into a context string that fits within budget. * * Content snippets are materialized lazily here (task 083 Lever 2): content is * added last and the loop `break`s as soon as a line exceeds the remaining * budget, so materializing each candidate's snippet inside the loop reads only * the snippets that survive the merge (`contentCount + 1`) instead of all * ~`limit` (≈150) the content store ranked. RLM-neutral — same candidates, same * order, same snippet text, same break, so the assembled context is identical. */ export declare function formatRetrievedContext(historyResults: ScoredHistoryResult[], contentResults: ContentSearchCandidate[], sessionResults: ScoredSessionResult[], summaryResults: ScoredSummaryResult[], budgetTokens: number, contentStore: ContentStore | null): Promise<{ context: string; historyCount: number; contentCount: number; summaryCount: number; tokensUsed: number; }>; /** * Retrieve relevant context for a user query. * Runs hybrid search on history, content, and session stores. */ export declare function retrieve(query: string, historyStore: HistoryStore, contentStore: ContentStore | null, options: RetrieverOptions): Promise; export {}; //# sourceMappingURL=retriever.d.ts.map