/** * Embedding provider interface for generating vector embeddings from text. */ export interface EmbeddingProvider { name: string; dimensions: number; embed(texts: string[]): Promise; } /** * Configuration for embedding generation. */ export interface EmbeddingConfig { provider: 'local'; enabled: boolean; } /** * Entry in the embeddings file. */ export interface EmbeddingEntry { messageId: string; embedding: number[]; timestamp: string; } /** * Structure of the embeddings file. */ export interface EmbeddingsFile { version: 1; model: string; dimensions: number; entries: EmbeddingEntry[]; } export declare function setSharedEmbeddingUrl(url: string | null): void; /** * Get or create the embedding provider. * Returns a RemoteEmbeddingProvider if a shared MCP server URL is configured, * otherwise falls back to the local LocalEmbeddingProvider. */ export declare function getEmbeddingProvider(): EmbeddingProvider; /** * Get the local embedding provider, ignoring any shared MCP URL. * This is used by the shared MCP server's /embed endpoint handler, which must * run the ONNX model locally (it IS the server that the remote provider calls). */ export declare function getLocalEmbeddingProvider(): EmbeddingProvider; /** * Check if embeddings are available/enabled. */ export declare function embeddingsAvailable(): Promise; /** * Calculate cosine similarity between two vectors. */ export declare function cosineSimilarity(a: number[], b: number[]): number; /** * Get the path to the embeddings file for a thread. * Returns the .embeddings.json path (canonical name for backward compatibility). * Callers should use loadEmbeddings/saveEmbeddings which handle binary format transparently. */ export declare function getEmbeddingsPath(threadPath: string): string; /** * Run `fn` holding an exclusive advisory lock on `filePath`. * * Only whole-file REWRITERS need this (compaction, delete/prune rebuilds). * Appenders deliberately do not take it: O_APPEND is already atomic, and making * every write contend on a lock file would reintroduce a serialization point on * the hot path for no correctness gain. * * Returns false without running `fn` if the lock could not be acquired — a * rewrite that cannot exclude appenders must not run, because it would rewrite * the file from a snapshot and lose whatever landed in between (the exact * failure this task exists to remove). */ export declare function withRewriteLock(filePath: string, fn: () => Promise): Promise; /** * Load embeddings from file, using in-memory cache. * Tries binary format first, then JSON. If JSON loaded, auto-converts to binary. */ export declare function loadEmbeddings(threadPath: string): Promise>; /** * Save embeddings to file (always writes binary format). * Merges new entries into existing embeddings. */ export declare function saveEmbeddings(threadPath: string, entries: EmbeddingEntry[], append?: boolean): Promise; /** * Generate embeddings for messages that don't have them yet. */ export declare function generateMissingEmbeddings(threadPath: string, messages: Array<{ id: string; content: string; }>): Promise; /** * Generate and save the embedding for a single message. * Used by the embed-on-write hook for background embedding generation. */ export declare function embedSingleMessage(threadPath: string, message: { id: string; content: string; }): Promise; /** * Dispose the local ONNX inference session and release its native worker * threads. MUST be called before `process.exit()` during shutdown/restart to * avoid a native SIGABRT (`mutex lock failed: Invalid argument`) when those * threads are torn down mid-flight. Best-effort and idempotent. No-op when the * model was never loaded or when using the remote provider (no in-process ONNX). */ export declare function disposeEmbeddingProvider(): Promise; /** * Get binary path for content store embeddings. */ export declare function getContentEmbeddingsBinPath(basePath: string): string; /** * Get JSON path for content store embeddings. */ export declare function getContentEmbeddingsJsonPath(basePath: string): string; /** * Load content store embeddings with caching. * Tries binary first, then JSON with auto-conversion. */ export declare function loadContentEmbeddingsCached(basePath: string): Promise>; /** * Merge new content-store embeddings into the file by APPENDING them (task 143). * * A content store can be shared by several co-threads, each in its own process, * so this is the one write path where concurrency is not hypothetical. The * merged map is still what the cache holds — only the disk write is incremental. */ export declare function saveContentEmbeddingsCached(basePath: string, newEntries: Map): Promise; /** * Rewrite a content store's embeddings file from a complete map (full-replace * semantics: delete and prune rebuilds). Takes the rewrite lock so it cannot * discard a concurrent append. */ export declare function rewriteContentEmbeddings(basePath: string, fullMap: Map): Promise; /** * Invalidate the content embeddings cache for a given basePath. * Called after delete operations that rewrite the embeddings file. */ export declare function invalidateContentEmbeddingsCache(basePath: string): void; /** * Get the consolidated binary embeddings path for a thread's sessions directory. * The leading underscore keeps it out of every `ses_*.md` / `*.embeddings.json` * enumeration in the codebase (all of which filter by those exact suffixes). */ export declare function getSessionEmbeddingsBinPath(sessionsDir: string): string; /** * Load a thread's consolidated session embeddings with caching. * Binary blob first; falls back to a one-time JSON→binary migration. */ export declare function loadSessionEmbeddingsCached(sessionsDir: string): Promise>; /** * Merge new session chunk embeddings into the consolidated blob and refresh * the cache. `newEntries` is keyed `ses:{sessionId}:{chunkIndex}`. */ export declare function saveSessionEmbeddingsCached(sessionsDir: string, newEntries: Map): Promise; /** * Invalidate the session embeddings cache for a given sessions directory. */ export declare function invalidateSessionEmbeddingsCache(sessionsDir: string): void; //# sourceMappingURL=embeddings.d.ts.map