/** * Storage layer for the embeddings module. * * Owns: * - the embeddings-specific schema migration on global.db * - the projects.embedding_* columns * - the vec0 virtual table for vectors * - read/write helpers around `embeddings` * - identifier extraction from a project's local index.db * * The vec0 hookup is lazy: sqlite-vec is loaded on first use, not at import time. */ import Database from 'better-sqlite3'; import type { EmbeddingModel } from './model-registry.js'; /** Test/teardown helper — closes the embeddings connection. */ export declare function _closeEmbeddingsDb(): void; /** * Internal accessor for search.ts — returns the singleton DB with sqlite-vec * loaded. Throws if vec isn't ready yet (caller must call ensureVecTable first * via the pipeline). */ export declare function _searchDbAccessor(): Database.Database; export declare function ensureEmbeddingsSchema(): void; export declare function ensureVecTable(dim: number): Promise; export declare function vecTableName(dim: number): string; export declare function markProjectEnabled(projectPath: string, model: EmbeddingModel): void; export declare function isProjectEnabled(projectPath: string): boolean; export declare function getEnabledProjectIds(): number[]; export declare function getEnabledProjectsWithModel(modelId: string): ProjectEmbeddingInfo[]; /** * Wipe every embedding row + vec0 entry for a project. Used by migrate(). */ export declare function wipeProjectEmbeddings(project: ProjectEmbeddingInfo): Promise; export interface ProjectEmbeddingInfo { id: number; path: string; name: string; modelId: string; dim: number; version: number; } export declare function getProjectInfo(projectPath: string): ProjectEmbeddingInfo | null; export interface MethodForEmbedding { methodId: number; name: string; prototype: string; filePath: string; lineNumber: number; bodyText: string | null; bodyLines: number | null; docComment: string | null; } export interface TypeForEmbedding { typeId: number; name: string; kind: string; filePath: string; lineNumber: number; } export interface IndexedFile { fileId: number; path: string; } export interface IndexDbHandle { db: Database.Database; close(): void; } export declare function openProjectIndexDb(projectPath: string): IndexDbHandle | null; export declare function readMethods(handle: IndexDbHandle): MethodForEmbedding[]; export declare function readTypes(handle: IndexDbHandle): TypeForEmbedding[]; /** * Identifiers occurring within a method's body lines, with usage counts. * Built from the existing items/occurrences/lines tables — no extra extraction. */ export declare function readMethodIdentifiers(handle: IndexDbHandle, filePath: string, startLine: number, endLine: number): Map; /** * Identifiers occurring within ±2 lines of a type definition. * Heuristic: types don't have bodies in our index, so we approximate. */ export declare function readTypeIdentifiers(handle: IndexDbHandle, filePath: string, line: number): Map; export interface TaskForEmbedding { id: number; title: string; description: string | null; summary: string | null; tags: string | null; status: string; priority: number; updated_at: number; } export interface TaskLogForEmbedding { id: number; task_id: number; task_title: string; note: string; created_at: number; } export interface NoteHistoryForEmbedding { id: number; note: string; summary: string | null; created_at: number; } export declare function readAllTasks(handle: IndexDbHandle): TaskForEmbedding[]; export declare function readTaskById(handle: IndexDbHandle, id: number): TaskForEmbedding | null; export declare function readAllTaskLogs(handle: IndexDbHandle): TaskLogForEmbedding[]; export declare function readTaskLogsByTask(handle: IndexDbHandle, taskId: number): TaskLogForEmbedding[]; export declare function readSessionNote(handle: IndexDbHandle): string | null; export declare function readNoteHistory(handle: IndexDbHandle): NoteHistoryForEmbedding[]; export interface DocFile { path: string; absPath: string; } /** * Markdown / text-doc files belonging to the project. * Reads from `project_files` (populated by aidex_init). */ export declare function listDocFiles(handle: IndexDbHandle, projectPath: string): DocFile[]; export declare function readDocFile(absPath: string): string | null; export interface EmbeddingWrite { sourceType: string; sourceKind: 'code' | 'docs' | 'workspace'; sourcePath: string | null; sourceAnchor: string | null; sourceName: string | null; sourceLine: number | null; /** Human-readable snippet stored in DB (what the viewer shows). */ sourceText: string; /** * Text actually fed to the embedding model. Optional — defaults to sourceText * when the two are identical (e.g. workspace, docs). Code chunks set this * separately so the display text can omit weighted-repetition noise. */ embeddingText?: string; contentHash: string; isPrivate: boolean; embedding: Float32Array; } export interface BulkWriteResult { inserted: number; skipped: number; } /** * Insert or replace an embedding row + its vector. * Returns the embeddings.id. */ export declare function bulkUpsertEmbeddings(project: ProjectEmbeddingInfo, items: EmbeddingWrite[]): Promise; export declare function setLastFullEmbedAt(projectId: number, ts: number): void; export declare function countProjectEmbeddings(projectId: number): number; export declare function totalEmbeddings(): number; export interface ProjectEmbeddingBreakdown { total: number; byKind: Record; byType: Record; } export declare function getProjectEmbeddingBreakdown(projectId: number): ProjectEmbeddingBreakdown; /** * Delete one embedding (and its vec0 row) by primary key fields. * Returns true if a row was deleted. */ export declare function deleteEmbeddingByAnchor(project: ProjectEmbeddingInfo, sourceType: string, sourceAnchor: string, sourcePath?: string | null): Promise; /** * Delete all embeddings whose source_anchor starts with the given prefix * (optionally filtered by source_type). Used to remove all embeddings * tied to a specific entity (e.g., all `task-log` rows for one task) * without touching embeddings of unrelated entities. * Returns the number of deleted rows. */ export declare function deleteEmbeddingsByAnchorPrefix(project: ProjectEmbeddingInfo, sourceAnchorPrefix: string, sourceType?: string | null): Promise; /** * Delete embeddings whose anchors are NOT in `keepAnchors` for the given source_type. * Used after re-indexing workspace items: any task that disappeared gets its * embedding pruned. Returns the number of pruned rows. */ export declare function pruneEmbeddingsByType(project: ProjectEmbeddingInfo, sourceType: string, keepAnchors: Set): Promise; /** * Delete all embeddings (and their vec0 rows) for a given file path within a project. * Used by removeFile() and as a precursor to updateFile(). * Returns the number of deleted rows. */ export declare function deleteEmbeddingsByFile(project: ProjectEmbeddingInfo, filePath: string): Promise; /** * Prune file-scoped embeddings (code/docs) whose anchors aren't in keepAnchors. * Used by updateFile() to drop methods/types/sections that disappeared. */ export declare function pruneFileEmbeddingsExcept(project: ProjectEmbeddingInfo, filePath: string, keepAnchors: Set): Promise; /** Read methods+types limited to one file path. Mirrors readMethods/readTypes. */ export declare function readMethodsForFile(handle: IndexDbHandle, filePath: string): MethodForEmbedding[]; export declare function readTypesForFile(handle: IndexDbHandle, filePath: string): TypeForEmbedding[]; /** Bump files_changed_since for stale-detection. */ export declare function bumpFilesChanged(projectId: number, by?: number): void; export declare function getFilesChangedSince(projectId: number): number; export declare function resetFilesChanged(projectId: number): void; export declare function getLastFullEmbedAt(projectId: number): number | null; /** * Prune doc-section embeddings whose (source_path, source_anchor) pair is not in keepKeys. * Used after re-indexing docs — removed sections / deleted files vanish. * Returns the number of pruned rows. */ export declare function pruneDocSectionsExcept(project: ProjectEmbeddingInfo, keepKeys: Set): Promise; export declare function readExistingHashes(projectId: number): Map; //# sourceMappingURL=store.d.ts.map