mnemos-coder
Version:
CLI-based coding agent with graph-based execution loop and terminal UI
172 lines • 4.69 kB
TypeScript
/**
* Vector database using Vectra for efficient similarity search
* Replaces sqlite-vec with a simpler Node.js native solution
*/
import { EmbeddingConfig } from '../config/GlobalConfig.js';
export interface CodeChunk {
id: string;
file_path: string;
start_line: number;
end_line: number;
content: string;
chunk_type: 'function' | 'class' | 'interface' | 'import' | 'variable' | 'comment' | 'other';
language: string;
content_hash: string;
embedding?: number[];
metadata?: Record<string, any>;
created_at: Date;
updated_at: Date;
}
export interface FileInfo {
file_path: string;
content_hash: string;
last_modified: Date;
file_size: number;
language: string;
chunk_count: number;
indexed_at: Date;
}
export interface VectorSearchResult {
chunk: CodeChunk;
similarity_score: number;
rank: number;
}
export interface DatabaseMetadata {
embedding_model: string;
embedding_dimension: number;
total_chunks: number;
total_files: number;
last_indexed: string;
version: string;
}
export declare class VectraDatabase {
private db;
private vectorIndex;
private dbPath;
private indexPath;
private embeddingDimension;
private embeddingModel;
private initPromise;
constructor(projectRoot: string, embeddingConfig: EmbeddingConfig);
private initializeDatabase;
private createTables;
private createIndexes;
/**
* Store file information with indexing status
*/
storeFile(fileInfo: Omit<FileInfo, 'indexed_at'>, status?: 'pending' | 'chunking' | 'embedding' | 'complete'): void;
/**
* Update file indexing status
*/
updateFileStatus(filePath: string, status: 'pending' | 'chunking' | 'embedding' | 'complete'): void;
/**
* Get incomplete files count
*/
getIncompleteFilesCount(): number;
/**
* Store code chunk with embedding
*/
storeChunk(chunk: Omit<CodeChunk, 'created_at' | 'updated_at'>, embedding?: number[]): Promise<void>;
/**
* Ensure database is fully initialized
*/
ensureInitialized(): Promise<void>;
/**
* Store embedding for a chunk using Vectra
*/
storeEmbedding(chunkId: string, embedding: number[]): Promise<void>;
/**
* Store multiple embeddings in a batch for better performance
*/
storeBatchEmbeddings(embeddings: {
chunkId: string;
embedding: number[];
}[]): Promise<void>;
/**
* Vector similarity search using Vectra
*/
vectorSearch(queryEmbedding: number[], limit?: number, threshold?: number): Promise<VectorSearchResult[]>;
/**
* Text search using FTS5
*/
textSearch(query: string, limit?: number): VectorSearchResult[];
/**
* Enrich search results with chunk data
*/
private enrichSearchResults;
/**
* Check if database needs reindexing due to model change
*/
needsReindexing(): {
needed: boolean;
reason?: string;
currentModel?: string;
newModel?: string;
};
/**
* Get database metadata
*/
getMetadata(): DatabaseMetadata;
/**
* Update database metadata
*/
private updateMetadata;
/**
* Get chunk by ID
*/
getChunkById(id: string): CodeChunk | null;
/**
* Convert database row to CodeChunk
*/
private rowToChunk;
/**
* Clear all embeddings (for reindexing)
*/
clearEmbeddings(): Promise<void>;
/**
* Get statistics
*/
getStats(): {
totalFiles: number;
totalChunks: number;
totalEmbeddings: number;
embeddingModel: string;
embeddingDimension: number;
};
/**
* Get all chunks by type
*/
getChunksByType(chunkType: string, limit?: number): CodeChunk[];
/**
* Get all chunks for a file
*/
getChunksByFile(filePath: string): CodeChunk[];
/**
* Remove all chunks for a file
*/
removeFileChunks(filePath: string): Promise<void>;
/**
* Get file info by path
*/
getFileInfo(filePath: string): FileInfo | null;
/**
* Get all indexed files with their metadata
*/
getAllIndexedFiles(includeIncomplete?: boolean): Map<string, FileInfo>;
/**
* Check if file has changed based on content hash
*/
hasFileChanged(filePath: string, currentHash: string): boolean;
/**
* Get all embeddings (for compatibility)
*/
getAllEmbeddings(): {
id: string;
embedding: number[];
}[];
/**
* Close database connection
*/
close(): void;
}
//# sourceMappingURL=VectraDatabase.d.ts.map