Skip to content

Commit 637ea13

Browse files
authored
fix: gracefully handle missing SQLite FTS5 on Windows (#65)
1 parent 039c922 commit 637ea13

5 files changed

Lines changed: 78 additions & 43 deletions

File tree

.github/logos/logo-mark.svg

Lines changed: 3 additions & 0 deletions
Loading

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1>skilld</h1>
1+
<h1><a href="https://skilld.dev"><img src=".github/logos/logo-mark.svg" alt="" width="28" height="28" valign="middle"></a> skilld</h1>
22

33
[![npm version](https://img.shields.io/npm/v/skilld?color=yellow)](https://npmjs.com/package/skilld)
44
[![npm downloads](https://img.shields.io/npm/dm/skilld?color=yellow)](https://npm.chart.dev/skilld)

pnpm-lock.yaml

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
overrides:
88
global-agent: ^4.1.3
99
catalog:
10-
'@mariozechner/pi-ai': ^0.63.1
10+
'@mariozechner/pi-ai': ^0.64.0
1111
'@mdream/crawl': ^1.0.3
1212
'@types/semver': ^7.7.1
1313
bumpp: ^11.0.1
@@ -36,7 +36,7 @@ catalogs:
3636
mlly: ^1.8.2
3737
oxc-parser: ^0.121.0
3838
p-limit: ^7.3.0
39-
sqlite-vec: ^0.1.7
39+
sqlite-vec: ^0.1.8
4040
tinyglobby: ^0.2.15
4141
unist-util-visit: ^5.1.0
4242
dev-build:

src/retriv/index.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,47 @@ export type { ChunkEntity, Document, IndexConfig, IndexPhase, IndexProgress, Sea
66
type RetrivInstance = Awaited<ReturnType<typeof getDb>>
77

88
export class SearchDepsUnavailableError extends Error {
9-
constructor(cause: unknown) {
10-
super('Search dependencies unavailable (sqlite-vec or retriv not installed). Search indexing skipped.')
9+
constructor(cause: unknown, message?: string) {
10+
super(message ?? 'Search dependencies unavailable (sqlite-vec or retriv not installed). Search indexing skipped.')
1111
this.name = 'SearchDepsUnavailableError'
1212
this.cause = cause
1313
}
1414
}
1515

16+
let _fts5Available: boolean | null = null
17+
18+
/**
19+
* Probe whether SQLite FTS5 module is available.
20+
* Windows Node.js binaries often ship without FTS5 compiled in.
21+
*/
22+
function checkFts5(): boolean {
23+
if (_fts5Available !== null)
24+
return _fts5Available
25+
const nodeSqlite = globalThis.process?.getBuiltinModule?.('node:sqlite') as typeof import('node:sqlite') | undefined
26+
if (!nodeSqlite) {
27+
_fts5Available = false
28+
return false
29+
}
30+
const db = new nodeSqlite.DatabaseSync(':memory:')
31+
try {
32+
db.exec('CREATE VIRTUAL TABLE _fts5_probe USING fts5(content)')
33+
db.exec('DROP TABLE _fts5_probe')
34+
_fts5Available = true
35+
}
36+
catch {
37+
_fts5Available = false
38+
}
39+
finally {
40+
db.close()
41+
}
42+
return _fts5Available
43+
}
44+
1645
// Dynamic imports: retriv/chunkers/auto eagerly loads typescript which may not be installed (e.g. npx)
1746
export async function getDb(config: Pick<IndexConfig, 'dbPath'>) {
47+
if (!checkFts5())
48+
throw new SearchDepsUnavailableError(new Error('FTS5 module not available'), 'SQLite FTS5 module not available. Search indexing skipped. On Windows, run from WSL where FTS5 is included.')
49+
1850
let createRetriv, autoChunker, sqliteMod, sqliteVec, transformersJs, cachedEmbeddings
1951
try {
2052
;([

0 commit comments

Comments
 (0)