/** * loadRelevant — read-side stage that embeds a query and fetches the * top-k most similar entries from a vector-capable `MemoryStore`. * * Reads from scope: `identity`, `newMessages` (or custom queryFrom) * Writes to scope: `loaded` (MemoryEntry[], ordered best-first — to be * narrowed by `pickByBudget` downstream) * * Query derivation: * Default: the last user message in `newMessages`. That's the natural * "what is the user asking about?" signal. Override with `queryFrom` * for custom retrieval (e.g., compose user + assistant content, * pull a summary, etc.). * * Empty behavior: * No query text → no search → `loaded = []`. Downstream * `pickByBudget` picks nothing and the formatter emits nothing — safe. * * Feature detection: * Throws at stage build time if the store doesn't implement * `search()`. Fail-loud — a semantic pipeline configured against a * non-vector store is a config bug, not a runtime condition. */ import type { TypedScope } from 'footprintjs'; import type { MemoryStore } from '../store/index.js'; import type { MemoryState } from '../stages/index.js'; import type { Embedder } from './types.js'; export interface LoadRelevantConfig { /** The vector-capable store. Must implement `search()`. */ readonly store: MemoryStore; /** Embedder used to turn the query text into a vector. */ readonly embedder: Embedder; /** * Identifier for the embedder. When set, the search filters entries * to those produced by the same embedder (prevents cross-model * similarity pollution). */ readonly embedderId?: string; /** Top-k to retrieve. Default 20 — picker will narrow further by budget. */ readonly k?: number; /** Minimum cosine score [-1, 1] to consider a match. Default: none. */ readonly minScore?: number; /** Filter results by tier. */ readonly tiers?: ReadonlyArray<'hot' | 'warm' | 'cold'>; /** * Extract the query text from scope. Default: the last user message * in `newMessages`. Override for custom retrieval signals. */ readonly queryFrom?: (scope: TypedScope) => string; } export declare function loadRelevant(config: LoadRelevantConfig): (scope: TypedScope) => Promise;