trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
87 lines • 2.53 kB
TypeScript
/**
* Embedding Vector Store
*
* Persistent storage for embedding vectors using sql.js (pure WASM SQLite).
* Works in Bun, Node, and WebContainer — no native addons required.
* Vectors are stored as Float32Array blobs; cosine similarity is computed
* in JavaScript for cross-platform portability.
*
* @see TRL-18
* @see TRL-2 (migrated from bun:sqlite to sql.js)
*/
import type { ChunkMeta, EmbeddingRecord, SearchOptions, SearchResult } from './types.js';
export declare class VectorStore {
private dbPath;
private db;
private stmts;
private writes;
private constructor();
/**
* Async factory — sql.js WASM init is async, but after bootstrap the store
* exposes a synchronous-style public API.
*/
static create(dbPath: string): Promise<VectorStore>;
private bootstrap;
private loadFromDisk;
private flushToDisk;
private prepareStatements;
/**
* Insert or update a chunk with its embedding vector.
*/
upsert(record: EmbeddingRecord): void;
/**
* Batch upsert multiple records.
*/
upsertBatch(records: EmbeddingRecord[]): void;
/**
* Delete a chunk and its vector by ID.
*/
delete(id: string): void;
/**
* Delete all chunks for an entity.
*/
deleteByEntity(entityId: string): void;
/**
* Delete all chunks associated with a file path.
*/
deleteByFile(filePath: string): void;
/**
* Get a chunk by ID (without vector).
*/
getChunk(id: string): ChunkMeta | null;
/**
* Search for chunks similar to the query vector.
* Uses brute-force cosine similarity scan.
*/
search(queryVector: Float32Array, opts?: SearchOptions): SearchResult[];
/**
* Get total count of chunks in the store.
*/
count(): number;
/**
* Get count by chunk type.
*/
countByType(): Record<string, number>;
/**
* Clear all data from the store.
*/
clear(): void;
/**
* Force a write of the in-memory DB image to disk.
*/
flush(): void;
/**
* Close the database connection.
*/
close(): void;
private runAll;
private runOne;
private tickFlush;
}
/**
* Compute cosine similarity between two vectors.
* Both vectors should already be normalized (output of mean pooling + normalize).
* For normalized vectors, cosine similarity = dot product.
*/
export declare function cosineSimilarity(a: Float32Array, b: Float32Array): number;
//# sourceMappingURL=store.d.ts.map