@askdb/rag 0.2.0-beta.23 → 0.2.0-beta.25
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/README.md +14 -10
- package/bin/askdb-rag.js +8 -1
- package/dist/chunker/chunker.d.ts +5 -1
- package/dist/chunker/chunker.d.ts.map +1 -1
- package/dist/chunker/chunker.js +198 -130
- package/dist/chunker/chunker.js.map +1 -1
- package/dist/chunker/ids.d.ts +15 -0
- package/dist/chunker/ids.d.ts.map +1 -0
- package/dist/chunker/ids.js +22 -0
- package/dist/chunker/ids.js.map +1 -0
- package/dist/chunker/index.d.ts +1 -0
- package/dist/chunker/index.d.ts.map +1 -1
- package/dist/chunker/index.js +1 -0
- package/dist/chunker/index.js.map +1 -1
- package/dist/chunker/sources.d.ts.map +1 -1
- package/dist/chunker/sources.js +1 -0
- package/dist/chunker/sources.js.map +1 -1
- package/dist/embedders/ai-sdk.d.ts +15 -0
- package/dist/embedders/ai-sdk.d.ts.map +1 -1
- package/dist/embedders/ai-sdk.js +9 -0
- package/dist/embedders/ai-sdk.js.map +1 -1
- package/dist/embedders/dimensions.d.ts +9 -0
- package/dist/embedders/dimensions.d.ts.map +1 -0
- package/dist/embedders/dimensions.js +18 -0
- package/dist/embedders/dimensions.js.map +1 -0
- package/dist/embedders/openai.d.ts +1 -1
- package/dist/embedders/openai.js +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/indexer/hash.d.ts +7 -0
- package/dist/indexer/hash.d.ts.map +1 -1
- package/dist/indexer/hash.js +13 -0
- package/dist/indexer/hash.js.map +1 -1
- package/dist/indexer/index.d.ts +10 -4
- package/dist/indexer/index.d.ts.map +1 -1
- package/dist/indexer/index.js +167 -30
- package/dist/indexer/index.js.map +1 -1
- package/dist/indexer/lock-file.d.ts +85 -4
- package/dist/indexer/lock-file.d.ts.map +1 -1
- package/dist/indexer/lock-file.js +108 -9
- package/dist/indexer/lock-file.js.map +1 -1
- package/dist/log-events.d.ts +11 -0
- package/dist/log-events.d.ts.map +1 -1
- package/dist/log-events.js +11 -0
- package/dist/log-events.js.map +1 -1
- package/dist/stores/file.d.ts +7 -1
- package/dist/stores/file.d.ts.map +1 -1
- package/dist/stores/file.js +52 -10
- package/dist/stores/file.js.map +1 -1
- package/dist/stores/memory.d.ts.map +1 -1
- package/dist/stores/memory.js +31 -3
- package/dist/stores/memory.js.map +1 -1
- package/dist/stores/pgvector.d.ts +36 -3
- package/dist/stores/pgvector.d.ts.map +1 -1
- package/dist/stores/pgvector.js +125 -17
- package/dist/stores/pgvector.js.map +1 -1
- package/dist/types.d.ts +69 -9
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -12
- package/dist/bin.d.ts +0 -3
- package/dist/bin.d.ts.map +0 -1
- package/dist/bin.js +0 -7
- package/dist/bin.js.map +0 -1
- package/dist/cli.d.ts +0 -11
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -356
- package/dist/cli.js.map +0 -1
package/dist/indexer/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { chunkSchema } from "../chunker/index.js";
|
|
1
|
+
import { chunkIdPrefix, chunkSchema } from "../chunker/index.js";
|
|
2
2
|
import { AskDbRagLogEvent } from "../log-events.js";
|
|
3
|
-
import { chunkContentHash } from "./hash.js";
|
|
4
|
-
import {
|
|
3
|
+
import { chunkContentHash, storedVectorHash } from "./hash.js";
|
|
4
|
+
import { SCHEMA_LOCK_VERSION, inspectLockFile, sameEmbedderId, writeLockFile, } from "./lock-file.js";
|
|
5
5
|
const DEFAULT_BATCH_SIZE = 64;
|
|
6
6
|
export async function buildSchemaIndex(options) {
|
|
7
|
-
const { embedder, store, embedderId,
|
|
7
|
+
const { embedder, store, embedderId, chunkOptions, batchSize = DEFAULT_BATCH_SIZE, logger, correlationId, onProgress, } = options;
|
|
8
8
|
const sources = normalizeIndexSources(options);
|
|
9
9
|
const baseLogContext = correlationId
|
|
10
10
|
? { correlationId }
|
|
@@ -28,25 +28,66 @@ export async function buildSchemaIndex(options) {
|
|
|
28
28
|
count: chunkResult.stats.sensitiveIncluded,
|
|
29
29
|
}, "sensitive describable-layer chunks INCLUDED (opt-in)");
|
|
30
30
|
}
|
|
31
|
-
// 3. Decide which chunks need (re-)embedding
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
// 3. Decide which chunks need (re-)embedding.
|
|
32
|
+
//
|
|
33
|
+
// Stores that can report stored hashes are the source of truth: a chunk is
|
|
34
|
+
// skipped only when the store already holds, for its id, the hash of the
|
|
35
|
+
// same text embedded by the same embedder (`storedVectorHash`). Stores that
|
|
36
|
+
// cannot report hashes fall back to the lock's text hashes, guarded by the
|
|
37
|
+
// lock's embedder id, store identity, and dimensions.
|
|
38
|
+
const schemaId = sources.schema.schemaId;
|
|
39
|
+
const idPrefix = chunkIdPrefix(schemaId);
|
|
40
|
+
const descriptor = store.describe?.();
|
|
41
|
+
// An ephemeral store (memory) outlives no process, so the lock, which
|
|
42
|
+
// describes the persisted index, is neither read nor written for it.
|
|
43
|
+
const lockFilePath = descriptor?.ephemeral === true ? undefined : options.lockFilePath;
|
|
44
|
+
const lockState = lockFilePath
|
|
45
|
+
? inspectLockFile(lockFilePath)
|
|
46
|
+
: { status: "missing" };
|
|
47
|
+
if (lockState.status === "ok" && lockState.lock.schemaId !== schemaId) {
|
|
48
|
+
// Renamed, or a lock copied from another schema's directory: its ids may
|
|
49
|
+
// belong to a schema that still shares this store, so nothing is deleted
|
|
50
|
+
// on its word.
|
|
51
|
+
logger?.info({
|
|
52
|
+
...baseLogContext,
|
|
53
|
+
event: AskDbRagLogEvent.LockSchemaMismatch,
|
|
54
|
+
lockSchemaId: lockState.lock.schemaId,
|
|
55
|
+
schemaId,
|
|
56
|
+
}, "schema.lock.json was written for another schema id; reindexing without it and pruning none of its ids");
|
|
57
|
+
}
|
|
58
|
+
const previousLock = lockState.status === "ok" && lockState.lock.schemaId === schemaId
|
|
59
|
+
? lockState.lock
|
|
60
|
+
: undefined;
|
|
61
|
+
const storeHashes = store.hashesByPrefix
|
|
62
|
+
? await store.hashesByPrefix(idPrefix)
|
|
63
|
+
: undefined;
|
|
64
|
+
const fullReindexReason = decideFullReindex({
|
|
65
|
+
force: options.force === true,
|
|
66
|
+
lockFilePath,
|
|
67
|
+
lockState,
|
|
68
|
+
previousLock,
|
|
69
|
+
embedderId,
|
|
70
|
+
descriptor,
|
|
71
|
+
storeReportsHashes: storeHashes !== undefined,
|
|
72
|
+
});
|
|
73
|
+
// Whether or not it decided the full reindex (`force` or an outdated lock
|
|
74
|
+
// may come first): it also drops the previous lock's width below.
|
|
75
|
+
const embedderChanged = previousLock !== undefined && !sameEmbedderId(previousLock.embedderId, embedderId);
|
|
76
|
+
const previousHashes = storeHashes ?? previousLock?.hashes ?? {};
|
|
77
|
+
// `newHashes` (text only) go to the lock; `vectorHashes` (text + embedder
|
|
78
|
+
// id) go to the store with each vector.
|
|
39
79
|
const newHashes = {};
|
|
80
|
+
const vectorHashes = {};
|
|
40
81
|
const toEmbed = [];
|
|
41
82
|
let reused = 0;
|
|
42
83
|
for (const c of chunks) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
84
|
+
newHashes[c.id] = chunkContentHash(c.text);
|
|
85
|
+
vectorHashes[c.id] = storedVectorHash(c.text, embedderId);
|
|
86
|
+
const current = storeHashes !== undefined ? vectorHashes[c.id] : newHashes[c.id];
|
|
87
|
+
if (fullReindexReason === undefined && previousHashes[c.id] === current) {
|
|
88
|
+
// Same text, same embedder, and (for hash-reporting stores) verified
|
|
89
|
+
// present in the store — keep the stored vector.
|
|
46
90
|
reused++;
|
|
47
|
-
// Chunk text unchanged AND embedder unchanged — assume the store still
|
|
48
|
-
// holds the embedding from a prior run. The retriever uses store.query
|
|
49
|
-
// directly so we don't need to round-trip the vector.
|
|
50
91
|
continue;
|
|
51
92
|
}
|
|
52
93
|
toEmbed.push(c);
|
|
@@ -58,6 +99,7 @@ export async function buildSchemaIndex(options) {
|
|
|
58
99
|
toEmbed: toEmbed.length,
|
|
59
100
|
reused,
|
|
60
101
|
embedderChanged,
|
|
102
|
+
...(fullReindexReason ? { fullReindexReason } : {}),
|
|
61
103
|
}, "rag indexing started");
|
|
62
104
|
onProgress?.({
|
|
63
105
|
kind: "started",
|
|
@@ -70,20 +112,40 @@ export async function buildSchemaIndex(options) {
|
|
|
70
112
|
...baseLogContext,
|
|
71
113
|
event: AskDbRagLogEvent.ChunksReused,
|
|
72
114
|
count: reused,
|
|
73
|
-
}, "rag chunks reused
|
|
115
|
+
}, "rag chunks reused (unchanged and already stored)");
|
|
74
116
|
}
|
|
75
117
|
// 4. Embed in batches and upsert.
|
|
118
|
+
if (lockFilePath && previousLock && embedderChanged && toEmbed.length > 0) {
|
|
119
|
+
// Until this run finishes, the store holds two models' vectors: mark the
|
|
120
|
+
// lock so a query guard (checkIndexMatches) refuses it if the run fails.
|
|
121
|
+
writeLockFile(lockFilePath, { ...previousLock, incomplete: true, updatedAt: new Date().toISOString() });
|
|
122
|
+
}
|
|
76
123
|
let embeddedCount = 0;
|
|
124
|
+
let observedDimensions;
|
|
77
125
|
for (let i = 0; i < toEmbed.length; i += batchSize) {
|
|
78
126
|
const batch = toEmbed.slice(i, i + batchSize);
|
|
79
127
|
const vectors = await embedder(batch.map((c) => c.text));
|
|
80
128
|
if (vectors.length !== batch.length) {
|
|
81
129
|
throw new Error(`Embedder returned ${vectors.length} vectors for ${batch.length} inputs.`);
|
|
82
130
|
}
|
|
131
|
+
for (const v of vectors) {
|
|
132
|
+
observedDimensions ??= v.length;
|
|
133
|
+
if (v.length !== observedDimensions) {
|
|
134
|
+
throw new Error(`Embedder returned vectors of inconsistent dimensions (${observedDimensions} and ${v.length}).`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (descriptor?.dimensions !== undefined &&
|
|
138
|
+
observedDimensions !== undefined &&
|
|
139
|
+
observedDimensions !== descriptor.dimensions) {
|
|
140
|
+
throw new Error(`Embedder returned ${observedDimensions}-dimension vectors but the ${descriptor.kind} store ` +
|
|
141
|
+
`is set up for ${descriptor.dimensions}. Use a store set up for ${observedDimensions}, or an ` +
|
|
142
|
+
`embedder that produces ${descriptor.dimensions}-dimension vectors.` +
|
|
143
|
+
(descriptor.widthHint ? ` ${descriptor.widthHint}` : ""));
|
|
144
|
+
}
|
|
83
145
|
await store.upsert(batch.map((c, idx) => ({
|
|
84
146
|
id: c.id,
|
|
85
147
|
vector: vectors[idx],
|
|
86
|
-
hash:
|
|
148
|
+
hash: vectorHashes[c.id],
|
|
87
149
|
payload: {
|
|
88
150
|
id: c.id,
|
|
89
151
|
type: c.type,
|
|
@@ -108,23 +170,51 @@ export async function buildSchemaIndex(options) {
|
|
|
108
170
|
total: toEmbed.length,
|
|
109
171
|
});
|
|
110
172
|
}
|
|
111
|
-
// 5. Drop
|
|
112
|
-
|
|
173
|
+
// 5. Drop this schema's chunks that no longer exist (artifact pruning).
|
|
174
|
+
// Scoped to this schema: other schemas sharing the store are never touched.
|
|
113
175
|
const currentIds = new Set(chunks.map((c) => c.id));
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
176
|
+
const candidates = new Set();
|
|
177
|
+
if (store.idsBySchema) {
|
|
178
|
+
// Exact: matched on payload schemaId (also finds older-format ids).
|
|
179
|
+
for (const id of await store.idsBySchema(schemaId))
|
|
180
|
+
candidates.add(id);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
// Without `idsBySchema` only the ids this schema's own lock lists are
|
|
184
|
+
// pruned. The id prefix isn't safe here: it can match other schemas' ids
|
|
185
|
+
// in the older, unscoped format (`chunk:table:` is both the prefix of a
|
|
186
|
+
// schema named `table` and the start of every old table-chunk id).
|
|
187
|
+
logger?.info({
|
|
188
|
+
...baseLogContext,
|
|
189
|
+
event: AskDbRagLogEvent.OrphanCleanupLimited,
|
|
190
|
+
}, "store has no idsBySchema; only orphaned ids listed in the previous lock are pruned");
|
|
191
|
+
}
|
|
192
|
+
for (const id of Object.keys(previousLock?.hashes ?? {})) {
|
|
193
|
+
if (id.startsWith(idPrefix))
|
|
194
|
+
candidates.add(id);
|
|
195
|
+
}
|
|
196
|
+
if (lockState.status === "outdated" && lockState.schemaId === schemaId) {
|
|
197
|
+
// Older-format (unscoped) ids this schema wrote under the previous lock.
|
|
198
|
+
for (const id of Object.keys(lockState.hashes))
|
|
199
|
+
candidates.add(id);
|
|
118
200
|
}
|
|
201
|
+
const orphaned = [...candidates].filter((id) => !currentIds.has(id)).sort();
|
|
119
202
|
if (orphaned.length > 0) {
|
|
120
203
|
await store.delete(orphaned);
|
|
121
204
|
}
|
|
122
205
|
// 6. Persist lock file.
|
|
123
206
|
if (lockFilePath) {
|
|
207
|
+
// The width of the vectors in the store: what this run embedded, else (nothing was
|
|
208
|
+
// re-embedded with the same embedder) what the previous run recorded, else what the
|
|
209
|
+
// store reports.
|
|
210
|
+
const dimensions = observedDimensions ??
|
|
211
|
+
(embedderChanged ? undefined : (previousLock?.dimensions ?? descriptor?.dimensions));
|
|
124
212
|
const lock = {
|
|
125
|
-
version:
|
|
126
|
-
schemaId
|
|
127
|
-
embedderId,
|
|
213
|
+
version: SCHEMA_LOCK_VERSION,
|
|
214
|
+
schemaId,
|
|
215
|
+
...(embedderId !== undefined ? { embedderId } : {}),
|
|
216
|
+
...(dimensions !== undefined ? { dimensions } : {}),
|
|
217
|
+
...(descriptor ? { store: storeIdentity(descriptor) } : {}),
|
|
128
218
|
hashes: newHashes,
|
|
129
219
|
updatedAt: new Date().toISOString(),
|
|
130
220
|
};
|
|
@@ -163,6 +253,53 @@ export async function buildSchemaIndex(options) {
|
|
|
163
253
|
chunks,
|
|
164
254
|
};
|
|
165
255
|
}
|
|
256
|
+
function decideFullReindex(args) {
|
|
257
|
+
if (args.force)
|
|
258
|
+
return "force";
|
|
259
|
+
const lock = args.previousLock;
|
|
260
|
+
if (args.lockFilePath !== undefined) {
|
|
261
|
+
if (args.lockState.status === "outdated")
|
|
262
|
+
return "lock-outdated";
|
|
263
|
+
// No usable lock → the embedder that produced any stored vectors is
|
|
264
|
+
// unknown, so nothing can be trusted.
|
|
265
|
+
if (!lock)
|
|
266
|
+
return "lock-missing";
|
|
267
|
+
}
|
|
268
|
+
if (!lock)
|
|
269
|
+
return undefined;
|
|
270
|
+
// Undefined vs defined counts as a change: we can't prove it's the same model.
|
|
271
|
+
if (!sameEmbedderId(lock.embedderId, args.embedderId))
|
|
272
|
+
return "embedder-changed";
|
|
273
|
+
if (lock.dimensions !== undefined &&
|
|
274
|
+
args.descriptor?.dimensions !== undefined &&
|
|
275
|
+
lock.dimensions !== args.descriptor.dimensions) {
|
|
276
|
+
return "dimensions-changed";
|
|
277
|
+
}
|
|
278
|
+
// The lock's hashes only describe the store they were written to. Stores
|
|
279
|
+
// that report their own hashes don't depend on it.
|
|
280
|
+
if (!args.storeReportsHashes) {
|
|
281
|
+
// An interrupted embedder switch left vectors the lock's hashes don't
|
|
282
|
+
// describe; only a store that reports its own hashes can sort them out.
|
|
283
|
+
if (lock.incomplete)
|
|
284
|
+
return "lock-incomplete";
|
|
285
|
+
// Without `describe()` nothing shows this is the store the lock was
|
|
286
|
+
// written to (a fresh, empty instance looks the same), so trust nothing.
|
|
287
|
+
if (!args.descriptor)
|
|
288
|
+
return "store-unidentified";
|
|
289
|
+
const current = storeIdentity(args.descriptor);
|
|
290
|
+
const previous = lock.store;
|
|
291
|
+
if (current.kind !== previous?.kind ||
|
|
292
|
+
(current.location ?? null) !== (previous?.location ?? null)) {
|
|
293
|
+
return "store-changed";
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
function storeIdentity(descriptor) {
|
|
299
|
+
return descriptor.location !== undefined
|
|
300
|
+
? { kind: descriptor.kind, location: descriptor.location }
|
|
301
|
+
: { kind: descriptor.kind };
|
|
302
|
+
}
|
|
166
303
|
function normalizeIndexSources(options) {
|
|
167
304
|
const input = options.schema ?? options.sources;
|
|
168
305
|
if (!input) {
|
|
@@ -191,6 +328,6 @@ export function createRetriever(args) {
|
|
|
191
328
|
return results;
|
|
192
329
|
};
|
|
193
330
|
}
|
|
194
|
-
export { readLockFile, writeLockFile, } from "./lock-file.js";
|
|
331
|
+
export { checkIndexMatches, readLockFile, writeLockFile, SCHEMA_LOCK_VERSION, } from "./lock-file.js";
|
|
195
332
|
export { chunkContentHash } from "./hash.js";
|
|
196
333
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/indexer/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAoB,MAAM,qBAAqB,CAAC;AAGpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,aAAa,GAEd,MAAM,gBAAgB,CAAC;AAgDxB,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAgC;IAEhC,MAAM,EACJ,QAAQ,EACR,KAAK,EACL,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,SAAS,GAAG,kBAAkB,EAC9B,MAAM,EACN,aAAa,EACb,UAAU,GACX,GAAG,OAAO,CAAC;IACZ,MAAM,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAE/C,MAAM,cAAc,GAA4B,aAAa;QAC3D,CAAC,CAAC,EAAE,aAAa,EAAE;QACnB,CAAC,CAAC,EAAE,CAAC;IAEP,WAAW;IACX,MAAM,WAAW,GAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACpE,MAAM,MAAM,GAAG,WAAW,CAAC,MAA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yBAAyB,CAC1B,CAAC;QACF,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC;AAED,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,mBAAmB,GAGpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1,23 +1,104 @@
|
|
|
1
|
+
/** Current `schema.lock.json` format version. */
|
|
2
|
+
export declare const SCHEMA_LOCK_VERSION = 2;
|
|
1
3
|
/**
|
|
2
|
-
* `schema.lock.json` shape — machine-managed
|
|
3
|
-
* skip re-embedding chunks whose content hasn't changed.
|
|
4
|
+
* `schema.lock.json` shape — machine-managed bookkeeping used by the indexer
|
|
5
|
+
* to skip re-embedding chunks whose content hasn't changed.
|
|
4
6
|
*
|
|
5
7
|
* Lives next to the v2 artifact (`<schemaId>.schema/schema.lock.json`).
|
|
8
|
+
*
|
|
9
|
+
* The lock is advisory: stores that can report stored content hashes
|
|
10
|
+
* (`VectorStore.hashesByPrefix` — all built-in stores) are the source of truth
|
|
11
|
+
* for what is already embedded; the lock only guards embedder identity for
|
|
12
|
+
* them. Stores that cannot report hashes fall back to `hashes` here, guarded
|
|
13
|
+
* by `store`, `dimensions`, and `embedderId`.
|
|
14
|
+
*
|
|
15
|
+
* Version history:
|
|
16
|
+
* - `1` — unscoped chunk ids (`chunk:table:public.orders`), no store identity.
|
|
17
|
+
* - `2` — schema-scoped chunk ids (`chunk:<schemaId>:table:public.orders`),
|
|
18
|
+
* records `store` identity and `dimensions`. A v1 lock triggers a one-time
|
|
19
|
+
* full reindex.
|
|
6
20
|
*/
|
|
7
21
|
export type SchemaLockFile = {
|
|
8
22
|
/** File-format version. Bump on breaking shape changes. */
|
|
9
|
-
version:
|
|
23
|
+
version: typeof SCHEMA_LOCK_VERSION;
|
|
10
24
|
/** Schema id this lock is bound to. */
|
|
11
25
|
schemaId: string;
|
|
12
26
|
/** Embedder id the embeddings were produced with (e.g. `openai:text-embedding-3-small`). */
|
|
13
27
|
embedderId?: string;
|
|
14
|
-
/**
|
|
28
|
+
/** Width of the vectors in the store, learned from the embedder's output. */
|
|
15
29
|
dimensions?: number;
|
|
30
|
+
/** Identity of the store the embeddings were written to (from `VectorStore.describe()`). */
|
|
31
|
+
store?: {
|
|
32
|
+
kind: string;
|
|
33
|
+
location?: string;
|
|
34
|
+
};
|
|
16
35
|
/** chunkId → SHA-256 content hash of the chunk's text. */
|
|
17
36
|
hashes: Record<string, string>;
|
|
18
37
|
/** ISO 8601 timestamp of last successful index. */
|
|
19
38
|
updatedAt?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Set while a run that switches the embedder is writing vectors, and
|
|
41
|
+
* cleared when it finishes. A lock that still carries it after the run
|
|
42
|
+
* ended describes a store holding two models' vectors, so it never
|
|
43
|
+
* matches a query (see {@link checkIndexMatches}).
|
|
44
|
+
*/
|
|
45
|
+
incomplete?: true;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Whether two embedder ids name the same embedder. Unset matches only unset:
|
|
49
|
+
* the indexer and {@link checkIndexMatches} share this rule.
|
|
50
|
+
*/
|
|
51
|
+
export declare function sameEmbedderId(a: string | undefined, b: string | undefined): boolean;
|
|
52
|
+
/** Result of {@link inspectLockFile}. */
|
|
53
|
+
export type LockFileInspection = {
|
|
54
|
+
status: "missing";
|
|
55
|
+
} | {
|
|
56
|
+
status: "invalid";
|
|
57
|
+
}
|
|
58
|
+
/** Written by an older `@askdb/rag`. `hashes` keys are that version's chunk ids. */
|
|
59
|
+
| {
|
|
60
|
+
status: "outdated";
|
|
61
|
+
version: unknown;
|
|
62
|
+
schemaId?: string;
|
|
63
|
+
hashes: Record<string, string>;
|
|
64
|
+
} | {
|
|
65
|
+
status: "ok";
|
|
66
|
+
lock: SchemaLockFile;
|
|
20
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* Read a lock file of the **current** version. Returns `undefined` when the
|
|
70
|
+
* file is missing, unparseable, or written in an older format.
|
|
71
|
+
*/
|
|
21
72
|
export declare function readLockFile(path: string): SchemaLockFile | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Read a lock file and report why it is (un)usable. Used by the indexer to
|
|
75
|
+
* detect older-format locks so it can reindex and clean up old chunk ids.
|
|
76
|
+
*/
|
|
77
|
+
export declare function inspectLockFile(path: string): LockFileInspection;
|
|
22
78
|
export declare function writeLockFile(path: string, lock: SchemaLockFile): void;
|
|
79
|
+
/** Result of {@link checkIndexMatches}. */
|
|
80
|
+
export type IndexMatch = {
|
|
81
|
+
ok: true;
|
|
82
|
+
/** The lock compared against; `undefined` when there is none for this schema (nothing to check). */
|
|
83
|
+
lock: SchemaLockFile | undefined;
|
|
84
|
+
} | {
|
|
85
|
+
ok: false;
|
|
86
|
+
reason: "lock-outdated" | "index-incomplete" | "embedder-changed" | "dimensions-changed";
|
|
87
|
+
message: string;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Whether an index described by `schema.lock.json` can be queried with this
|
|
91
|
+
* embedder: the rule `askdb rag query` applies, for any host that queries a
|
|
92
|
+
* persisted index (e.g. through `createRetriever`). The embedder id must be
|
|
93
|
+
* the one the lock records (unset matches only unset, as in the indexer),
|
|
94
|
+
* and when both widths are known they must match. A lock left `incomplete`
|
|
95
|
+
* by an interrupted embedder switch never matches. A missing or unreadable
|
|
96
|
+
* lock, or one for another schema, has nothing to compare and passes.
|
|
97
|
+
*/
|
|
98
|
+
export declare function checkIndexMatches(args: {
|
|
99
|
+
lockFilePath: string;
|
|
100
|
+
schemaId: string;
|
|
101
|
+
embedderId: string | undefined;
|
|
102
|
+
dimensions?: number;
|
|
103
|
+
}): IndexMatch;
|
|
23
104
|
//# sourceMappingURL=lock-file.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lock-file.d.ts","sourceRoot":"","sources":["../../src/indexer/lock-file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lock-file.d.ts","sourceR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AI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAGrE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CA8BhE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAetE;AAOD,2CAA2C;AAC3C,MAAM,MAAM,UAAU,GAClB;IACE,EAAE,EAAE,IAAI,CAAC;IACT,oGAAoG;IACpG,IAAI,EAAE,cAAc,GAAG,SAAS,CAAC;CAClC,GACD;IACE,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EAAE,eAAe,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,oBAAoB,CAAC;IACzF,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEN;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,UAAU,CA0Cb"}
|
|
@@ -1,25 +1,61 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
/** Current `schema.lock.json` format version. */
|
|
4
|
+
export const SCHEMA_LOCK_VERSION = 2;
|
|
5
|
+
/**
|
|
6
|
+
* Whether two embedder ids name the same embedder. Unset matches only unset:
|
|
7
|
+
* the indexer and {@link checkIndexMatches} share this rule.
|
|
8
|
+
*/
|
|
9
|
+
export function sameEmbedderId(a, b) {
|
|
10
|
+
return (a ?? null) === (b ?? null);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Read a lock file of the **current** version. Returns `undefined` when the
|
|
14
|
+
* file is missing, unparseable, or written in an older format.
|
|
15
|
+
*/
|
|
2
16
|
export function readLockFile(path) {
|
|
17
|
+
const inspected = inspectLockFile(path);
|
|
18
|
+
return inspected.status === "ok" ? inspected.lock : undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Read a lock file and report why it is (un)usable. Used by the indexer to
|
|
22
|
+
* detect older-format locks so it can reindex and clean up old chunk ids.
|
|
23
|
+
*/
|
|
24
|
+
export function inspectLockFile(path) {
|
|
3
25
|
let raw;
|
|
4
26
|
try {
|
|
5
27
|
raw = readFileSync(path, "utf8");
|
|
6
28
|
}
|
|
7
29
|
catch {
|
|
8
|
-
return
|
|
30
|
+
return { status: "missing" };
|
|
9
31
|
}
|
|
10
32
|
let parsed;
|
|
11
33
|
try {
|
|
12
34
|
parsed = JSON.parse(raw);
|
|
13
35
|
}
|
|
14
36
|
catch {
|
|
15
|
-
return
|
|
37
|
+
return { status: "invalid" };
|
|
16
38
|
}
|
|
17
|
-
if (typeof parsed !== "object" ||
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
39
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
40
|
+
return { status: "invalid" };
|
|
41
|
+
const obj = parsed;
|
|
42
|
+
const hashes = isStringRecord(obj.hashes) ? obj.hashes : undefined;
|
|
43
|
+
if (obj.version !== SCHEMA_LOCK_VERSION) {
|
|
44
|
+
// Only an older lock is "outdated" (its ids get cleaned up). A newer one
|
|
45
|
+
// was written by a later @askdb/rag whose id format this one can't know.
|
|
46
|
+
const older = typeof obj.version === "number" && obj.version < SCHEMA_LOCK_VERSION;
|
|
47
|
+
if (!hashes || !older)
|
|
48
|
+
return { status: "invalid" };
|
|
49
|
+
return {
|
|
50
|
+
status: "outdated",
|
|
51
|
+
version: obj.version,
|
|
52
|
+
schemaId: typeof obj.schemaId === "string" ? obj.schemaId : undefined,
|
|
53
|
+
hashes,
|
|
54
|
+
};
|
|
21
55
|
}
|
|
22
|
-
|
|
56
|
+
if (!hashes || typeof obj.schemaId !== "string")
|
|
57
|
+
return { status: "invalid" };
|
|
58
|
+
return { status: "ok", lock: parsed };
|
|
23
59
|
}
|
|
24
60
|
export function writeLockFile(path, lock) {
|
|
25
61
|
// Sort keys for deterministic on-disk output.
|
|
@@ -28,6 +64,69 @@ export function writeLockFile(path, lock) {
|
|
|
28
64
|
sortedHashes[k] = lock.hashes[k];
|
|
29
65
|
}
|
|
30
66
|
const out = { ...lock, hashes: sortedHashes };
|
|
31
|
-
|
|
67
|
+
// Temp file + rename, so a crash never leaves a half-written lock.
|
|
68
|
+
const tmp = `${path}.tmp-${process.pid}-${randomBytes(4).toString("hex")}`;
|
|
69
|
+
try {
|
|
70
|
+
writeFileSync(tmp, JSON.stringify(out, null, 2) + "\n", "utf8");
|
|
71
|
+
renameSync(tmp, path);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
rmSync(tmp, { force: true });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function isStringRecord(value) {
|
|
78
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
79
|
+
return false;
|
|
80
|
+
return Object.values(value).every((v) => typeof v === "string");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Whether an index described by `schema.lock.json` can be queried with this
|
|
84
|
+
* embedder: the rule `askdb rag query` applies, for any host that queries a
|
|
85
|
+
* persisted index (e.g. through `createRetriever`). The embedder id must be
|
|
86
|
+
* the one the lock records (unset matches only unset, as in the indexer),
|
|
87
|
+
* and when both widths are known they must match. A lock left `incomplete`
|
|
88
|
+
* by an interrupted embedder switch never matches. A missing or unreadable
|
|
89
|
+
* lock, or one for another schema, has nothing to compare and passes.
|
|
90
|
+
*/
|
|
91
|
+
export function checkIndexMatches(args) {
|
|
92
|
+
const inspected = inspectLockFile(args.lockFilePath);
|
|
93
|
+
if (inspected.status === "outdated" && (inspected.schemaId ?? args.schemaId) === args.schemaId) {
|
|
94
|
+
return {
|
|
95
|
+
ok: false,
|
|
96
|
+
reason: "lock-outdated",
|
|
97
|
+
message: "schema.lock.json was written by an older @askdb/rag (unscoped chunk ids); rebuild the index.",
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if (inspected.status !== "ok" || inspected.lock.schemaId !== args.schemaId) {
|
|
101
|
+
return { ok: true, lock: undefined };
|
|
102
|
+
}
|
|
103
|
+
const lock = inspected.lock;
|
|
104
|
+
if (lock.incomplete) {
|
|
105
|
+
return {
|
|
106
|
+
ok: false,
|
|
107
|
+
reason: "index-incomplete",
|
|
108
|
+
message: "The last index build switched embedders and didn't finish, so the store holds two models' vectors; rebuild the index.",
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// Equal widths don't make two models' vectors comparable.
|
|
112
|
+
if (!sameEmbedderId(lock.embedderId, args.embedderId)) {
|
|
113
|
+
const built = lock.embedderId === undefined
|
|
114
|
+
? "without an embedder id, so its embedder is unknown,"
|
|
115
|
+
: `with embedder "${lock.embedderId}"`;
|
|
116
|
+
const using = args.embedderId === undefined ? "no embedder id" : `"${args.embedderId}"`;
|
|
117
|
+
return {
|
|
118
|
+
ok: false,
|
|
119
|
+
reason: "embedder-changed",
|
|
120
|
+
message: `The index was built ${built} but this query uses ${using}.`,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (lock.dimensions !== undefined && args.dimensions !== undefined && lock.dimensions !== args.dimensions) {
|
|
124
|
+
return {
|
|
125
|
+
ok: false,
|
|
126
|
+
reason: "dimensions-changed",
|
|
127
|
+
message: `The index holds ${lock.dimensions}-dimension embeddings but this query uses ${args.dimensions}.`,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return { ok: true, lock };
|
|
32
131
|
}
|
|
33
132
|
//# sourceMappingURL=lock-file.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lock-file.js","sourceRoot":"","sources":["../../src/indexer/lock-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":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export declare const AskDbRagLogEvent: {
|
|
|
16
16
|
readonly SensitiveChunksExcluded: "askdb.rag.sensitive_chunks_excluded";
|
|
17
17
|
/** Counts only — opt-in `includeSensitiveDescribable: true` is in effect. */
|
|
18
18
|
readonly SensitiveChunksIncluded: "askdb.rag.sensitive_chunks_included";
|
|
19
|
+
/**
|
|
20
|
+
* The store has no `idsBySchema`, so orphan cleanup only prunes ids listed
|
|
21
|
+
* in the previous `schema.lock.json` (never other schemas' chunks).
|
|
22
|
+
*/
|
|
23
|
+
readonly OrphanCleanupLimited: "askdb.rag.orphan_cleanup_limited";
|
|
24
|
+
/**
|
|
25
|
+
* `schema.lock.json` names another schema id (a renamed schema, or a lock
|
|
26
|
+
* copied from another schema's directory). The run reindexes without it
|
|
27
|
+
* and deletes none of the ids it lists.
|
|
28
|
+
*/
|
|
29
|
+
readonly LockSchemaMismatch: "askdb.rag.lock_schema_mismatch";
|
|
19
30
|
/** Retrieval ran for a question; counts only. */
|
|
20
31
|
readonly RetrievalCompleted: "askdb.rag.retrieval_completed";
|
|
21
32
|
};
|
package/dist/log-events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-events.d.ts","sourceRoot":"","sources":["../src/log-events.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB;IAC3B,qDAAqD;;IAErD,gDAAgD;;IAEhD,sEAAsE;;IAEtE,kCAAkC;;IAElC,+GAA+G;;IAE/G,6EAA6E;;IAE7E,iDAAiD;;CAEzC,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAC9B,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"log-events.d.ts","sourceRoot":"","sources":["../src/log-events.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB;IAC3B,qDAAqD;;IAErD,gDAAgD;;IAEhD,sEAAsE;;IAEtE,kCAAkC;;IAElC,+GAA+G;;IAE/G,6EAA6E;;IAE7E;;;OAGG;;IAEH;;;;OAIG;;IAEH,iDAAiD;;CAEzC,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAC9B,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC"}
|
package/dist/log-events.js
CHANGED
|
@@ -16,6 +16,17 @@ export const AskDbRagLogEvent = {
|
|
|
16
16
|
SensitiveChunksExcluded: "askdb.rag.sensitive_chunks_excluded",
|
|
17
17
|
/** Counts only — opt-in `includeSensitiveDescribable: true` is in effect. */
|
|
18
18
|
SensitiveChunksIncluded: "askdb.rag.sensitive_chunks_included",
|
|
19
|
+
/**
|
|
20
|
+
* The store has no `idsBySchema`, so orphan cleanup only prunes ids listed
|
|
21
|
+
* in the previous `schema.lock.json` (never other schemas' chunks).
|
|
22
|
+
*/
|
|
23
|
+
OrphanCleanupLimited: "askdb.rag.orphan_cleanup_limited",
|
|
24
|
+
/**
|
|
25
|
+
* `schema.lock.json` names another schema id (a renamed schema, or a lock
|
|
26
|
+
* copied from another schema's directory). The run reindexes without it
|
|
27
|
+
* and deletes none of the ids it lists.
|
|
28
|
+
*/
|
|
29
|
+
LockSchemaMismatch: "askdb.rag.lock_schema_mismatch",
|
|
19
30
|
/** Retrieval ran for a question; counts only. */
|
|
20
31
|
RetrievalCompleted: "askdb.rag.retrieval_completed",
|
|
21
32
|
};
|
package/dist/log-events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-events.js","sourceRoot":"","sources":["../src/log-events.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,qDAAqD;IACrD,eAAe,EAAE,4BAA4B;IAC7C,gDAAgD;IAChD,YAAY,EAAE,yBAAyB;IACvC,sEAAsE;IACtE,YAAY,EAAE,yBAAyB;IACvC,kCAAkC;IAClC,iBAAiB,EAAE,8BAA8B;IACjD,+GAA+G;IAC/G,uBAAuB,EAAE,qCAAqC;IAC9D,6EAA6E;IAC7E,uBAAuB,EAAE,qCAAqC;IAC9D,iDAAiD;IACjD,kBAAkB,EAAE,+BAA+B;CAC3C,CAAC"}
|
|
1
|
+
{"version":3,"file":"log-events.js","sourceRoot":"","sources":["../src/log-events.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,qDAAqD;IACrD,eAAe,EAAE,4BAA4B;IAC7C,gDAAgD;IAChD,YAAY,EAAE,yBAAyB;IACvC,sEAAsE;IACtE,YAAY,EAAE,yBAAyB;IACvC,kCAAkC;IAClC,iBAAiB,EAAE,8BAA8B;IACjD,+GAA+G;IAC/G,uBAAuB,EAAE,qCAAqC;IAC9D,6EAA6E;IAC7E,uBAAuB,EAAE,qCAAqC;IAC9D;;;OAGG;IACH,oBAAoB,EAAE,kCAAkC;IACxD;;;;OAIG;IACH,kBAAkB,EAAE,gCAAgC;IACpD,iDAAiD;IACjD,kBAAkB,EAAE,+BAA+B;CAC3C,CAAC"}
|