/** * Semantic Memory Search — Embeddings-based retrieval over blackboard data * * Provides an in-memory vector store that can index blackboard entries and * answer similarity queries. Bring your own embedding function (BYOE) — * no runtime dependency on any specific model or provider. * * Optionally persists the index to a JSON file (`persistPath`) so memory * survives process restarts without re-embedding everything. * * Inspired by Claw-Code's semantic memory pattern. * * @module SemanticSearch * @version 1.1.0 */ /** * User-provided function that converts text to a fixed-length float vector. * Can wrap OpenAI, Cohere, local models, etc. */ export type EmbeddingFn = (text: string) => Promise; /** * A single search result with similarity score. */ export interface SearchResult { /** Blackboard key or document id */ key: string; /** The stored value */ value: unknown; /** Cosine similarity (0–1, higher = more similar) */ score: number; /** Which agent wrote this entry */ sourceAgent: string; } /** * In-memory semantic vector store with optional file-backed persistence. * * @example * ```typescript * // Ephemeral (in-memory only) * const memory = new SemanticMemory(async (text) => openai.embed(text)); * * // Persistent across restarts * const memory = new SemanticMemory( * async (text) => openai.embed(text), * { persistPath: './data/semantic-index.json' } * ); * await memory.load(); // restore from disk on startup * * // Index entries * await memory.index('task:1', 'Quarterly revenue analysis', { status: 'done' }, 'analyst'); * await memory.save(); // flush to disk * * // Search * const results = await memory.search('financial trends', 5); * // → [{ key: 'task:1', score: 0.87, ... }] * ``` */ export declare class SemanticMemory { private entries; private embeddingFn; private readonly persistPath; /** * @param embeddingFn Function that produces embeddings from text * @param options Optional configuration * @param options.persistPath Path to a JSON file for durable storage. * Call `load()` after construction to restore, and `save()` (or use * `autoSave`) to flush writes. */ constructor(embeddingFn: EmbeddingFn, options?: { persistPath?: string; }); /** * Persist the current in-memory index to `persistPath`. * No-op when `persistPath` was not set. */ save(): void; /** * Restore the index from `persistPath`. * No-op when `persistPath` was not set or the file does not exist. * * Call this once after construction to warm the index from a previous run. */ load(): void; /** * Delete the persistence file. * Useful for clearing stale indexes between projects. */ clearPersisted(): void; /** * Index a key–value pair with its text representation. * Re-indexing the same key replaces the previous embedding. * * @param key Unique identifier * @param text The text to embed for similarity matching * @param value The value to return in search results * @param sourceAgent Agent that produced this entry * @param autoSave Flush to disk after indexing (requires `persistPath`). Default false. */ index(key: string, text: string, value: unknown, sourceAgent: string, autoSave?: boolean): Promise; /** * Search for entries similar to the query text. * * @param query Natural language query * @param topK Maximum results to return (default 5) * @param threshold Minimum cosine similarity (default 0) * @returns Sorted results, highest similarity first */ search(query: string, topK?: number, threshold?: number): Promise; /** * Bulk-index all entries from a blackboard snapshot. * * @param snapshot Record of key → { value, source_agent } (from LockedBlackboard.getSnapshot()) * @returns Number of entries indexed */ indexSnapshot(snapshot: Record): Promise; /** * Remove an entry by key. * @returns true if an entry was removed */ remove(key: string): boolean; /** * Remove all indexed entries. */ clear(): void; /** * Number of indexed entries. */ size(): number; /** * Check if a key is indexed. */ has(key: string): boolean; /** * List all indexed keys. */ keys(): string[]; } //# sourceMappingURL=semantic-search.d.ts.map