/** * CortexStore — storage abstraction for cortex-engine. * * Implementations: FirestoreCortexStore (cloud), SqliteCortexStore (local), * JsonCortexStore (file-backed, for backup/migration). * All methods operate on plain JS objects (no Firestore Timestamps, no VectorValue). */ import type { Memory, Observation, Edge, OpsEntry, OpsFilters, Signal, BeliefEntry, SearchResult, QueryFilter, FSRSData } from './types.js'; /** * Bumped when the CortexStore wire format changes in a way that breaks * round-trip migration. Used by getCapabilities() during migrate to refuse * incompatible source/destination pairs. */ export declare const CORTEX_STORE_SCHEMA_VERSION = 1; export interface StoreCapabilities { /** Bumped on breaking interface/wire-format changes; see CORTEX_STORE_SCHEMA_VERSION. */ schemaVersion: number; /** Length of the first stored memory's embedding, or 0 if the store is empty. */ embeddingDimension: number; /** Distinct Memory.category values observed in the store (best-effort, may be empty). */ categories: string[]; /** The namespace prefix the store is bound to ('' for the default namespace). */ namespace: string; /** Identifier for the backend implementation. */ backend: 'sqlite' | 'firestore' | 'json'; } export interface CortexStore { /** Store a new memory, returns its ID. */ putMemory(memory: Omit): Promise; /** Get a memory by ID. */ getMemory(id: string): Promise; /** Update specific fields on a memory. */ updateMemory(id: string, updates: Partial>): Promise; /** Find k nearest memories by embedding vector. Returns sorted by similarity desc. */ findNearest(embedding: number[], limit: number): Promise; /** Increment access_count, update last_accessed and FSRS fields. */ touchMemory(id: string, fsrsUpdates: Partial): Promise; /** Get all memories (for batch operations like dream scoring). Use with caution. */ getAllMemories(): Promise; /** Get memories updated within the last N days, limited to M results. */ getRecentMemories(days: number, limit: number): Promise; /** Store a new observation, returns its ID. */ putObservation(obs: Omit): Promise; /** Get unprocessed observations (for dream consolidation). */ getUnprocessedObservations(limit: number): Promise; /** Mark an observation as processed. */ markObservationProcessed(id: string): Promise; /** Store a new edge, returns its ID. */ putEdge(edge: Omit): Promise; /** Get all edges originating from a memory. */ getEdgesFrom(memoryId: string): Promise; /** Get all edges (both directions) for a set of memory IDs. */ getEdgesForMemories(memoryIds: string[]): Promise; /** Append an ops entry, returns its ID. */ appendOps(entry: Omit): Promise; /** Query ops entries with composable filters. */ queryOps(filters: OpsFilters): Promise; /** Update an ops entry (e.g., mark as done). */ updateOps(id: string, updates: Partial>): Promise; /** Store a signal, returns its ID. */ putSignal(signal: Omit): Promise; /** Log a belief change. */ putBelief(entry: Omit): Promise; /** Get belief history for a concept. */ getBeliefHistory(conceptId: string): Promise; /** Store a document in a named collection. Returns its ID. */ put(collection: string, doc: Record): Promise; /** Get a document from a named collection by ID. */ get(collection: string, id: string): Promise | null>; /** * Update a document in a named collection by ID. Merges updates. * Throws `Error("Document not found: ${collection}/${id}")` if the * document does not exist — both SQLite and Firestore backends honour * this contract. */ update(collection: string, id: string, updates: Record): Promise; /** Query documents from a named collection with filters. */ query(collection: string, filters: QueryFilter[], options?: { limit?: number; orderBy?: string; orderDir?: 'asc' | 'desc'; }): Promise[]>; /** Count documents in a named collection, optionally filtered. */ countDocuments(collection: string, filters?: QueryFilter[]): Promise; /** Delete a document from a named collection by ID. */ delete(collection: string, id: string): Promise; /** * Run `fn` inside a backend-native transaction. All writes commit atomically * on resolve; any thrown error rolls back. The proxy passed to `fn` is the * same store instance — call store methods on it normally. * * SQLite constraint: the body of `fn` MUST NOT await external systems * (LLM calls, network). Store operations themselves are safe because * better-sqlite3 is synchronous under the async wrapper. * * See docs/concurrency.md for the full contract. */ withTransaction(fn: (txn: CortexStore) => Promise): Promise; /** Insert or replace a memory by its existing ID. */ upsertMemory(memory: Memory): Promise; /** Insert or replace an observation by its existing ID. */ upsertObservation(obs: Observation): Promise; /** Insert or replace an edge by its existing ID. */ upsertEdge(edge: Edge): Promise; /** Insert or replace an ops entry by its existing ID. */ upsertOpsEntry(entry: OpsEntry): Promise; /** Insert or replace a signal by its existing ID. */ upsertSignal(signal: Signal): Promise; /** Insert or replace a belief entry by its existing ID. */ upsertBelief(belief: BeliefEntry): Promise; /** * Return a snapshot of store metadata used by the migration tool to detect * incompatible source/destination pairs before mutating data. */ getCapabilities(): Promise; } //# sourceMappingURL=store.d.ts.map