Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/core/indexing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ export async function indexDocument(
try {
const vecBuffer = Buffer.from(new Float32Array(embedding).buffer);
insertEmbedding.run(chunkId, vecBuffer);
} catch {
// Vector table might not exist — skip silently
log.debug({ chunkId }, "Skipped vector insertion (sqlite-vec may not be loaded)");
} catch (err) {
log.debug({ chunkId, err }, "Skipped vector insertion (sqlite-vec may not be loaded)");
}
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/core/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export async function searchDocuments(
score: 1 - row.distance, // Convert distance to similarity
avgRating: row.avg_rating,
}));
} catch {
log.warn("Vector search unavailable, falling back to keyword search");
} catch (err) {
log.warn({ err }, "Vector search unavailable, falling back to keyword search");
return keywordSearch(db, options, limit);
}
}
Expand All @@ -139,8 +139,8 @@ function keywordSearch(
// Try FTS5 first
try {
return fts5Search(db, options, limit);
} catch {
log.debug("FTS5 unavailable, falling back to LIKE search");
} catch (err) {
log.debug({ err }, "FTS5 unavailable, falling back to LIKE search");
}

const words = options.query.split(/\s+/).filter((w) => w.length > 2);
Expand Down
5 changes: 4 additions & 1 deletion src/core/url-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export async function fetchAndConvert(url: string): Promise<FetchedDocument> {
};
} catch (err) {
if (err instanceof FetchError) throw err;
throw new FetchError(`Failed to fetch URL: ${url} — ${String(err)}`, err);
throw new FetchError(
`Failed to fetch URL: ${url} — ${err instanceof Error ? err.message : String(err)}`,
err,
);
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ const MIGRATIONS: Record<number, string> = {
VALUES (new.content, new.id, new.document_id);
END;

-- Backfill existing chunks into FTS
INSERT INTO chunks_fts(content, chunk_id, document_id)
SELECT content, id, document_id FROM chunks;

INSERT INTO schema_version (version) VALUES (2);
`,
};

const FTS_BACKFILL_SQL = `
INSERT INTO chunks_fts(content, chunk_id, document_id)
SELECT content, id, document_id FROM chunks;
`;

/** Run pending migrations on the database. */
export function runMigrations(db: Database.Database): void {
const log = getLogger();
Expand Down Expand Up @@ -130,6 +131,13 @@ export function runMigrations(db: Database.Database): void {
});

migrate();

try {
db.exec(FTS_BACKFILL_SQL);
} catch (err) {
log.warn({ err }, "FTS backfill failed — new chunks will still be indexed via triggers");
}

log.info("Database migrations complete");
} catch (err) {
if (err instanceof DatabaseError) throw err;
Expand Down
Loading