/** * Memory Bridge — Routes CLI memory operations through SQLite * * Uses SQLiteBackend (better-sqlite3, sql.js WASM fallback) from @monoes/memory. * LanceDB was replaced by this SQLite engine 2026-07; the on-disk data * directory is still named `lancedb` for legacy/back-compat path resolution * (see getDbPath below) but no longer holds LanceDB data. * All exported function signatures are unchanged. * * @module v1/cli/memory-bridge */ export declare function safeParseEmbedding(raw: string | null | undefined): number[] | null; export declare const BRIDGE_EMBEDDING_MODEL = "Alibaba-NLP/gte-modernbert-base"; export declare const BRIDGE_EMBEDDING_DIMS = 768; /** The directory that identifies "this project" for every Second Brain store. * * Deliberately NOT the raw cwd: keying on cwd forked the brain per directory — * `doc ingest ./docs` from a package subdir wrote to a different store, and a * different metadata file, than the identical command at the repo root, and * neither could see the other. We walk up to the nearest ancestor carrying a * `.monomind` or `.git` marker, so every directory inside one project resolves * to one brain. Nested projects still win (the walk stops at the FIRST marker), * which keeps worktrees and vendored sub-repos independent. * * The walk never crosses the home directory: a dotfiles repo at `~` would * otherwise swallow every loose project underneath it into one shared brain. * * For anyone who already ran from the project root — the normal case — the * resolved path is identical to before, so their store does not move. * * `MONOMIND_CWD` wins over the real cwd, matching `getProjectCwd()` in * mcp-tools/types.ts — an MCP server is launched with whatever cwd the client * chose, and that env var is already how monograph and swarm state learn which * project they belong to. Inlined rather than imported to keep this module on * node builtins only (see the static import in document-pipeline.ts). */ export declare function getProjectRoot(from?: string): string; /** The personal, cross-project knowledge store. Deliberately a SIBLING of * ~/.monomind/projects (never inside it) so per-project pruning heuristics * (`cleanup --data`) can never touch it. Env-overridable for tests and for * users who keep their brain on a synced/external location. Resolved lazily * so the override works regardless of import order. */ export declare function getGlobalBrainDir(): string; /** Sentinel callers pass as dbPath to address the global brain. */ export declare const GLOBAL_BRAIN = "@global"; /** Resolve the real on-disk SQLite data-dir path for a given custom path (or the * default) — the dir is still named `lancedb` for legacy path back-compat. */ export declare function bridgeGetDbPath(customPath?: string): string; export declare const BRIDGE_RERANKER_MODEL = "cross-encoder/ettin-reranker-32m-v1"; /** Pre-load the cross-encoder reranker model. Idempotent, no-op when * MONOMIND_RERANKER=0. Exported so the eval harness can force-load before * the network guard blocks model downloads. */ export declare function loadReranker(): Promise; export declare function bridgeStoreEntry(options: { key: string; value: string; namespace?: string; generateEmbeddingFlag?: boolean; tags?: string[]; ttl?: number; dbPath?: string; upsert?: boolean; /** Structured metadata persisted on the entry (KG nodes/edges, weights, provenance). */ metadata?: Record; }): Promise<{ success: boolean; id: string; embedding?: { dimensions: number; model: string; }; guarded?: boolean; cached?: boolean; attested?: boolean; duplicate?: boolean; error?: string; } | null>; export declare function bridgeSearchEntries(options: { query: string; namespace?: string; limit?: number; threshold?: number; dbPath?: string; /** Skip cross-encoder reranking even if the model is loaded. */ skipRerank?: boolean; /** When true, superseded knowledge chunks are kept in the results * (flagged by the caller). Default false — removed documents are * filtered out for security. */ includeSuperseded?: boolean; /** Project root to read document metadata from for the knowledge-superseded * check (default: getProjectRoot(), i.e. process.cwd()-derived). Callers * operating on an explicit project directory that differs from cwd — e.g. * searchKnowledge({ rootDir }) — must pass the SAME root here, or every * freshly-ingested doc in that directory reads as superseded (its content * hash won't be found in metadata read from the wrong place) and gets * filtered out despite matching the query. */ rootDir?: string; }): Promise<{ success: boolean; results: { id: string; key: string; content: string; score: number; namespace: string; provenance?: string; tags?: string[]; }[]; searchTime: number; /** What actually ran, never what was requested. 'keyword-fallback' means the * vector path was attempted and did not produce the results. */ searchMethod?: 'semantic' | 'keyword' | 'keyword-fallback'; /** Whether a cross-encoder reranker was applied to the final results. */ reranked?: boolean; /** Why the vector path did not serve these results (absent when it did). */ fallbackReason?: 'no-embedding-model' | 'empty-query' | 'embedding-failed' | 'no-semantic-matches'; error?: string; } | null>; export declare function bridgeListEntries(options: { namespace?: string; limit?: number; offset?: number; dbPath?: string; }): Promise<{ success: boolean; entries: { id: string; key: string; namespace: string; content: string; accessCount: number; createdAt: string; updatedAt: string; hasEmbedding: boolean; tags: string[]; metadata: Record; }[]; total: number; error?: string; } | null>; export declare function bridgeGetEntry(options: { key: string; namespace?: string; dbPath?: string; agentId?: string; }): Promise<{ success: boolean; found: boolean; entry?: { id: string; key: string; namespace: string; content: string; accessCount: number; createdAt: string; updatedAt: string; hasEmbedding: boolean; tags: string[]; metadata: Record; }; cacheHit?: boolean; error?: string; } | null>; export declare function bridgeDeleteEntry(options: { key?: string; id?: string; namespace?: string; dbPath?: string; }): Promise<{ success: boolean; deleted: boolean; error?: string; } | null>; export declare function bridgeGenerateEmbedding(text: string, dbPath?: string): Promise<{ embedding: number[]; dimensions: number; model: string; } | null>; export declare function bridgeLoadEmbeddingModel(dbPath?: string): Promise<{ success: boolean; dimensions: number; modelName: string; loadTime?: number; } | null>; export declare function bridgeGetBackendStats(dbPath?: string): Promise<{ totalEntries: number; entriesByNamespace: Record; memoryUsage: number; } | null>; export declare function bridgeAddToHNSW(options: { id: string; embedding: number[]; namespace?: string; dbPath?: string; }): Promise<{ success: boolean; indexSize?: number; error?: string; } | null>; /** * Real status for the ANN (HNSW) fast path inside SqlBackend.search() — * whether the corpus is big enough to use it, whether it's currently built, * and where its on-disk cache lives. Read-only; does not build anything. */ export declare function bridgeGetHNSWStatus(dbPath?: string): Promise<{ available: boolean; thresholdEntries: number; activeEmbeddedEntries: number; built: boolean; entryCount: number; dimensions: number; cachePath: string | null; } | null>; /** * Force-build (or reload from disk cache) the ANN index regardless of * MONOMIND_HNSW_THRESHOLD — the real implementation behind * `memory search --build-hnsw`. */ export declare function bridgeForceBuildHNSW(dbPath?: string): Promise<{ entryCount: number; dimensions: number; cachePath: string | null; } | null>; export declare function isBridgeAvailable(dbPath?: string): Promise; export declare function shutdownBridge(): Promise; export declare function bridgeStorePattern(options: { pattern: string; taskType?: string; outcome?: string; confidence?: number; dbPath?: string; }): Promise<{ success: boolean; id: string; error?: string; } | null>; export declare function bridgeSearchPatterns(options: { query: string; taskType?: string; limit?: number; dbPath?: string; }): Promise<{ success: boolean; patterns: { id: string; pattern: string; confidence: number; taskType?: string; score: number; }[]; error?: string; } | null>; /** Record that these entries were actually USED (returned to and consumed by a * caller) — increments frequency_weight, which feeds the ranking blend. */ export declare function bridgeRecordUsage(options: { entryIds: string[]; dbPath?: string; }): Promise<{ success: boolean; updated: number; } | null>; /** Apply a usefulness rating to the entries that produced an answer: * EWMA feedback_weight' = w + alpha*(score - w), clipped [0,1] (cognee's * apply_feedback_weights). `ledgerKey` makes application idempotent — a * daemon retry or duplicate MCP call must never compound the update. */ export declare function bridgeApplyFeedback(options: { entryIds: string[]; score: number; ledgerKey?: string; alpha?: number; dbPath?: string; }): Promise<{ success: boolean; applied: number; alreadyApplied?: boolean; error?: string; } | null>; export declare function bridgeRecordFeedback(options: { taskType: string; action: string; outcome: 'success' | 'failure' | 'partial'; confidence?: number; metadata?: Record; dbPath?: string; }): Promise<{ success: boolean; id: string; error?: string; } | null>; export declare function bridgeRecordCausalEdge(options: { sourceId: string; targetId: string; relation: string; strength?: number; dbPath?: string; }): Promise<{ success: boolean; id: string; error?: string; } | null>; export declare function bridgeSessionStart(options: { sessionId: string; agentId?: string; metadata?: Record; dbPath?: string; }): Promise<{ success: boolean; id: string; error?: string; } | null>; export declare function bridgeSessionEnd(options: { sessionId: string; summary?: string; metrics?: Record; dbPath?: string; }): Promise<{ success: boolean; error?: string; } | null>; export declare function bridgeRouteTask(options: { task: string; topK?: number; dbPath?: string; }): Promise<{ success: boolean; routes: { agentType: string; confidence: number; pattern?: string; }[]; error?: string; } | null>; export declare function bridgeHealthCheck(dbPath?: string): Promise<{ healthy: boolean; backend: string; stats?: { totalEntries: number; namespaces: string[]; }; error?: string; } | null>; export declare function bridgeHierarchicalStore(params: { key: string; value: string; tier?: string; importance?: number; }): Promise; export declare function bridgeHierarchicalRecall(params: { query: string; tier?: string; topK?: number; }): Promise; export declare function bridgeConsolidate(params: { /** Minimum age in MILLISECONDS since last update (default 7 days). */ minAge?: number; maxEntries?: number; /** Namespace to GC; 'all' scans every non-protected namespace (default 'default'). */ namespace?: string; dbPath?: string; }): Promise; export declare function bridgeBatchOperation(params: { operation: string; entries: any[]; }): Promise; export declare function bridgeContextSynthesize(params: { query: string; maxEntries?: number; }): Promise; export declare function bridgeSemanticRoute(params: { input: string; }): Promise; //# sourceMappingURL=memory-bridge.d.ts.map