Add WASM fallbacks for tree-sitter and SQLite, fix installer
Replace native tree-sitter with web-tree-sitter + tree-sitter-wasms for universal cross-platform support. Add node-sqlite3-wasm as a fallback when better-sqlite3 native bindings aren't available. Move better-sqlite3 and sqlite-vss to optionalDependencies so installs never fail. Fix installer to use npx fallback when global npm install fails, so MCP config, hooks, and quick-start instructions all work without the bare codegraph command in PATH. Fix tests: update schema version expectation, fix db test paths and method names, extract MAX_OUTPUT_LENGTH as module constant, normalize Windows path separators in import resolver.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* High-level manager that coordinates embedding generation and vector search.
|
||||
*/
|
||||
|
||||
import Database from 'better-sqlite3';
|
||||
import { SqliteDatabase } from '../db/sqlite-adapter';
|
||||
import { Node, SearchResult, SearchOptions } from '../types';
|
||||
import { TextEmbedder, createEmbedder, EmbedderOptions, EMBEDDING_DIMENSION } from './embedder';
|
||||
import { VectorSearchManager, createVectorSearch } from './search';
|
||||
@@ -68,7 +68,7 @@ export class VectorManager {
|
||||
private initialized = false;
|
||||
|
||||
constructor(
|
||||
db: Database.Database,
|
||||
db: SqliteDatabase,
|
||||
queries: QueryBuilder,
|
||||
options: VectorManagerOptions = {}
|
||||
) {
|
||||
@@ -355,7 +355,7 @@ export class VectorManager {
|
||||
* Create a vector manager
|
||||
*/
|
||||
export function createVectorManager(
|
||||
db: Database.Database,
|
||||
db: SqliteDatabase,
|
||||
queries: QueryBuilder,
|
||||
options?: VectorManagerOptions
|
||||
): VectorManager {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Falls back to brute-force cosine similarity if sqlite-vss is not available.
|
||||
*/
|
||||
|
||||
import Database from 'better-sqlite3';
|
||||
import { SqliteDatabase } from '../db/sqlite-adapter';
|
||||
import { Node } from '../types';
|
||||
import { TextEmbedder, EMBEDDING_DIMENSION } from './embedder';
|
||||
|
||||
@@ -29,11 +29,11 @@ export interface VectorSearchOptions {
|
||||
* Handles vector storage and similarity search for semantic code search.
|
||||
*/
|
||||
export class VectorSearchManager {
|
||||
private db: Database.Database;
|
||||
private db: SqliteDatabase;
|
||||
private vssEnabled = false;
|
||||
private embeddingDimension: number;
|
||||
|
||||
constructor(db: Database.Database, dimension: number = EMBEDDING_DIMENSION) {
|
||||
constructor(db: SqliteDatabase, dimension: number = EMBEDDING_DIMENSION) {
|
||||
this.db = db;
|
||||
this.embeddingDimension = dimension;
|
||||
}
|
||||
@@ -75,10 +75,11 @@ export class VectorSearchManager {
|
||||
const vss = await import('sqlite-vss');
|
||||
|
||||
// Use the load function which loads both vector0 and vss0
|
||||
// VSS extension expects the raw better-sqlite3 Database instance
|
||||
if (typeof vss.load === 'function') {
|
||||
vss.load(this.db);
|
||||
vss.load(this.db as any);
|
||||
} else if (typeof vss.default?.load === 'function') {
|
||||
vss.default.load(this.db);
|
||||
vss.default.load(this.db as any);
|
||||
} else {
|
||||
throw new Error('sqlite-vss load function not found');
|
||||
}
|
||||
@@ -464,7 +465,7 @@ export class VectorSearchManager {
|
||||
* Create a vector search manager
|
||||
*/
|
||||
export function createVectorSearch(
|
||||
db: Database.Database,
|
||||
db: SqliteDatabase,
|
||||
dimension?: number
|
||||
): VectorSearchManager {
|
||||
return new VectorSearchManager(db, dimension);
|
||||
|
||||
Reference in New Issue
Block a user