feat(TRUEREF-0023): add sqlite-vec search pipeline
This commit is contained in:
@@ -6,6 +6,7 @@ import { readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import * as schema from './schema';
|
||||
import { loadSqliteVec, sqliteVecRowidTableName, sqliteVecTableName } from './sqlite-vec';
|
||||
import {
|
||||
repositories,
|
||||
repositoryVersions,
|
||||
@@ -24,6 +25,7 @@ import {
|
||||
function createTestDb() {
|
||||
const client = new Database(':memory:');
|
||||
client.pragma('foreign_keys = ON');
|
||||
loadSqliteVec(client);
|
||||
|
||||
const db = drizzle(client, { schema });
|
||||
|
||||
@@ -266,10 +268,11 @@ describe('snippets table', () => {
|
||||
|
||||
describe('snippet_embeddings table', () => {
|
||||
let db: ReturnType<typeof createTestDb>['db'];
|
||||
let client: Database.Database;
|
||||
let snippetId: string;
|
||||
|
||||
beforeEach(() => {
|
||||
({ db } = createTestDb());
|
||||
({ db, client } = createTestDb());
|
||||
db.insert(repositories).values(makeRepo()).run();
|
||||
const docId = crypto.randomUUID();
|
||||
db.insert(documents)
|
||||
@@ -344,6 +347,30 @@ describe('snippet_embeddings table', () => {
|
||||
const result = db.select().from(snippetEmbeddings).all();
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('keeps the relational schema free of vec_embedding and retains the profile index', () => {
|
||||
const columns = client
|
||||
.prepare("PRAGMA table_info('snippet_embeddings')")
|
||||
.all() as Array<{ name: string }>;
|
||||
expect(columns.map((column) => column.name)).not.toContain('vec_embedding');
|
||||
|
||||
const indexes = client
|
||||
.prepare("PRAGMA index_list('snippet_embeddings')")
|
||||
.all() as Array<{ name: string }>;
|
||||
expect(indexes.map((index) => index.name)).toContain('idx_embeddings_profile');
|
||||
});
|
||||
|
||||
it('loads sqlite-vec idempotently and derives deterministic per-profile table names', () => {
|
||||
expect(() => loadSqliteVec(client)).not.toThrow();
|
||||
const tableName = sqliteVecTableName('local-default');
|
||||
const rowidTableName = sqliteVecRowidTableName('local-default');
|
||||
|
||||
expect(tableName).toMatch(/^snippet_embeddings_vec_local_default_[0-9a-f]{8}$/);
|
||||
expect(rowidTableName).toMatch(/^snippet_embeddings_vec_rowids_local_default_[0-9a-f]{8}$/);
|
||||
expect(sqliteVecTableName('local-default')).toBe(tableName);
|
||||
expect(sqliteVecRowidTableName('local-default')).toBe(rowidTableName);
|
||||
expect(sqliteVecTableName('local-default')).not.toBe(sqliteVecTableName('openai/custom'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('indexing_jobs table', () => {
|
||||
|
||||
Reference in New Issue
Block a user