/** * InMemoryStore — reference `MemoryStore` implementation, zero dependencies. * * Kept deliberately small — ~200 lines. Its job is to validate the * interface contract: every stage and pipeline is tested against this * adapter, so any bug in the store shape surfaces here first. * * Internal structure: * namespace (string) → Map * + Set (for seen) * + Map (for feedback) * * TTL is enforced lazily on read (cheapest; no background sweeper needed). * Pagination cursor is a monotonic integer — entries sorted by updatedAt desc. */ import type { MemoryIdentity } from '../identity/index.js'; import type { MemoryEntry } from '../entry/index.js'; import type { ListOptions, ListResult, MemoryStore, PutIfVersionResult, ScoredEntry, SearchOptions } from './types.js'; export declare class InMemoryStore implements MemoryStore { /** * Top-level namespace → slot. Using `Map` rather than a plain object * avoids prototype-pollution surface AND preserves insertion order * (needed for deterministic list pagination). */ private readonly namespaces; private slot; /** True if the entry's TTL has elapsed. Centralized so both `get` and `list` agree. */ private isExpired; get(identity: MemoryIdentity, id: string): Promise | null>; put(identity: MemoryIdentity, entry: MemoryEntry): Promise; /** * Batched write — resolves the slot once and writes each entry into the * same Map. Saves N-1 slot lookups vs. calling `put()` in a loop, and * gives network-backed adapters a place to pipeline round-trips. */ putMany(identity: MemoryIdentity, entries: readonly MemoryEntry[]): Promise; putIfVersion(identity: MemoryIdentity, entry: MemoryEntry, expectedVersion: number): Promise; list(identity: MemoryIdentity, options?: ListOptions): Promise>; delete(identity: MemoryIdentity, id: string): Promise; seen(identity: MemoryIdentity, signature: string): Promise; recordSignature(identity: MemoryIdentity, signature: string): Promise; feedback(identity: MemoryIdentity, id: string, usefulness: number): Promise; getFeedback(identity: MemoryIdentity, id: string): Promise<{ average: number; count: number; } | null>; forget(identity: MemoryIdentity): Promise; /** * O(n) linear scan over identity-scoped entries. Fine for dev / tests * — for production, plug in a real vector backend (pgvector, Pinecone, * Qdrant) that implements the same interface. * * Semantics per the `MemoryStore.search?` contract: * - Entries without `embedding` are skipped (ignored, not errored). * - Entries with `embedding.length` mismatching the query are * skipped (cosine would throw — silent-skip avoids poisoning top-k). * - TTL-expired entries are omitted. * - Optional `tiers` / `minScore` / `embedderId` filters applied. * - Returns descending by score; ties broken by id for determinism. */ search(identity: MemoryIdentity, query: readonly number[], options?: SearchOptions): Promise[]>; }