promptgraph-mcp 2.9.15 → 2.9.16
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/embedder.js +4 -1
- package/indexer.js +14 -17
- package/package.json +1 -1
package/embedder.js
CHANGED
|
@@ -32,15 +32,18 @@ export async function embed(text) {
|
|
|
32
32
|
return Array.from(results[0]);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export async function embedBatch(texts) {
|
|
35
|
+
export async function embedBatch(texts, onProgress) {
|
|
36
36
|
if (embedCallCount + texts.length > MAX_EMBEDDING_CALLS) {
|
|
37
37
|
throw new Error(`Embedding queue limit exceeded (max ${MAX_EMBEDDING_CALLS} chunks per session). Use --fast or reindex incrementally.`);
|
|
38
38
|
}
|
|
39
39
|
embedCallCount += texts.length;
|
|
40
40
|
const m = await getModel();
|
|
41
41
|
const all = [];
|
|
42
|
+
let done = 0;
|
|
42
43
|
for await (const batch of m.embed(texts)) {
|
|
43
44
|
all.push(...batch);
|
|
45
|
+
done += batch.length;
|
|
46
|
+
if (onProgress) onProgress(done, texts.length);
|
|
44
47
|
}
|
|
45
48
|
return all.map(v => Array.from(v));
|
|
46
49
|
}
|
package/indexer.js
CHANGED
|
@@ -66,25 +66,22 @@ export async function indexBatch(db, skills, { fast = false } = {}) {
|
|
|
66
66
|
}
|
|
67
67
|
})();
|
|
68
68
|
|
|
69
|
-
// pass 1b: embed in
|
|
69
|
+
// pass 1b: embed all chunks in one call (fastembed batches internally by 256), with progress
|
|
70
70
|
if (!fast && allChunks.length) {
|
|
71
|
-
const
|
|
72
|
-
const total =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
for (let j = 0; j < batch.length; j++) {
|
|
79
|
-
const { id, chunkIndex, text } = batch[j];
|
|
80
|
-
upsertChunk.run(id, chunkIndex, text, vecToBlob(vecs[j]));
|
|
81
|
-
}
|
|
82
|
-
})();
|
|
83
|
-
const done = Math.min(i + EMBED_BATCH, total);
|
|
84
|
-
const pct = Math.round(done / total * 100);
|
|
85
|
-
process.stdout.write(`\r Embedding chunks... ${done}/${total} (${pct}%) `);
|
|
86
|
-
}
|
|
71
|
+
const texts = allChunks.map(c => c.text);
|
|
72
|
+
const total = texts.length;
|
|
73
|
+
process.stdout.write(`\r Embedding chunks... 0/${total} (0%) `);
|
|
74
|
+
const embeddings = await embedBatch(texts, (done, tot) => {
|
|
75
|
+
const pct = Math.round(done / tot * 100);
|
|
76
|
+
process.stdout.write(`\r Embedding chunks... ${done}/${tot} (${pct}%) `);
|
|
77
|
+
});
|
|
87
78
|
process.stdout.write('\r' + ' '.repeat(50) + '\r');
|
|
79
|
+
db.transaction(() => {
|
|
80
|
+
for (let i = 0; i < allChunks.length; i++) {
|
|
81
|
+
const { id, chunkIndex, text } = allChunks[i];
|
|
82
|
+
upsertChunk.run(id, chunkIndex, text, vecToBlob(embeddings[i]));
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
88
85
|
}
|
|
89
86
|
|
|
90
87
|
// pass 2: resolve edges after all skills in batch are committed
|