/** * SqliteCortexStore — local SQLite-backed implementation of CortexStore. * * Uses better-sqlite3 for synchronous SQLite access wrapped in async interface. * Vector search uses brute-force cosine similarity (sufficient for <10k memories). * Dates stored as ISO-8601 strings. Arrays stored as JSON text, except * embeddings, which are raw Float32Array blobs (legacy JSON-text embeddings * are converted in place at open time and still readable either way). */ import type { CortexStore, StoreCapabilities } from '../core/store.js'; import type { Memory, Observation, Edge, OpsEntry, OpsFilters, Signal, SignalFilters, BeliefEntry, SearchResult, FSRSData, QueryFilter } from '../core/types.js'; export declare class SqliteCortexStore implements CortexStore { private db; private ns; private txnQueue; private inTransaction; constructor(dbPath: string, namespace?: string); private t; private createTables; /** Add columns introduced after initial schema. Safe to run repeatedly (no-ops on new DBs). */ private migrateSchema; /** * One-time conversion of legacy JSON-text embeddings to Float32Array blobs. * Idempotent: only rows whose stored value is still text are touched, so * re-opening an already-converted DB is a no-op scan. Column affinity does * not matter here — SQLite stores blob values as blobs regardless of the * declared column type, and typeof() reports the stored type. */ private migrateEmbeddingsToBlobs; private addColumn; private createIndexes; /** * External-content FTS5 index over memory name/definition/tags, kept in * sync by triggers. On first creation against a non-empty memories table, * the index is rebuilt from existing rows. */ private createFtsTable; putMemory(memory: Omit): Promise; getMemory(id: string): Promise; updateMemory(id: string, updates: Partial>): Promise; findNearest(embedding: number[], limit: number): Promise; searchText(text: string, limit: number): Promise; touchMemory(id: string, fsrsUpdates: Partial): Promise; getAllMemories(): Promise; getRecentMemories(days: number, limit: number): Promise; putObservation(obs: Omit): Promise; getUnprocessedObservations(limit: number): Promise; markObservationProcessed(id: string): Promise; putEdge(edge: Omit): Promise; getEdgesFrom(memoryId: string): Promise; getEdgesForMemories(memoryIds: string[]): Promise; appendOps(entry: Omit): Promise; queryOps(filters: OpsFilters): Promise; updateOps(id: string, updates: Partial>): Promise; putSignal(signal: Omit): Promise; getSignal(id: string): Promise; getSignals(filters?: SignalFilters): Promise; updateSignal(id: string, updates: Partial>): Promise; putBelief(entry: Omit): Promise; getBeliefHistory(conceptId: string): Promise; put(collection: string, doc: Record): Promise; get(collection: string, id: string): Promise | null>; update(collection: string, id: string, updates: Record): Promise; query(collection: string, filters: QueryFilter[], options?: { limit?: number; orderBy?: string; orderDir?: 'asc' | 'desc'; }): Promise[]>; countDocuments(collection: string, filters?: QueryFilter[]): Promise; delete(collection: string, id: string): Promise; /** * Manual BEGIN IMMEDIATE / COMMIT / ROLLBACK rather than better-sqlite3's * db.transaction() wrapper. The wrapper is purely synchronous and commits * the moment the sync callback returns — it cannot survive an await * suspension inside an async user closure, and refuses outright if the * closure returns a Promise. Manual statements let the closure await store * ops correctly. * * Concurrent calls are serialized through a Promise-chained queue: only * one transaction is in flight at a time per store instance. Without this, * two parallel BEGINs would race and the second would throw SQLITE_ERROR * "cannot start a transaction within a transaction". * * Hard constraint on fn: avoid awaits to external systems (LLM, network). * They hold the transaction open and block every other writer through the * queue. Store ops are fine — they are sync under their async wrapper. * * Nested calls on the same store are forbidden and rejected explicitly. * See docs/concurrency.md. */ withTransaction(fn: (txn: CortexStore) => Promise): Promise; upsertMemory(memory: Memory): Promise; upsertObservation(obs: Observation): Promise; upsertEdge(edge: Edge): Promise; upsertOpsEntry(entry: OpsEntry): Promise; upsertSignal(signal: Signal): Promise; upsertBelief(belief: BeliefEntry): Promise; getCapabilities(): Promise; } //# sourceMappingURL=sqlite.d.ts.map