indexer-cli 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,12 +32,15 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.LanceDbVectorStore = exports.REQUIRED_COLUMNS = void 0;
39
+ exports.LanceDbVectorStore = exports.SqliteVecVectorStore = exports.REQUIRED_COLUMNS = void 0;
37
40
  const node_fs_1 = require("node:fs");
38
- const lancedb = __importStar(require("@lancedb/lancedb"));
39
- const logger_js_1 = require("../core/logger.js");
40
- const logger = new logger_js_1.SystemLogger("vector-lancedb");
41
+ const node_path_1 = __importDefault(require("node:path"));
42
+ const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
43
+ const sqliteVec = __importStar(require("sqlite-vec"));
41
44
  exports.REQUIRED_COLUMNS = [
42
45
  "project_id",
43
46
  "chunk_id",
@@ -48,361 +51,271 @@ exports.REQUIRED_COLUMNS = [
48
51
  "content_hash",
49
52
  "chunk_type",
50
53
  "primary_symbol",
51
- "vector",
54
+ "embedding",
52
55
  ];
53
- const COPY_VECTORS_QUERY_LIMIT = 1_000_000;
54
- class LanceDbVectorStore {
56
+ const UPSERT_BATCH_SIZE = 200;
57
+ class SqliteVecVectorStore {
55
58
  dbPath;
56
59
  vectorSize;
57
- tableName;
58
- cacheTTL;
59
60
  db;
60
- table;
61
61
  initialized = false;
62
- lastCacheRefresh = 0;
63
- operationQueue = Promise.resolve();
64
62
  constructor(options) {
65
63
  this.dbPath = options.dbPath;
66
64
  this.vectorSize = options.vectorSize;
67
- this.tableName = options.tableName ?? "vectors";
68
- this.cacheTTL = options.cacheTTL ?? 5 * 60 * 1000;
65
+ this.db = this.openDatabase();
69
66
  }
70
67
  async initialize() {
71
68
  if (this.initialized) {
72
69
  return;
73
70
  }
74
- this.db = await lancedb.connect(this.dbPath);
75
- const tables = await this.db.tableNames();
76
- if (!tables.includes(this.tableName)) {
77
- await this.createTable();
78
- }
79
- else {
80
- this.table = await this.db.openTable(this.tableName);
81
- const schema = await this.table.getSchema();
82
- if (!this.hasRequiredSchema(schema)) {
83
- logger.warn(`[LanceDB] Schema mismatch for table "${this.tableName}", recreating.`);
84
- await this.db.dropTable(this.tableName);
85
- await this.createTable();
86
- }
71
+ const db = this.getDb();
72
+ db.exec(`
73
+ CREATE TABLE IF NOT EXISTS vector_meta (
74
+ chunk_id TEXT PRIMARY KEY,
75
+ project_id TEXT NOT NULL,
76
+ snapshot_id TEXT NOT NULL,
77
+ file_path TEXT NOT NULL,
78
+ start_line INTEGER NOT NULL,
79
+ end_line INTEGER NOT NULL,
80
+ content_hash TEXT NOT NULL,
81
+ chunk_type TEXT NOT NULL DEFAULT '',
82
+ primary_symbol TEXT NOT NULL DEFAULT ''
83
+ );
84
+
85
+ CREATE INDEX IF NOT EXISTS idx_vector_meta_snapshot_id
86
+ ON vector_meta(snapshot_id);
87
+
88
+ CREATE INDEX IF NOT EXISTS idx_vector_meta_project_id
89
+ ON vector_meta(project_id);
90
+
91
+ CREATE INDEX IF NOT EXISTS idx_vector_meta_file_path
92
+ ON vector_meta(file_path);
93
+ `);
94
+ const vecChunksExists = db
95
+ .prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'vec_chunks'")
96
+ .get();
97
+ if (!vecChunksExists) {
98
+ db.exec(`
99
+ CREATE VIRTUAL TABLE vec_chunks USING vec0(
100
+ chunk_id TEXT PRIMARY KEY,
101
+ embedding float[${this.vectorSize}]
102
+ )
103
+ `);
87
104
  }
88
105
  this.initialized = true;
89
106
  }
90
107
  async close() {
108
+ if (this.db) {
109
+ this.db.close();
110
+ this.db = null;
111
+ }
91
112
  this.initialized = false;
92
- this.db = null;
93
- this.table = null;
94
113
  }
95
114
  async upsert(vectors) {
96
- await this.runSerialized(async () => {
97
- await this.withTransientIoRetry("upsert", async () => {
98
- if (vectors.length === 0) {
99
- return;
100
- }
101
- if (!this.initialized) {
102
- await this.initialize();
103
- }
104
- const batchSize = 200;
105
- for (let index = 0; index < vectors.length; index += batchSize) {
106
- const batch = vectors.slice(index, index + batchSize);
107
- const data = batch.map((vector) => ({
108
- project_id: vector.projectId,
109
- chunk_id: vector.chunkId,
110
- snapshot_id: vector.snapshotId,
111
- file_path: vector.filePath,
112
- start_line: vector.startLine,
113
- end_line: vector.endLine,
114
- content_hash: vector.contentHash,
115
- chunk_type: vector.chunkType ?? "",
116
- primary_symbol: vector.primarySymbol ?? "",
117
- vector: Array.from(vector.embedding),
118
- }));
119
- await this.table.add(data);
120
- }
121
- });
115
+ if (vectors.length === 0) {
116
+ return;
117
+ }
118
+ await this.initialize();
119
+ const db = this.getDb();
120
+ const deleteVectorStatement = db.prepare("DELETE FROM vec_chunks WHERE chunk_id = ?");
121
+ const deleteMetaStatement = db.prepare("DELETE FROM vector_meta WHERE chunk_id = ?");
122
+ const insertMetaStatement = db.prepare(`
123
+ INSERT INTO vector_meta (
124
+ chunk_id,
125
+ project_id,
126
+ snapshot_id,
127
+ file_path,
128
+ start_line,
129
+ end_line,
130
+ content_hash,
131
+ chunk_type,
132
+ primary_symbol
133
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
134
+ `);
135
+ const insertVectorStatement = db.prepare("INSERT INTO vec_chunks (chunk_id, embedding) VALUES (?, vec_f32(?))");
136
+ const upsertBatch = db.transaction((batch) => {
137
+ for (const vector of batch) {
138
+ deleteVectorStatement.run(vector.chunkId);
139
+ deleteMetaStatement.run(vector.chunkId);
140
+ insertMetaStatement.run(vector.chunkId, vector.projectId, vector.snapshotId, vector.filePath, vector.startLine, vector.endLine, vector.contentHash, vector.chunkType ?? "", vector.primarySymbol ?? "");
141
+ insertVectorStatement.run(vector.chunkId, this.embeddingToBuffer(vector.embedding));
142
+ }
122
143
  });
144
+ for (let index = 0; index < vectors.length; index += UPSERT_BATCH_SIZE) {
145
+ const batch = vectors.slice(index, index + UPSERT_BATCH_SIZE);
146
+ upsertBatch(batch);
147
+ }
123
148
  }
124
149
  async search(queryEmbedding, topK, filters) {
125
- return this.runSerialized(async () => {
126
- return this.withTransientIoRetry("search", async () => {
127
- if (!filters.projectId) {
128
- throw new Error("projectId is required in filters for search");
129
- }
130
- if (!this.initialized) {
131
- await this.initialize();
132
- }
133
- await this.refreshCacheIfNeeded();
134
- await this.reopenTableIfNeeded();
135
- const prefilter = await this.buildPrefilter(filters);
136
- let results;
137
- if (prefilter &&
138
- (typeof this.table.query === "function" ||
139
- typeof this.table.filter === "function")) {
140
- const rows = typeof this.table.query === "function"
141
- ? await this.table
142
- .query()
143
- .where(prefilter)
144
- .limit(COPY_VECTORS_QUERY_LIMIT)
145
- .select([
146
- "chunk_id",
147
- "snapshot_id",
148
- "file_path",
149
- "start_line",
150
- "end_line",
151
- "content_hash",
152
- "chunk_type",
153
- "primary_symbol",
154
- "vector",
155
- ])
156
- .toArray({ batchSize: 1024 })
157
- : await this.table
158
- .filter(prefilter)
159
- .limit(COPY_VECTORS_QUERY_LIMIT)
160
- .select([
161
- "chunk_id",
162
- "snapshot_id",
163
- "file_path",
164
- "start_line",
165
- "end_line",
166
- "content_hash",
167
- "chunk_type",
168
- "primary_symbol",
169
- "vector",
170
- ])
171
- .toArray();
172
- results = rows
173
- .map((row) => {
174
- const vector = Array.isArray(row.vector)
175
- ? row.vector
176
- : Array.from(row.vector ?? []);
177
- return {
178
- ...row,
179
- _distance: this.euclideanDistance(queryEmbedding, vector),
180
- };
181
- })
182
- .sort((left, right) => left._distance - right._distance)
183
- .slice(0, topK);
184
- }
185
- else {
186
- const searchQuery = this.table.search(queryEmbedding).limit(topK);
187
- results = prefilter
188
- ? await searchQuery.where(prefilter).toArray()
189
- : await searchQuery.toArray();
190
- }
191
- return results.map((result) => ({
192
- chunkId: result.chunk_id,
193
- snapshotId: result.snapshot_id,
194
- filePath: result.file_path,
195
- startLine: result.start_line,
196
- endLine: result.end_line,
197
- contentHash: result.content_hash,
198
- chunkType: typeof result.chunk_type === "string"
199
- ? result.chunk_type
200
- : undefined,
201
- primarySymbol: typeof result.primary_symbol === "string"
202
- ? result.primary_symbol
203
- : undefined,
204
- score: 1 /
205
- (1 + (typeof result._distance === "number" ? result._distance : 0)),
206
- distance: typeof result._distance === "number" ? result._distance : 0,
207
- }));
208
- });
209
- });
150
+ if (!filters.projectId) {
151
+ throw new Error("projectId is required in filters for search");
152
+ }
153
+ await this.initialize();
154
+ const db = this.getDb();
155
+ const conditions = ["vm.project_id = ?"];
156
+ const values = [filters.projectId];
157
+ const prefilter = this.buildPrefilter(filters, "vm");
158
+ if (prefilter) {
159
+ conditions.push(prefilter);
160
+ }
161
+ const rows = db
162
+ .prepare(`
163
+ SELECT vm.*, vec_distance_L2(vc.embedding, vec_f32(?)) AS distance
164
+ FROM vec_chunks vc
165
+ JOIN vector_meta vm ON vc.chunk_id = vm.chunk_id
166
+ WHERE ${conditions.join(" AND ")}
167
+ ORDER BY distance
168
+ LIMIT ?
169
+ `)
170
+ .all(this.embeddingToBuffer(queryEmbedding), ...values, topK);
171
+ return rows.map((row) => ({
172
+ chunkId: row.chunk_id,
173
+ snapshotId: row.snapshot_id,
174
+ filePath: row.file_path,
175
+ startLine: row.start_line,
176
+ endLine: row.end_line,
177
+ contentHash: row.content_hash,
178
+ chunkType: row.chunk_type || undefined,
179
+ primarySymbol: row.primary_symbol || undefined,
180
+ score: 1 / (1 + row.distance),
181
+ distance: row.distance,
182
+ }));
210
183
  }
211
184
  async countVectors(filters) {
212
- return this.runSerialized(async () => {
213
- return this.withTransientIoRetry("countVectors", async () => {
214
- if (!filters.projectId) {
215
- throw new Error("projectId is required in filters for countVectors");
216
- }
217
- if (!this.initialized) {
218
- await this.initialize();
219
- }
220
- await this.refreshCacheIfNeeded();
221
- await this.reopenTableIfNeeded();
222
- const prefilter = await this.buildPrefilter(filters);
223
- if (typeof this.table.countRows === "function") {
224
- return prefilter
225
- ? await this.table.countRows(prefilter)
226
- : await this.table.countRows();
227
- }
228
- if (typeof this.table.filter === "function") {
229
- logger.warn("[LanceDB] countRows not available, falling back to filter-based count");
230
- const results = await this.table
231
- .filter(prefilter || "1 = 1")
232
- .limit(COPY_VECTORS_QUERY_LIMIT)
233
- .select(["chunk_id"])
234
- .toArray();
235
- return results.length;
236
- }
237
- if (typeof this.table.query === "function") {
238
- logger.warn("[LanceDB] countRows not available, falling back to query-based count");
239
- const query = this.table.query();
240
- const results = prefilter
241
- ? await query
242
- .where(prefilter)
243
- .limit(COPY_VECTORS_QUERY_LIMIT)
244
- .select(["chunk_id"])
245
- .toArray({ batchSize: 1024 })
246
- : await query
247
- .limit(COPY_VECTORS_QUERY_LIMIT)
248
- .select(["chunk_id"])
249
- .toArray({
250
- batchSize: 1024,
251
- });
252
- return results.length;
253
- }
254
- throw new Error("[LanceDB] countVectors requires countRows(), filter(), or query() support for exhaustive results");
255
- });
256
- });
185
+ if (!filters.projectId) {
186
+ throw new Error("projectId is required in filters for countVectors");
187
+ }
188
+ await this.initialize();
189
+ const db = this.getDb();
190
+ const conditions = ["project_id = ?"];
191
+ const values = [filters.projectId];
192
+ const prefilter = this.buildPrefilter(filters);
193
+ if (prefilter) {
194
+ conditions.push(prefilter);
195
+ }
196
+ const row = db
197
+ .prepare(`SELECT COUNT(*) AS count FROM vector_meta WHERE ${conditions.join(" AND ")}`)
198
+ .get(...values);
199
+ return row.count;
257
200
  }
258
201
  async deleteBySnapshot(projectId, snapshotId) {
259
- await this.runSerialized(async () => {
260
- await this.withTransientIoRetry("deleteBySnapshot", async () => {
261
- void projectId;
262
- if (!this.initialized) {
263
- await this.initialize();
264
- }
265
- await this.table.delete(`snapshot_id = '${this.escapeSqlLiteral(snapshotId.toString())}'`);
266
- });
267
- });
202
+ await this.initialize();
203
+ const db = this.getDb();
204
+ db.transaction(() => {
205
+ db.prepare(`
206
+ DELETE FROM vec_chunks
207
+ WHERE chunk_id IN (
208
+ SELECT chunk_id FROM vector_meta
209
+ WHERE project_id = ? AND snapshot_id = ?
210
+ )
211
+ `).run(projectId, snapshotId);
212
+ db.prepare("DELETE FROM vector_meta WHERE project_id = ? AND snapshot_id = ?").run(projectId, snapshotId);
213
+ })();
268
214
  }
269
215
  async copyVectors(projectId, fromSnapshotId, toSnapshotId, excludeFilePaths) {
270
- await this.runSerialized(async () => {
271
- await this.withTransientIoRetry("copyVectors", async () => {
272
- if (!this.initialized) {
273
- await this.initialize();
274
- }
275
- await this.refreshCacheIfNeeded();
276
- await this.reopenTableIfNeeded();
277
- const filter = `snapshot_id = '${this.escapeSqlLiteral(fromSnapshotId.toString())}'`;
278
- const results = typeof this.table.query === "function"
279
- ? await this.table
280
- .query()
281
- .where(filter)
282
- .limit(COPY_VECTORS_QUERY_LIMIT)
283
- .select([
284
- "project_id",
285
- "chunk_id",
286
- "snapshot_id",
287
- "file_path",
288
- "start_line",
289
- "end_line",
290
- "content_hash",
291
- "chunk_type",
292
- "primary_symbol",
293
- "vector",
294
- ])
295
- .toArray({ batchSize: 1024 })
296
- : typeof this.table.filter === "function"
297
- ? await this.table
298
- .filter(filter)
299
- .limit(COPY_VECTORS_QUERY_LIMIT)
300
- .select([
301
- "project_id",
302
- "chunk_id",
303
- "snapshot_id",
304
- "file_path",
305
- "start_line",
306
- "end_line",
307
- "content_hash",
308
- "chunk_type",
309
- "primary_symbol",
310
- "vector",
311
- ])
312
- .toArray()
313
- : await this.table
314
- .search(Array(this.vectorSize).fill(0))
315
- .limit(COPY_VECTORS_QUERY_LIMIT)
316
- .where(filter)
317
- .toArray();
318
- const filtered = results.filter((row) => !excludeFilePaths.includes(String(row.file_path)));
319
- if (filtered.length === 0) {
320
- return;
321
- }
322
- await this.table.add(filtered.map((row) => ({
323
- project_id: row.project_id ?? projectId.toString(),
324
- chunk_id: row.chunk_id,
325
- snapshot_id: toSnapshotId.toString(),
326
- file_path: row.file_path,
327
- start_line: row.start_line,
328
- end_line: row.end_line,
329
- content_hash: row.content_hash,
330
- chunk_type: row.chunk_type ?? "",
331
- primary_symbol: row.primary_symbol ?? "",
332
- vector: row.vector,
333
- })));
334
- });
216
+ await this.initialize();
217
+ const db = this.getDb();
218
+ const conditions = ["vm.project_id = ?", "vm.snapshot_id = ?"];
219
+ const values = [projectId, fromSnapshotId];
220
+ if (excludeFilePaths.length > 0) {
221
+ const placeholders = excludeFilePaths.map(() => "?").join(", ");
222
+ conditions.push(`vm.file_path NOT IN (${placeholders})`);
223
+ values.push(...excludeFilePaths);
224
+ }
225
+ const rows = db
226
+ .prepare(`
227
+ SELECT vm.*, vc.embedding
228
+ FROM vector_meta vm
229
+ JOIN vec_chunks vc ON vc.chunk_id = vm.chunk_id
230
+ WHERE ${conditions.join(" AND ")}
231
+ `)
232
+ .all(...values);
233
+ if (rows.length === 0) {
234
+ return;
235
+ }
236
+ const deleteVectorStatement = db.prepare("DELETE FROM vec_chunks WHERE chunk_id = ?");
237
+ const deleteMetaStatement = db.prepare("DELETE FROM vector_meta WHERE chunk_id = ?");
238
+ const insertMetaStatement = db.prepare(`
239
+ INSERT INTO vector_meta (
240
+ chunk_id,
241
+ project_id,
242
+ snapshot_id,
243
+ file_path,
244
+ start_line,
245
+ end_line,
246
+ content_hash,
247
+ chunk_type,
248
+ primary_symbol
249
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
250
+ `);
251
+ const insertVectorStatement = db.prepare("INSERT INTO vec_chunks (chunk_id, embedding) VALUES (?, vec_f32(?))");
252
+ const copyBatch = db.transaction((batch) => {
253
+ for (const row of batch) {
254
+ deleteVectorStatement.run(row.chunk_id);
255
+ deleteMetaStatement.run(row.chunk_id);
256
+ insertMetaStatement.run(row.chunk_id, row.project_id, toSnapshotId, row.file_path, row.start_line, row.end_line, row.content_hash, row.chunk_type, row.primary_symbol);
257
+ insertVectorStatement.run(row.chunk_id, this.normalizeEmbeddingValue(row.embedding));
258
+ }
335
259
  });
260
+ for (let index = 0; index < rows.length; index += UPSERT_BATCH_SIZE) {
261
+ const batch = rows.slice(index, index + UPSERT_BATCH_SIZE);
262
+ copyBatch(batch);
263
+ }
336
264
  }
337
265
  async deleteByProject(projectId) {
338
- await this.runSerialized(async () => {
339
- await this.withTransientIoRetry("deleteByProject", async () => {
340
- void projectId;
341
- await this.close();
342
- if (!(0, node_fs_1.existsSync)(this.dbPath)) {
343
- return;
344
- }
345
- (0, node_fs_1.rmSync)(this.dbPath, { recursive: true, force: true });
346
- });
347
- });
348
- }
349
- async runSerialized(operation) {
350
- const run = this.operationQueue.then(operation, operation);
351
- this.operationQueue = run.then(() => undefined, () => undefined);
352
- return run;
266
+ await this.initialize();
267
+ const db = this.getDb();
268
+ db.transaction(() => {
269
+ db.prepare(`
270
+ DELETE FROM vec_chunks
271
+ WHERE chunk_id IN (
272
+ SELECT chunk_id FROM vector_meta WHERE project_id = ?
273
+ )
274
+ `).run(projectId);
275
+ db.prepare("DELETE FROM vector_meta WHERE project_id = ?").run(projectId);
276
+ })();
277
+ const legacyVectorsPath = node_path_1.default.join(node_path_1.default.dirname(this.dbPath), "vectors");
278
+ if ((0, node_fs_1.existsSync)(legacyVectorsPath)) {
279
+ (0, node_fs_1.rmSync)(legacyVectorsPath, { recursive: true, force: true });
280
+ }
353
281
  }
354
- isTransientIoError(error) {
355
- const message = error instanceof Error ? error.message : String(error);
356
- return (message.includes("LanceError(IO)") &&
357
- (message.includes("Not found:") ||
358
- message.includes("Did not find any data files") ||
359
- message.includes("/vectors.lance/data/")));
282
+ openDatabase() {
283
+ const db = new better_sqlite3_1.default(this.dbPath);
284
+ sqliteVec.load(db);
285
+ return db;
360
286
  }
361
- async withTransientIoRetry(operationName, operation) {
362
- try {
363
- return await operation();
364
- }
365
- catch (error) {
366
- if (!this.isTransientIoError(error)) {
367
- throw error;
368
- }
369
- const message = error instanceof Error ? error.message : String(error);
370
- logger.warn(`[LanceDB] ${operationName} hit transient IO error, reopening and retrying once: ${message}`);
371
- await this.close();
372
- await this.initialize();
373
- return operation();
287
+ getDb() {
288
+ if (!this.db) {
289
+ this.db = this.openDatabase();
374
290
  }
291
+ return this.db;
375
292
  }
376
- async refreshCacheIfNeeded() {
377
- const now = Date.now();
378
- if (this.cacheTTL <= 0) {
379
- if (this.table) {
380
- this.table = null;
381
- }
382
- this.lastCacheRefresh = now;
383
- return;
293
+ embeddingToBuffer(embedding) {
294
+ return Buffer.from(new Float32Array(embedding).buffer);
295
+ }
296
+ normalizeEmbeddingValue(embedding) {
297
+ if (Buffer.isBuffer(embedding)) {
298
+ return embedding;
384
299
  }
385
- if (this.table && now - this.lastCacheRefresh > this.cacheTTL) {
386
- this.table = null;
387
- this.lastCacheRefresh = now;
388
- logger.debug(`[LanceDB] Cache refreshed (TTL: ${this.cacheTTL}ms)`);
300
+ if (embedding instanceof Uint8Array) {
301
+ return Buffer.from(embedding);
389
302
  }
390
- }
391
- async reopenTableIfNeeded() {
392
- if (!this.table) {
393
- this.table = await this.db.openTable(this.tableName);
303
+ if (embedding instanceof ArrayBuffer) {
304
+ return Buffer.from(embedding);
394
305
  }
306
+ throw new Error("Unsupported sqlite-vec embedding value returned from database");
395
307
  }
396
- async buildPrefilter(filters) {
308
+ buildPrefilter(filters, alias) {
397
309
  const conditions = [];
310
+ const prefix = alias ? `${alias}.` : "";
398
311
  if (filters.snapshotId) {
399
- conditions.push(`snapshot_id = '${this.escapeSqlLiteral(filters.snapshotId)}'`);
312
+ conditions.push(`${prefix}snapshot_id = '${this.escapeSqlLiteral(filters.snapshotId)}'`);
400
313
  }
401
314
  if (filters.filePath) {
402
- conditions.push(`file_path = '${this.escapeSqlLiteral(filters.filePath)}'`);
315
+ conditions.push(`${prefix}file_path = '${this.escapeSqlLiteral(filters.filePath)}'`);
403
316
  }
404
317
  else if (filters.pathPrefix) {
405
- conditions.push(`file_path LIKE '${this.escapeSqlLike(filters.pathPrefix)}%'`);
318
+ conditions.push(`${prefix}file_path LIKE '${this.escapeSqlLike(filters.pathPrefix)}%'`);
406
319
  }
407
320
  if (filters.chunkTypes && filters.chunkTypes.length > 0) {
408
321
  const normalizedChunkTypes = filters.chunkTypes
@@ -410,48 +323,11 @@ class LanceDbVectorStore {
410
323
  .filter((chunkType) => chunkType.length > 0)
411
324
  .map((chunkType) => `'${this.escapeSqlLiteral(chunkType)}'`);
412
325
  if (normalizedChunkTypes.length > 0) {
413
- conditions.push(`chunk_type IN (${normalizedChunkTypes.join(", ")})`);
326
+ conditions.push(`${prefix}chunk_type IN (${normalizedChunkTypes.join(", ")})`);
414
327
  }
415
328
  }
416
329
  return conditions.join(" AND ");
417
330
  }
418
- euclideanDistance(a, b) {
419
- const length = Math.min(a.length, b.length);
420
- let sum = 0;
421
- for (let index = 0; index < length; index += 1) {
422
- const delta = a[index] - b[index];
423
- sum += delta * delta;
424
- }
425
- return Math.sqrt(sum);
426
- }
427
- async createTable() {
428
- this.table = await this.db.createTable(this.tableName, [
429
- {
430
- project_id: "",
431
- chunk_id: "",
432
- snapshot_id: "",
433
- file_path: "",
434
- start_line: 0,
435
- end_line: 0,
436
- content_hash: "",
437
- chunk_type: "",
438
- primary_symbol: "",
439
- vector: Array(this.vectorSize).fill(0),
440
- },
441
- ]);
442
- }
443
- hasRequiredSchema(schema) {
444
- if (!schema?.fields) {
445
- return false;
446
- }
447
- const fields = new Set(schema.fields.map((field) => field.name));
448
- for (const column of exports.REQUIRED_COLUMNS) {
449
- if (!fields.has(column)) {
450
- return false;
451
- }
452
- }
453
- return true;
454
- }
455
331
  escapeSqlLiteral(value) {
456
332
  return value.replace(/'/g, "''");
457
333
  }
@@ -459,5 +335,6 @@ class LanceDbVectorStore {
459
335
  return this.escapeSqlLiteral(value).replace(/[%_]/g, (char) => `\\${char}`);
460
336
  }
461
337
  }
462
- exports.LanceDbVectorStore = LanceDbVectorStore;
338
+ exports.SqliteVecVectorStore = SqliteVecVectorStore;
339
+ exports.LanceDbVectorStore = SqliteVecVectorStore;
463
340
  //# sourceMappingURL=vectors.js.map