daftari 1.7.0 → 1.8.0
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.
- package/CHANGELOG.md +53 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +97 -32
- package/dist/index.js.map +1 -1
- package/dist/search/hybrid.js +3 -3
- package/dist/search/hybrid.js.map +1 -1
- package/dist/search/index-state.d.ts +17 -0
- package/dist/search/index-state.d.ts.map +1 -0
- package/dist/search/index-state.js +68 -0
- package/dist/search/index-state.js.map +1 -0
- package/dist/search/reindex.d.ts +4 -0
- package/dist/search/reindex.d.ts.map +1 -1
- package/dist/search/reindex.js +238 -34
- package/dist/search/reindex.js.map +1 -1
- package/dist/storage/index-db.d.ts +14 -3
- package/dist/storage/index-db.d.ts.map +1 -1
- package/dist/storage/index-db.js +98 -20
- package/dist/storage/index-db.js.map +1 -1
- package/dist/tools/search.d.ts.map +1 -1
- package/dist/tools/search.js +37 -8
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/write.d.ts.map +1 -1
- package/dist/tools/write.js +28 -0
- package/dist/tools/write.js.map +1 -1
- package/package.json +1 -1
package/dist/search/reindex.js
CHANGED
|
@@ -4,16 +4,105 @@
|
|
|
4
4
|
// from scratch — there is no incremental update path to drift out of sync.
|
|
5
5
|
// Called on server start and by the vault_reindex tool / --reindex CLI flag.
|
|
6
6
|
//
|
|
7
|
-
// Embedding is
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
// only the
|
|
7
|
+
// Embedding is content-addressed: each chunk's text is hashed (sha256), and
|
|
8
|
+
// the embeddings table is keyed by (content_hash, model). A reindex hashes
|
|
9
|
+
// every chunk, asks the cache which (hash, model) pairs already exist, and
|
|
10
|
+
// only embeds the misses. Edits to one file re-embed that file's changed
|
|
11
|
+
// chunks; renames, moved paragraphs, and identical text in two files all
|
|
12
|
+
// hit the cache and embed zero. Orphaned cache rows (chunks that no longer
|
|
13
|
+
// reference them) are reaped at the end of the pass.
|
|
14
|
+
//
|
|
15
|
+
// If the model is unavailable the documents (and their BM25 tokens) still
|
|
16
|
+
// index; chunks are written with their content_hash but no embedding row is
|
|
17
|
+
// inserted, so the join in vector.ts comes back null and search degrades to
|
|
18
|
+
// lexical-only.
|
|
19
|
+
import { stat } from "node:fs/promises";
|
|
11
20
|
import { parseDocument } from "../frontmatter/parser.js";
|
|
12
21
|
import { err, ok } from "../frontmatter/types.js";
|
|
13
|
-
import { clearIndex, deleteDocument, documentCount,
|
|
22
|
+
import { clearIndex, deleteDocument, documentCount, existingEmbeddingHashes, gcOrphanedEmbeddings, getMeta, insertChunkRow, insertDocument, insertEmbedding, openIndexDb, setMeta, } from "../storage/index-db.js";
|
|
14
23
|
import { listFiles, readFile, resolveVaultPath } from "../storage/local.js";
|
|
24
|
+
import { sha256Hex } from "../utils/hash.js";
|
|
15
25
|
import { tokenize } from "./bm25.js";
|
|
16
|
-
import { chunkText, EMBEDDING_DIM, embed } from "./vector.js";
|
|
26
|
+
import { chunkText, EMBEDDING_DIM, EMBEDDING_MODEL, embed } from "./vector.js";
|
|
27
|
+
// Manifest key in the meta table: JSON object mapping vault-relative path to
|
|
28
|
+
// mtime in ms. Written at the end of a successful reindex and updated by
|
|
29
|
+
// indexDocument after each incremental write, so a startup freshness check
|
|
30
|
+
// can decide whether the persisted index already reflects the files on disk.
|
|
31
|
+
const MANIFEST_META_KEY = "vault_manifest";
|
|
32
|
+
// Walks the vault and produces a fresh path→mtimeMs map. Returns null if any
|
|
33
|
+
// file cannot be stat'd or the file listing fails — caller treats null as
|
|
34
|
+
// "can't prove freshness, fall back to a full reindex."
|
|
35
|
+
async function buildManifest(vaultRoot) {
|
|
36
|
+
const list = await listFiles(vaultRoot);
|
|
37
|
+
if (!list.ok)
|
|
38
|
+
return null;
|
|
39
|
+
const manifest = {};
|
|
40
|
+
for (const relPath of list.value) {
|
|
41
|
+
const resolved = resolveVaultPath(vaultRoot, relPath);
|
|
42
|
+
if (!resolved.ok)
|
|
43
|
+
return null;
|
|
44
|
+
try {
|
|
45
|
+
const st = await stat(resolved.value);
|
|
46
|
+
manifest[relPath] = st.mtimeMs;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return manifest;
|
|
53
|
+
}
|
|
54
|
+
function readManifest(db) {
|
|
55
|
+
const raw = getMeta(db, MANIFEST_META_KEY);
|
|
56
|
+
if (!raw)
|
|
57
|
+
return null;
|
|
58
|
+
try {
|
|
59
|
+
const parsed = JSON.parse(raw);
|
|
60
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
61
|
+
return null;
|
|
62
|
+
return parsed;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function writeManifest(db, manifest) {
|
|
69
|
+
setMeta(db, MANIFEST_META_KEY, JSON.stringify(manifest));
|
|
70
|
+
}
|
|
71
|
+
function manifestsMatch(a, b) {
|
|
72
|
+
const aKeys = Object.keys(a);
|
|
73
|
+
const bKeys = Object.keys(b);
|
|
74
|
+
if (aKeys.length !== bKeys.length)
|
|
75
|
+
return false;
|
|
76
|
+
for (const key of aKeys) {
|
|
77
|
+
if (a[key] !== b[key])
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
// Returns true when the persisted index already reflects every markdown file
|
|
83
|
+
// on disk: doc count is non-zero, a manifest exists, and every file's mtime
|
|
84
|
+
// matches the stored value. Used by `main()` to skip a 20+ minute re-embed
|
|
85
|
+
// pass on every restart of a vault that hasn't changed.
|
|
86
|
+
export async function isIndexFresh(vaultRoot) {
|
|
87
|
+
const dbResult = openIndexDb(vaultRoot);
|
|
88
|
+
if (!dbResult.ok)
|
|
89
|
+
return false;
|
|
90
|
+
const db = dbResult.value;
|
|
91
|
+
try {
|
|
92
|
+
if (documentCount(db) === 0)
|
|
93
|
+
return false;
|
|
94
|
+
const stored = readManifest(db);
|
|
95
|
+
if (!stored)
|
|
96
|
+
return false;
|
|
97
|
+
const current = await buildManifest(vaultRoot);
|
|
98
|
+
if (!current)
|
|
99
|
+
return false;
|
|
100
|
+
return manifestsMatch(stored, current);
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
db.close();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
17
106
|
// Reads and parses a single markdown file into the shape the index needs.
|
|
18
107
|
// Returns null when the file should be skipped (unreadable, or malformed YAML
|
|
19
108
|
// frontmatter) so a reindex never aborts on one bad file.
|
|
@@ -32,6 +121,8 @@ async function stageOne(vaultRoot, relPath) {
|
|
|
32
121
|
// BM25 indexes title, tags, and body together so a title- or tag-only
|
|
33
122
|
// match still ranks.
|
|
34
123
|
const tokens = tokenize(`${fm.title} ${fm.tags.join(" ")} ${body}`);
|
|
124
|
+
const chunks = chunkText(body);
|
|
125
|
+
const hashes = chunks.map((t) => sha256Hex(t));
|
|
35
126
|
return {
|
|
36
127
|
doc: {
|
|
37
128
|
path: relPath,
|
|
@@ -48,7 +139,8 @@ async function stageOne(vaultRoot, relPath) {
|
|
|
48
139
|
created: fm.created,
|
|
49
140
|
supersededBy: fm.superseded_by,
|
|
50
141
|
},
|
|
51
|
-
chunks
|
|
142
|
+
chunks,
|
|
143
|
+
hashes,
|
|
52
144
|
};
|
|
53
145
|
}
|
|
54
146
|
// Reads and parses every markdown file into the shape the index needs. A file
|
|
@@ -69,21 +161,23 @@ async function stageDocuments(vaultRoot) {
|
|
|
69
161
|
}
|
|
70
162
|
return ok({ staged, skipped });
|
|
71
163
|
}
|
|
72
|
-
|
|
164
|
+
// Inserts the chunk rows in a single transaction. Embeddings are persisted by
|
|
165
|
+
// the caller (with a model identifier) so the chunk write stays oblivious to
|
|
166
|
+
// which model produced the vectors.
|
|
167
|
+
function writeChunkRows(db, staged) {
|
|
73
168
|
let chunkCount = 0;
|
|
74
|
-
let cursor = 0;
|
|
75
169
|
const write = db.transaction(() => {
|
|
76
170
|
clearIndex(db);
|
|
77
|
-
for (const { doc, chunks } of staged) {
|
|
171
|
+
for (const { doc, chunks, hashes } of staged) {
|
|
78
172
|
insertDocument(db, doc);
|
|
79
173
|
chunks.forEach((text, chunkIndex) => {
|
|
80
|
-
|
|
174
|
+
const row = {
|
|
81
175
|
path: doc.path,
|
|
82
176
|
chunkIndex,
|
|
83
177
|
text,
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
178
|
+
contentHash: hashes[chunkIndex] ?? "",
|
|
179
|
+
};
|
|
180
|
+
insertChunkRow(db, row);
|
|
87
181
|
chunkCount += 1;
|
|
88
182
|
});
|
|
89
183
|
}
|
|
@@ -96,31 +190,94 @@ export async function reindexVault(vaultRoot, opts = {}) {
|
|
|
96
190
|
if (!staging.ok)
|
|
97
191
|
return staging;
|
|
98
192
|
const { staged, skipped } = staging.value;
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
for (const s of staged)
|
|
102
|
-
allChunkTexts.push(...s.chunks);
|
|
103
|
-
const embedResult = await embed(allChunkTexts, opts.onProgress);
|
|
104
|
-
const vectorEnabled = embedResult.ok;
|
|
105
|
-
const embeddings = embedResult.ok
|
|
106
|
-
? embedResult.value
|
|
107
|
-
: allChunkTexts.map(() => null);
|
|
193
|
+
// Open the index first so we can ask the embeddings cache which (hash,
|
|
194
|
+
// model) pairs already exist before deciding what to embed.
|
|
108
195
|
const dbResult = openIndexDb(vaultRoot);
|
|
109
196
|
if (!dbResult.ok)
|
|
110
197
|
return dbResult;
|
|
111
198
|
const db = dbResult.value;
|
|
112
199
|
const indexedAt = new Date().toISOString();
|
|
113
200
|
try {
|
|
114
|
-
|
|
201
|
+
// Flatten every chunk's text + hash so we can dedupe and query the cache
|
|
202
|
+
// in one shot. A single hash may appear in multiple files (or repeatedly
|
|
203
|
+
// in one file) — embed it once.
|
|
204
|
+
const allHashes = [];
|
|
205
|
+
const allTexts = [];
|
|
206
|
+
for (const s of staged) {
|
|
207
|
+
for (let i = 0; i < s.chunks.length; i++) {
|
|
208
|
+
const h = s.hashes[i] ?? "";
|
|
209
|
+
const t = s.chunks[i] ?? "";
|
|
210
|
+
allHashes.push(h);
|
|
211
|
+
allTexts.push(t);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const cached = existingEmbeddingHashes(db, EMBEDDING_MODEL, allHashes);
|
|
215
|
+
// Build the deduped miss list. Each unique missing hash gets embedded
|
|
216
|
+
// exactly once; identical chunk text in multiple places shares the row.
|
|
217
|
+
const missTextByHash = new Map();
|
|
218
|
+
for (let i = 0; i < allHashes.length; i++) {
|
|
219
|
+
const h = allHashes[i] ?? "";
|
|
220
|
+
if (cached.has(h))
|
|
221
|
+
continue;
|
|
222
|
+
if (missTextByHash.has(h))
|
|
223
|
+
continue;
|
|
224
|
+
missTextByHash.set(h, allTexts[i] ?? "");
|
|
225
|
+
}
|
|
226
|
+
const missHashes = [...missTextByHash.keys()];
|
|
227
|
+
const missTexts = missHashes.map((h) => missTextByHash.get(h) ?? "");
|
|
228
|
+
const totalChunks = allHashes.length;
|
|
229
|
+
const cacheHits = totalChunks - allHashes.filter((h) => !cached.has(h)).length;
|
|
230
|
+
let vectorEnabled = true;
|
|
231
|
+
if (missTexts.length > 0) {
|
|
232
|
+
const embedResult = await embed(missTexts, opts.onProgress);
|
|
233
|
+
if (embedResult.ok) {
|
|
234
|
+
const writeEmbeds = db.transaction(() => {
|
|
235
|
+
for (let i = 0; i < missHashes.length; i++) {
|
|
236
|
+
const h = missHashes[i] ?? "";
|
|
237
|
+
const vec = embedResult.value[i];
|
|
238
|
+
if (!vec)
|
|
239
|
+
continue;
|
|
240
|
+
insertEmbedding(db, h, EMBEDDING_MODEL, vec, indexedAt);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
writeEmbeds();
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
// Model unavailable. We still want documents + chunk rows so BM25
|
|
247
|
+
// works; vector ranking simply degrades to nothing for this reindex.
|
|
248
|
+
vectorEnabled = false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
else if (totalChunks === 0) {
|
|
252
|
+
// No chunks at all (empty vault). Treat as vectorEnabled=true by
|
|
253
|
+
// convention — there is nothing to embed but also nothing failed.
|
|
254
|
+
vectorEnabled = true;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
// Everything was cached. Vector ranking has data already, so the
|
|
258
|
+
// reindex did not need to load the model — still vector-enabled.
|
|
259
|
+
vectorEnabled = true;
|
|
260
|
+
}
|
|
261
|
+
const chunkCount = writeChunkRows(db, staged);
|
|
262
|
+
const orphansRemoved = gcOrphanedEmbeddings(db);
|
|
115
263
|
setMeta(db, "indexed_at", indexedAt);
|
|
116
264
|
setMeta(db, "vector_enabled", String(vectorEnabled));
|
|
117
265
|
setMeta(db, "embedding_dim", String(EMBEDDING_DIM));
|
|
266
|
+
setMeta(db, "embedding_model", EMBEDDING_MODEL);
|
|
267
|
+
// Persist a freshness manifest so the next startup can skip this whole
|
|
268
|
+
// pass when nothing on disk has changed.
|
|
269
|
+
const manifest = await buildManifest(vaultRoot);
|
|
270
|
+
if (manifest)
|
|
271
|
+
writeManifest(db, manifest);
|
|
118
272
|
return ok({
|
|
119
273
|
documentCount: staged.length,
|
|
120
274
|
chunkCount,
|
|
121
275
|
vectorEnabled,
|
|
122
276
|
skipped,
|
|
123
277
|
indexedAt,
|
|
278
|
+
embeddedCount: missHashes.length,
|
|
279
|
+
cacheHits,
|
|
280
|
+
orphansRemoved,
|
|
124
281
|
});
|
|
125
282
|
}
|
|
126
283
|
catch (e) {
|
|
@@ -135,8 +292,9 @@ export async function reindexVault(vaultRoot, opts = {}) {
|
|
|
135
292
|
//
|
|
136
293
|
// If the index has never been built it falls back to a full reindex, so the
|
|
137
294
|
// first write to a fresh vault still produces a complete index rather than a
|
|
138
|
-
// one-document one. Otherwise it re-stages just `relPath`,
|
|
139
|
-
//
|
|
295
|
+
// one-document one. Otherwise it re-stages just `relPath`, hashes its chunks,
|
|
296
|
+
// embeds only those whose (hash, model) pair is not already in the embeddings
|
|
297
|
+
// cache, evicts the document's stale chunk rows, and re-inserts.
|
|
140
298
|
export async function indexDocument(vaultRoot, relPath) {
|
|
141
299
|
const dbCheck = openIndexDb(vaultRoot);
|
|
142
300
|
if (!dbCheck.ok)
|
|
@@ -156,30 +314,76 @@ export async function indexDocument(vaultRoot, relPath) {
|
|
|
156
314
|
if (!staged) {
|
|
157
315
|
return err(new Error(`cannot index document: ${relPath}`));
|
|
158
316
|
}
|
|
159
|
-
const { doc, chunks } = staged;
|
|
160
|
-
const embedResult = await embed(chunks);
|
|
161
|
-
const vectorEnabled = embedResult.ok;
|
|
162
|
-
const embeddings = embedResult.ok
|
|
163
|
-
? embedResult.value
|
|
164
|
-
: chunks.map(() => null);
|
|
317
|
+
const { doc, chunks, hashes } = staged;
|
|
165
318
|
const dbResult = openIndexDb(vaultRoot);
|
|
166
319
|
if (!dbResult.ok)
|
|
167
320
|
return dbResult;
|
|
168
321
|
const db = dbResult.value;
|
|
322
|
+
const createdAt = new Date().toISOString();
|
|
169
323
|
try {
|
|
324
|
+
const cached = existingEmbeddingHashes(db, EMBEDDING_MODEL, hashes);
|
|
325
|
+
const missTextByHash = new Map();
|
|
326
|
+
for (let i = 0; i < hashes.length; i++) {
|
|
327
|
+
const h = hashes[i] ?? "";
|
|
328
|
+
if (cached.has(h))
|
|
329
|
+
continue;
|
|
330
|
+
if (missTextByHash.has(h))
|
|
331
|
+
continue;
|
|
332
|
+
missTextByHash.set(h, chunks[i] ?? "");
|
|
333
|
+
}
|
|
334
|
+
const missHashes = [...missTextByHash.keys()];
|
|
335
|
+
const missTexts = missHashes.map((h) => missTextByHash.get(h) ?? "");
|
|
336
|
+
let vectorEnabled = true;
|
|
337
|
+
if (missTexts.length > 0) {
|
|
338
|
+
const embedResult = await embed(missTexts);
|
|
339
|
+
if (embedResult.ok) {
|
|
340
|
+
const writeEmbeds = db.transaction(() => {
|
|
341
|
+
for (let i = 0; i < missHashes.length; i++) {
|
|
342
|
+
const h = missHashes[i] ?? "";
|
|
343
|
+
const vec = embedResult.value[i];
|
|
344
|
+
if (!vec)
|
|
345
|
+
continue;
|
|
346
|
+
insertEmbedding(db, h, EMBEDDING_MODEL, vec, createdAt);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
writeEmbeds();
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
vectorEnabled = false;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
170
355
|
const write = db.transaction(() => {
|
|
171
356
|
deleteDocument(db, doc.path);
|
|
172
357
|
insertDocument(db, doc);
|
|
173
358
|
chunks.forEach((text, chunkIndex) => {
|
|
174
|
-
|
|
359
|
+
insertChunkRow(db, {
|
|
175
360
|
path: doc.path,
|
|
176
361
|
chunkIndex,
|
|
177
362
|
text,
|
|
178
|
-
|
|
363
|
+
contentHash: hashes[chunkIndex] ?? "",
|
|
179
364
|
});
|
|
180
365
|
});
|
|
181
366
|
});
|
|
182
367
|
write();
|
|
368
|
+
// Keep the freshness manifest in sync with this single write so the next
|
|
369
|
+
// startup still sees a current index. Stat the file we just indexed and
|
|
370
|
+
// patch only its entry — re-statting the whole vault would defeat the
|
|
371
|
+
// point of the incremental path.
|
|
372
|
+
const stored = readManifest(db);
|
|
373
|
+
if (stored) {
|
|
374
|
+
const resolved = resolveVaultPath(vaultRoot, relPath);
|
|
375
|
+
if (resolved.ok) {
|
|
376
|
+
try {
|
|
377
|
+
const st = await stat(resolved.value);
|
|
378
|
+
stored[relPath] = st.mtimeMs;
|
|
379
|
+
writeManifest(db, stored);
|
|
380
|
+
}
|
|
381
|
+
catch {
|
|
382
|
+
// ignore — manifest just stays stale for this entry; worst case is
|
|
383
|
+
// one extra reindex on next startup.
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
183
387
|
return ok({ chunkCount: chunks.length, vectorEnabled });
|
|
184
388
|
}
|
|
185
389
|
catch (e)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QACT,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;AACH,CAAC"}
|
|
@@ -20,6 +20,7 @@ export interface IndexedChunk {
|
|
|
20
20
|
path: string;
|
|
21
21
|
chunkIndex: number;
|
|
22
22
|
text: string;
|
|
23
|
+
contentHash: string;
|
|
23
24
|
embedding: Float32Array | null;
|
|
24
25
|
}
|
|
25
26
|
export declare function indexDbPath(vaultRoot: string): string;
|
|
@@ -29,12 +30,22 @@ export declare function deleteDocument(db: IndexDb, path: string): void;
|
|
|
29
30
|
export declare function embeddingToBlob(vec: Float32Array): Buffer;
|
|
30
31
|
export declare function blobToEmbedding(blob: Buffer): Float32Array;
|
|
31
32
|
export declare function insertDocument(db: IndexDb, doc: IndexedDocument): void;
|
|
32
|
-
export
|
|
33
|
+
export interface ChunkRowInput {
|
|
34
|
+
path: string;
|
|
35
|
+
chunkIndex: number;
|
|
36
|
+
text: string;
|
|
37
|
+
contentHash: string;
|
|
38
|
+
}
|
|
39
|
+
export declare function insertChunkRow(db: IndexDb, chunk: ChunkRowInput): void;
|
|
40
|
+
export declare function existingEmbeddingHashes(db: IndexDb, model: string, hashes: string[]): Set<string>;
|
|
41
|
+
export declare function insertEmbedding(db: IndexDb, contentHash: string, model: string, embedding: Float32Array, createdAt: string): void;
|
|
42
|
+
export declare function gcOrphanedEmbeddings(db: IndexDb): number;
|
|
33
43
|
export declare function setMeta(db: IndexDb, key: string, value: string): void;
|
|
34
44
|
export declare function getAllDocuments(db: IndexDb): IndexedDocument[];
|
|
35
45
|
export declare function getDocument(db: IndexDb, path: string): IndexedDocument | null;
|
|
36
|
-
export declare function getAllChunks(db: IndexDb): IndexedChunk[];
|
|
37
|
-
export declare function getChunksForPath(db: IndexDb, path: string): IndexedChunk[];
|
|
46
|
+
export declare function getAllChunks(db: IndexDb, model: string): IndexedChunk[];
|
|
47
|
+
export declare function getChunksForPath(db: IndexDb, path: string, model: string): IndexedChunk[];
|
|
38
48
|
export declare function getMeta(db: IndexDb, key: string): string | null;
|
|
39
49
|
export declare function documentCount(db: IndexDb): number;
|
|
50
|
+
export declare function embeddingCount(db: IndexDb): number;
|
|
40
51
|
//# sourceMappingURL=index-db.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-db.d.ts","sourceRoot":"","sources":["../../src/storage/index-db.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index-db.d.ts","sourceRoot":"","sources":["../../src/storage/index-db.ts"],"names":[],"mappings":"AAsBA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAE/D,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC;AAIxC,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,YAAY,GAAG,IAAI,CAAC;CAChC;AAID,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAErD;AAuCD,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,O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E,MAAM,GAAG,eAAe,GAAG,IAAI,CAK7E;AAyBD,wBAAgB,YAAY,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,EAAE,CAWvE;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,EAAE,CAYzF;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK/D;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,CAGjD;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,CAGlD"}
|
package/dist/storage/index-db.js
CHANGED
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
//
|
|
3
3
|
// The index is a derived cache: it holds nothing the markdown files don't
|
|
4
4
|
// already hold, so .daftari/index.db can be deleted and rebuilt at any time
|
|
5
|
-
// (see search/reindex.ts).
|
|
5
|
+
// (see search/reindex.ts). Three tables carry the search payload:
|
|
6
6
|
//
|
|
7
|
-
// documents
|
|
8
|
-
//
|
|
9
|
-
// chunks
|
|
10
|
-
//
|
|
7
|
+
// documents — one row per markdown file: frontmatter fields, the full body,
|
|
8
|
+
// and the BM25 token list (JSON).
|
|
9
|
+
// chunks — one row per embedded text chunk: the chunk text and a
|
|
10
|
+
// content_hash (sha256 of the chunk text) that joins to the
|
|
11
|
+
// embeddings table for the current model.
|
|
12
|
+
// embeddings — one row per (content_hash, model) pair. Content-addressed,
|
|
13
|
+
// so identical chunk text shares one row across files and
|
|
14
|
+
// across reindexes. A model migration can keep the same
|
|
15
|
+
// content_hash present under two model values at once, which
|
|
16
|
+
// is why the primary key is composite.
|
|
11
17
|
//
|
|
12
18
|
// A small meta table records index-wide facts (embedding dimension, whether
|
|
13
19
|
// vectors were built, when the index was last rebuilt).
|
|
@@ -15,7 +21,7 @@ import { mkdirSync } from "node:fs";
|
|
|
15
21
|
import { join } from "node:path";
|
|
16
22
|
import Database from "better-sqlite3";
|
|
17
23
|
import { err, ok } from "../frontmatter/types.js";
|
|
18
|
-
const SCHEMA_VERSION = "
|
|
24
|
+
const SCHEMA_VERSION = "3";
|
|
19
25
|
// The .daftari control directory is excluded from vault listings, so the index
|
|
20
26
|
// file lives there without ever being mistaken for vault content.
|
|
21
27
|
export function indexDbPath(vaultRoot) {
|
|
@@ -38,12 +44,20 @@ CREATE TABLE IF NOT EXISTS documents (
|
|
|
38
44
|
superseded_by TEXT
|
|
39
45
|
);
|
|
40
46
|
CREATE TABLE IF NOT EXISTS chunks (
|
|
41
|
-
path
|
|
42
|
-
chunk_index
|
|
43
|
-
text
|
|
44
|
-
|
|
47
|
+
path TEXT NOT NULL,
|
|
48
|
+
chunk_index INTEGER NOT NULL,
|
|
49
|
+
text TEXT NOT NULL,
|
|
50
|
+
content_hash TEXT NOT NULL,
|
|
45
51
|
PRIMARY KEY (path, chunk_index)
|
|
46
52
|
);
|
|
53
|
+
CREATE INDEX IF NOT EXISTS idx_chunks_content_hash ON chunks(content_hash);
|
|
54
|
+
CREATE TABLE IF NOT EXISTS embeddings (
|
|
55
|
+
content_hash TEXT NOT NULL,
|
|
56
|
+
model TEXT NOT NULL,
|
|
57
|
+
embedding BLOB NOT NULL,
|
|
58
|
+
created_at TEXT NOT NULL,
|
|
59
|
+
PRIMARY KEY (content_hash, model)
|
|
60
|
+
);
|
|
47
61
|
CREATE TABLE IF NOT EXISTS meta (
|
|
48
62
|
key TEXT PRIMARY KEY,
|
|
49
63
|
value TEXT NOT NULL
|
|
@@ -61,7 +75,13 @@ export function openIndexDb(vaultRoot) {
|
|
|
61
75
|
);`);
|
|
62
76
|
const stored = getMeta(db, "schema_version");
|
|
63
77
|
if (stored !== SCHEMA_VERSION) {
|
|
64
|
-
|
|
78
|
+
// Schema bump means a clean rebuild: every derived table is dropped and
|
|
79
|
+
// the freshness manifest is cleared so the next reindex repopulates
|
|
80
|
+
// everything. Trying to ALTER across this change would race the new
|
|
81
|
+
// composite-PK embeddings table; the markdown files are the source of
|
|
82
|
+
// truth and the index is cheap to regenerate.
|
|
83
|
+
db.exec("DROP TABLE IF EXISTS documents; DROP TABLE IF EXISTS chunks; DROP TABLE IF EXISTS embeddings;");
|
|
84
|
+
db.prepare("DELETE FROM meta WHERE key = ?").run("vault_manifest");
|
|
65
85
|
}
|
|
66
86
|
db.exec(SCHEMA);
|
|
67
87
|
setMeta(db, "schema_version", SCHEMA_VERSION);
|
|
@@ -73,7 +93,9 @@ export function openIndexDb(vaultRoot) {
|
|
|
73
93
|
}
|
|
74
94
|
}
|
|
75
95
|
// Drops every indexed row. Called at the start of a rebuild so a reindex never
|
|
76
|
-
// leaves rows for files that have since been deleted.
|
|
96
|
+
// leaves rows for files that have since been deleted. Embeddings are NOT
|
|
97
|
+
// cleared here — they are content-addressed and a subsequent gc pass deletes
|
|
98
|
+
// only the orphaned ones, preserving the cache across reindexes.
|
|
77
99
|
export function clearIndex(db) {
|
|
78
100
|
db.exec("DELETE FROM documents; DELETE FROM chunks;");
|
|
79
101
|
}
|
|
@@ -102,9 +124,44 @@ export function insertDocument(db, doc) {
|
|
|
102
124
|
ttl_days, created, superseded_by)
|
|
103
125
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(doc.path, doc.title, doc.collection, doc.domain, doc.status, doc.confidence, doc.updated, JSON.stringify(doc.tags), doc.content, JSON.stringify(doc.tokens), doc.ttlDays, doc.created, doc.supersededBy);
|
|
104
126
|
}
|
|
105
|
-
export function
|
|
106
|
-
db.prepare(`INSERT OR REPLACE INTO chunks (path, chunk_index, text,
|
|
107
|
-
VALUES (?, ?, ?, ?)`).run(chunk.path, chunk.chunkIndex, chunk.text, chunk.
|
|
127
|
+
export function insertChunkRow(db, chunk) {
|
|
128
|
+
db.prepare(`INSERT OR REPLACE INTO chunks (path, chunk_index, text, content_hash)
|
|
129
|
+
VALUES (?, ?, ?, ?)`).run(chunk.path, chunk.chunkIndex, chunk.text, chunk.contentHash);
|
|
130
|
+
}
|
|
131
|
+
// Returns the set of content_hash values that already have a row for `model`
|
|
132
|
+
// in the embeddings cache. Used by the reindex pass to skip re-embedding any
|
|
133
|
+
// chunk whose text hash is already known.
|
|
134
|
+
export function existingEmbeddingHashes(db, model, hashes) {
|
|
135
|
+
if (hashes.length === 0)
|
|
136
|
+
return new Set();
|
|
137
|
+
// SQLite has a finite SQL variable limit (default 999), so chunk the IN()
|
|
138
|
+
// list to stay well under it.
|
|
139
|
+
const found = new Set();
|
|
140
|
+
const BATCH = 500;
|
|
141
|
+
for (let start = 0; start < hashes.length; start += BATCH) {
|
|
142
|
+
const slice = hashes.slice(start, start + BATCH);
|
|
143
|
+
const placeholders = slice.map(() => "?").join(",");
|
|
144
|
+
const rows = db
|
|
145
|
+
.prepare(`SELECT content_hash FROM embeddings WHERE model = ? AND content_hash IN (${placeholders})`)
|
|
146
|
+
.all(model, ...slice);
|
|
147
|
+
for (const r of rows)
|
|
148
|
+
found.add(r.content_hash);
|
|
149
|
+
}
|
|
150
|
+
return found;
|
|
151
|
+
}
|
|
152
|
+
export function insertEmbedding(db, contentHash, model, embedding, createdAt) {
|
|
153
|
+
db.prepare(`INSERT OR REPLACE INTO embeddings (content_hash, model, embedding, created_at)
|
|
154
|
+
VALUES (?, ?, ?, ?)`).run(contentHash, model, embeddingToBlob(embedding), createdAt);
|
|
155
|
+
}
|
|
156
|
+
// Deletes every embeddings row whose content_hash is referenced by no chunks
|
|
157
|
+
// row. Called at the end of a reindex to reap entries for chunks that no
|
|
158
|
+
// longer exist anywhere in the vault. Returns the number of rows deleted.
|
|
159
|
+
export function gcOrphanedEmbeddings(db) {
|
|
160
|
+
const info = db
|
|
161
|
+
.prepare(`DELETE FROM embeddings
|
|
162
|
+
WHERE content_hash NOT IN (SELECT content_hash FROM chunks)`)
|
|
163
|
+
.run();
|
|
164
|
+
return info.changes;
|
|
108
165
|
}
|
|
109
166
|
export function setMeta(db, key, value) {
|
|
110
167
|
db.prepare("INSERT OR REPLACE INTO meta (key, value) VALUES (?, ?)").run(key, value);
|
|
@@ -139,17 +196,34 @@ function rowToChunk(row) {
|
|
|
139
196
|
path: row.path,
|
|
140
197
|
chunkIndex: row.chunk_index,
|
|
141
198
|
text: row.text,
|
|
199
|
+
contentHash: row.content_hash,
|
|
142
200
|
embedding: row.embedding ? blobToEmbedding(row.embedding) : null,
|
|
143
201
|
};
|
|
144
202
|
}
|
|
145
|
-
|
|
146
|
-
|
|
203
|
+
// Reads every chunk LEFT JOINed against the embeddings cache, filtered to
|
|
204
|
+
// `model`. A chunk whose content_hash has no embeddings row for this model
|
|
205
|
+
// (e.g. the model was unavailable during reindex) comes back with embedding =
|
|
206
|
+
// null and the vector ranker simply skips it, matching the old NULL-blob
|
|
207
|
+
// behaviour.
|
|
208
|
+
export function getAllChunks(db, model) {
|
|
209
|
+
const rows = db
|
|
210
|
+
.prepare(`SELECT c.path, c.chunk_index, c.text, c.content_hash, e.embedding
|
|
211
|
+
FROM chunks c
|
|
212
|
+
LEFT JOIN embeddings e
|
|
213
|
+
ON e.content_hash = c.content_hash AND e.model = ?
|
|
214
|
+
ORDER BY c.path, c.chunk_index`)
|
|
215
|
+
.all(model);
|
|
147
216
|
return rows.map(rowToChunk);
|
|
148
217
|
}
|
|
149
|
-
export function getChunksForPath(db, path) {
|
|
218
|
+
export function getChunksForPath(db, path, model) {
|
|
150
219
|
const rows = db
|
|
151
|
-
.prepare(
|
|
152
|
-
|
|
220
|
+
.prepare(`SELECT c.path, c.chunk_index, c.text, c.content_hash, e.embedding
|
|
221
|
+
FROM chunks c
|
|
222
|
+
LEFT JOIN embeddings e
|
|
223
|
+
ON e.content_hash = c.content_hash AND e.model = ?
|
|
224
|
+
WHERE c.path = ?
|
|
225
|
+
ORDER BY c.chunk_index`)
|
|
226
|
+
.all(model, path);
|
|
153
227
|
return rows.map(rowToChunk);
|
|
154
228
|
}
|
|
155
229
|
export function getMeta(db, key) {
|
|
@@ -160,4 +234,8 @@ export function documentCount(db) {
|
|
|
160
234
|
const row = db.prepare("SELECT COUNT(*) AS n FROM documents").get();
|
|
161
235
|
return row.n;
|
|
162
236
|
}
|
|
237
|
+
export function embeddingCount(db) {
|
|
238
|
+
const row = db.prepare("SELECT COUNT(*) AS n FROM embeddings").get();
|
|
239
|
+
return row.n;
|
|
240
|
+
}
|
|
163
241
|
//# sourceMappingURL=index-db.js.map
|