mcp-rag-memory 2.4.1 → 2.7.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/.env.example +3 -1
- package/LICENSE +21 -0
- package/README.md +151 -16
- package/dist/cli.js +102 -34
- package/dist/db/database.d.ts +10 -2
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/database.js +119 -18
- package/dist/db/database.js.map +1 -1
- package/dist/env.js +32 -12
- package/dist/mcp/rag-server.js +140 -39
- package/dist/mcp/rag-server.js.map +1 -1
- package/dist/memory/memory.d.ts +5 -1
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/memory/memory.js +245 -101
- package/dist/memory/memory.js.map +1 -1
- package/dist/rag/chunker.d.ts +7 -0
- package/dist/rag/chunker.d.ts.map +1 -1
- package/dist/rag/chunker.js +119 -11
- package/dist/rag/chunker.js.map +1 -1
- package/dist/rag/embeddings.d.ts +25 -0
- package/dist/rag/embeddings.d.ts.map +1 -1
- package/dist/rag/embeddings.js +56 -4
- package/dist/rag/embeddings.js.map +1 -1
- package/dist/rag/pipeline.d.ts +19 -2
- package/dist/rag/pipeline.d.ts.map +1 -1
- package/dist/rag/pipeline.js +212 -39
- package/dist/rag/pipeline.js.map +1 -1
- package/dist/rag/reindex.d.ts +27 -0
- package/dist/rag/reindex.d.ts.map +1 -0
- package/dist/rag/reindex.js +138 -0
- package/dist/rag/reindex.js.map +1 -0
- package/dist/rag/vector-search.d.ts +26 -1
- package/dist/rag/vector-search.d.ts.map +1 -1
- package/dist/rag/vector-search.js +207 -65
- package/dist/rag/vector-search.js.map +1 -1
- package/dist/session/transcript.d.ts +15 -5
- package/dist/session/transcript.d.ts.map +1 -1
- package/dist/session/transcript.js +152 -25
- package/dist/session/transcript.js.map +1 -1
- package/package.json +6 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunker.d.ts","sourceRoot":"","sources":["../../src/rag/chunker.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;
|
|
1
|
+
{"version":3,"file":"chunker.d.ts","sourceRoot":"","sources":["../../src/rag/chunker.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAwHD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,KAAK,EAAE,CAiF3E;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAInD;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAG7D"}
|
package/dist/rag/chunker.js
CHANGED
|
@@ -18,7 +18,9 @@ function splitIntoParagraphs(text) {
|
|
|
18
18
|
let current = "";
|
|
19
19
|
let inCode = false;
|
|
20
20
|
for (const line of text.split(/\r?\n/)) {
|
|
21
|
-
|
|
21
|
+
// Only real fences toggle code mode — `---` is a thematic break / front
|
|
22
|
+
// matter delimiter, and one stray `---` used to swallow the whole document.
|
|
23
|
+
const codeBoundary = /^\s*(```|~~~)/.test(line.trim());
|
|
22
24
|
if (codeBoundary)
|
|
23
25
|
inCode = !inCode;
|
|
24
26
|
if (inCode || isCodeLine(line)) {
|
|
@@ -38,9 +40,59 @@ function splitIntoParagraphs(text) {
|
|
|
38
40
|
blocks.push(current.trimEnd());
|
|
39
41
|
return blocks.filter((b) => b.trim().length > 0);
|
|
40
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Sentence split that keeps decimals and version numbers intact
|
|
45
|
+
* ("pip 24.0.1" stays one sentence) and keeps fenced code blocks whole,
|
|
46
|
+
* because newlines are never treated as terminators.
|
|
47
|
+
*/
|
|
41
48
|
function splitIntoSentences(block) {
|
|
42
|
-
const
|
|
43
|
-
|
|
49
|
+
const out = [];
|
|
50
|
+
const TERMINATORS = ".!?。!?";
|
|
51
|
+
let start = 0;
|
|
52
|
+
for (let i = 0; i < block.length; i++) {
|
|
53
|
+
const ch = block[i];
|
|
54
|
+
if (!TERMINATORS.includes(ch))
|
|
55
|
+
continue;
|
|
56
|
+
// A period between two digits is a decimal point, not a sentence end.
|
|
57
|
+
if (ch === "." && /\d/.test(block[i - 1] ?? "") && /\d/.test(block[i + 1] ?? ""))
|
|
58
|
+
continue;
|
|
59
|
+
let end = i + 1;
|
|
60
|
+
while (end < block.length && /["')\]}»”]/.test(block[end]))
|
|
61
|
+
end++;
|
|
62
|
+
const piece = block.slice(start, end).trim();
|
|
63
|
+
if (piece)
|
|
64
|
+
out.push(piece);
|
|
65
|
+
start = end;
|
|
66
|
+
i = end - 1;
|
|
67
|
+
}
|
|
68
|
+
const tail = block.slice(start).trim();
|
|
69
|
+
if (tail)
|
|
70
|
+
out.push(tail);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Trim an overlap tail so a chunk never starts with a partial word: when the cut
|
|
75
|
+
* landed inside a word (last char before the cut and first char of the tail are
|
|
76
|
+
* both word characters), the leading fragment is dropped.
|
|
77
|
+
*/
|
|
78
|
+
function snapToWordStart(tail, charBeforeCut) {
|
|
79
|
+
const at = tail.search(/\S/);
|
|
80
|
+
const body = at <= 0 ? tail : tail.slice(at);
|
|
81
|
+
if (!body)
|
|
82
|
+
return body;
|
|
83
|
+
const startsMidWord = /[\p{L}\p{N}_]/u.test(charBeforeCut) && /[\p{L}\p{N}_]/u.test(body[0]);
|
|
84
|
+
if (!startsMidWord)
|
|
85
|
+
return body;
|
|
86
|
+
const space = body.search(/\s/);
|
|
87
|
+
return space === -1 ? body : body.slice(space).trimStart();
|
|
88
|
+
}
|
|
89
|
+
/** Last whitespace break inside the budget, so a hard cut avoids mid-word cuts. */
|
|
90
|
+
function lastBreak(candidate, max) {
|
|
91
|
+
for (let i = Math.min(candidate.length, max) - 1; i > Math.floor(max * 0.6); i--) {
|
|
92
|
+
if (/\s/.test(candidate[i]))
|
|
93
|
+
return i + 1;
|
|
94
|
+
}
|
|
95
|
+
return max;
|
|
44
96
|
}
|
|
45
97
|
function splitLongText(text, max) {
|
|
46
98
|
const parts = [];
|
|
@@ -48,7 +100,7 @@ function splitLongText(text, max) {
|
|
|
48
100
|
while (rest.length > max) {
|
|
49
101
|
const candidate = rest.slice(0, max);
|
|
50
102
|
const cut = Math.max(candidate.lastIndexOf(". "), candidate.lastIndexOf(".\n"), candidate.lastIndexOf("。"), candidate.lastIndexOf("\n"), candidate.lastIndexOf(", "));
|
|
51
|
-
const pos = cut > Math.floor(max * 0.6) ? cut + 1 : max;
|
|
103
|
+
const pos = cut > Math.floor(max * 0.6) ? cut + 1 : lastBreak(candidate, max);
|
|
52
104
|
parts.push(rest.slice(0, pos).trim());
|
|
53
105
|
rest = rest.slice(pos);
|
|
54
106
|
}
|
|
@@ -56,15 +108,40 @@ function splitLongText(text, max) {
|
|
|
56
108
|
parts.push(rest.trim());
|
|
57
109
|
return parts;
|
|
58
110
|
}
|
|
111
|
+
/** Separator that never mangles code: newline if either side has one. */
|
|
112
|
+
function joiner(left, right) {
|
|
113
|
+
if (!left)
|
|
114
|
+
return "";
|
|
115
|
+
if (left.endsWith("\n") || right.startsWith("\n"))
|
|
116
|
+
return "";
|
|
117
|
+
return left.includes("\n") || right.includes("\n") ? "\n" : " ";
|
|
118
|
+
}
|
|
59
119
|
export function chunkText(text, options = {}) {
|
|
60
120
|
const maxChars = options.maxChars ?? DEFAULT_MAX;
|
|
61
121
|
const overlapChars = options.overlapChars ?? DEFAULT_OVERLAP;
|
|
122
|
+
if (!Number.isFinite(maxChars) || maxChars < 1)
|
|
123
|
+
throw new RangeError("chunkText: maxChars must be >= 1");
|
|
124
|
+
if (!Number.isFinite(overlapChars) || overlapChars < 0)
|
|
125
|
+
throw new RangeError("chunkText: overlapChars must be >= 0");
|
|
62
126
|
const chunks = [];
|
|
63
127
|
let cursor = 0;
|
|
64
128
|
const emit = (content) => {
|
|
65
129
|
const trimmed = content.trim();
|
|
66
130
|
if (!trimmed)
|
|
67
131
|
return;
|
|
132
|
+
// Backstop for maxChars. The window is normally kept under budget, but
|
|
133
|
+
// carry() (up to maxChars/2) plus a full-size piece could still land at
|
|
134
|
+
// ~1.5x, and an over-budget chunk blows the embedder's context for no
|
|
135
|
+
// benefit. Split rather than silently shipping an oversized chunk.
|
|
136
|
+
if (trimmed.length > maxChars) {
|
|
137
|
+
for (const part of splitLongText(trimmed, maxChars)) {
|
|
138
|
+
const t = part.trim();
|
|
139
|
+
if (!t)
|
|
140
|
+
continue;
|
|
141
|
+
chunks.push({ text: t, index: cursor++, tokenCount: estimateTokens(t) });
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
68
145
|
chunks.push({
|
|
69
146
|
text: trimmed,
|
|
70
147
|
index: cursor++,
|
|
@@ -72,9 +149,12 @@ export function chunkText(text, options = {}) {
|
|
|
72
149
|
});
|
|
73
150
|
};
|
|
74
151
|
const paragraphs = splitIntoParagraphs(text);
|
|
152
|
+
const overlap = Math.min(overlapChars, Math.floor(maxChars / 2));
|
|
153
|
+
/** The tail carried into the next chunk; "" when overlapChars is 0. */
|
|
154
|
+
const carry = (emitted) => overlap > 0 ? snapToWordStart(emitted.slice(-overlap), emitted.slice(-overlap - 1, -overlap)) : "";
|
|
75
155
|
let window = "";
|
|
76
156
|
for (const para of paragraphs) {
|
|
77
|
-
let pieces
|
|
157
|
+
let pieces;
|
|
78
158
|
if (para.length > maxChars) {
|
|
79
159
|
pieces = splitLongText(para, maxChars);
|
|
80
160
|
}
|
|
@@ -84,16 +164,33 @@ export function chunkText(text, options = {}) {
|
|
|
84
164
|
}
|
|
85
165
|
for (const piece of pieces) {
|
|
86
166
|
if (piece.length > maxChars) {
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
167
|
+
// A single sentence longer than maxChars: hard-split it. The pending
|
|
168
|
+
// window must be flushed first, otherwise the text collected so far is
|
|
169
|
+
// emitted twice (once here, once with the next piece appended).
|
|
170
|
+
const hards = splitLongText(piece, maxChars);
|
|
171
|
+
if (window) {
|
|
172
|
+
emit(window);
|
|
173
|
+
window = carry(window);
|
|
174
|
+
}
|
|
175
|
+
for (const hard of hards) {
|
|
176
|
+
const projectedHard = window.length + joiner(window, hard).length + hard.length;
|
|
177
|
+
if (window && projectedHard > maxChars) {
|
|
178
|
+
emit(window);
|
|
179
|
+
window = carry(window);
|
|
180
|
+
}
|
|
181
|
+
window += joiner(window, hard) + hard;
|
|
182
|
+
}
|
|
90
183
|
continue;
|
|
91
184
|
}
|
|
92
|
-
|
|
185
|
+
const projected = window.length + joiner(window, piece).length + piece.length;
|
|
186
|
+
if (window && projected > maxChars) {
|
|
93
187
|
emit(window);
|
|
94
|
-
|
|
188
|
+
// Overlap carries the tail of the previous chunk. overlap === 0 must
|
|
189
|
+
// reset the window: slice(-0) returns the whole string, which used to
|
|
190
|
+
// duplicate the previous chunk and grow it without bound.
|
|
191
|
+
window = carry(window);
|
|
95
192
|
}
|
|
96
|
-
window += (window
|
|
193
|
+
window += joiner(window, piece) + piece;
|
|
97
194
|
}
|
|
98
195
|
}
|
|
99
196
|
if (window.trim())
|
|
@@ -106,4 +203,15 @@ export function estimateTokens(text) {
|
|
|
106
203
|
const rest = text.length - cjk;
|
|
107
204
|
return Math.ceil(cjk * 1.5) + Math.ceil(rest / 4);
|
|
108
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Same estimate for an already-known character count. Lets a caller total
|
|
208
|
+
* LENGTH() across many rows in SQL instead of materialising each content
|
|
209
|
+
* blob just to re-count its characters. Assumes no CJK in the total, which
|
|
210
|
+
* under-counts CJK-heavy stores — the same tradeoff the SQL path already made.
|
|
211
|
+
*/
|
|
212
|
+
export function estimateTokensFromChars(chars) {
|
|
213
|
+
if (!Number.isFinite(chars) || chars <= 0)
|
|
214
|
+
return 0;
|
|
215
|
+
return Math.ceil(chars / 4);
|
|
216
|
+
}
|
|
109
217
|
//# sourceMappingURL=chunker.js.map
|
package/dist/rag/chunker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunker.js","sourceRoot":"","sources":["../../src/rag/chunker.ts"],"names":[],"mappings":"AAAA;;GAEG;AAaH,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IACtB,IAAI,6DAA6D,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACvF,IAAI,wCAAwC,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAClE,IAAI,+FAA+F,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACzH,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAY;IACvC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,MAAM,YAAY,GAAG,
|
|
1
|
+
{"version":3,"file":"chunker.js","sourceRoot":"","sources":["../../src/rag/chunker.ts"],"names":[],"mappings":"AAAA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AC,CAAC;IAEhC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,4CAA4C,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IACpF,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;IAC/B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;AACpD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAa;IACnD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IACpD,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;AAC9B,CAAC"}
|
package/dist/rag/embeddings.d.ts
CHANGED
|
@@ -4,11 +4,36 @@ export declare const EMBEDDING_PROVIDER: EmbeddingProvider;
|
|
|
4
4
|
export declare const EMBEDDING_MODEL: string;
|
|
5
5
|
export declare function expectedDim(): number;
|
|
6
6
|
export declare function modelName(): string;
|
|
7
|
+
/**
|
|
8
|
+
* What the vector leg actually measures, reported honestly.
|
|
9
|
+
*
|
|
10
|
+
* `local` is a hashing embedder over character n-grams: it scores lexical and
|
|
11
|
+
* sub-word overlap, not meaning. A query and a document that use entirely
|
|
12
|
+
* different words for the same idea score near zero, no matter how well written
|
|
13
|
+
* either is. `transformers` produces true semantic vectors.
|
|
14
|
+
*
|
|
15
|
+
* Callers should not describe the `local` vector leg as "semantic"; the hybrid
|
|
16
|
+
* score is dominated by the FTS leg in that configuration, and an agent that
|
|
17
|
+
* believes otherwise will trust synonym-blind recall that is not there.
|
|
18
|
+
*/
|
|
19
|
+
export declare function vectorLegKind(): "lexical" | "semantic";
|
|
20
|
+
export declare function vectorLegNote(): string;
|
|
7
21
|
export declare function embeddingInfo(): {
|
|
8
22
|
provider: EmbeddingProvider;
|
|
9
23
|
dim: number;
|
|
10
24
|
model: string;
|
|
25
|
+
vectorLeg: "lexical" | "semantic";
|
|
26
|
+
note: string;
|
|
11
27
|
};
|
|
12
28
|
/** Embed text into a normalized Float64Array. Async for provider parity. */
|
|
13
29
|
export declare function embedText(text: string): Promise<Float64Array>;
|
|
30
|
+
/**
|
|
31
|
+
* Embed without the store-dimension guard.
|
|
32
|
+
*
|
|
33
|
+
* `reindex` is the one operation whose entire purpose is to *replace* the stored
|
|
34
|
+
* vector space, so requiring the new vectors to already match the old ones would
|
|
35
|
+
* make the migration impossible to express. Every other caller must use
|
|
36
|
+
* `embedText`, which enforces the guard.
|
|
37
|
+
*/
|
|
38
|
+
export declare function embedTextUnguarded(text: string): Promise<Float64Array>;
|
|
14
39
|
//# sourceMappingURL=embeddings.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embeddings.d.ts","sourceRoot":"","sources":["../../src/rag/embeddings.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,cAAc,CAAC;AAEzD,eAAO,MAAM,kBAAkB,EAAE,iBAC6C,CAAC;AAE/E,eAAO,MAAM,eAAe,QAA2D,CAAC;AAYxF,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED,wBAAgB,aAAa,IAAI;
|
|
1
|
+
{"version":3,"file":"embeddings.d.ts","sourceRoot":"","sources":["../../src/rag/embeddings.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,cAAc,CAAC;AAEzD,eAAO,MAAM,kBAAkB,EAAE,iBAC6C,CAAC;AAE/E,eAAO,MAAM,eAAe,QAA2D,CAAC;AAYxF,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,IAAI,SAAS,GAAG,UAAU,CAEtD;AAED,wBAAgB,aAAa,IAAI,MAAM,CAMtC;AAED,wBAAgB,aAAa,IAAI;IAC/B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,SAAS,GAAG,UAAU,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;CACd,CAQA;AAyBD,4EAA4E;AAC5E,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAInE;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAE5E"}
|
package/dist/rag/embeddings.js
CHANGED
|
@@ -28,17 +28,43 @@ export function expectedDim() {
|
|
|
28
28
|
export function modelName() {
|
|
29
29
|
return EMBEDDING_PROVIDER === "local" ? "local-hash-1024" : EMBEDDING_MODEL;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* What the vector leg actually measures, reported honestly.
|
|
33
|
+
*
|
|
34
|
+
* `local` is a hashing embedder over character n-grams: it scores lexical and
|
|
35
|
+
* sub-word overlap, not meaning. A query and a document that use entirely
|
|
36
|
+
* different words for the same idea score near zero, no matter how well written
|
|
37
|
+
* either is. `transformers` produces true semantic vectors.
|
|
38
|
+
*
|
|
39
|
+
* Callers should not describe the `local` vector leg as "semantic"; the hybrid
|
|
40
|
+
* score is dominated by the FTS leg in that configuration, and an agent that
|
|
41
|
+
* believes otherwise will trust synonym-blind recall that is not there.
|
|
42
|
+
*/
|
|
43
|
+
export function vectorLegKind() {
|
|
44
|
+
return EMBEDDING_PROVIDER === "local" ? "lexical" : "semantic";
|
|
45
|
+
}
|
|
46
|
+
export function vectorLegNote() {
|
|
47
|
+
return EMBEDDING_PROVIDER === "local"
|
|
48
|
+
? "Local hashing embedder: the vector leg scores lexical/sub-word overlap, not meaning. " +
|
|
49
|
+
"Synonym-only queries depend on the FTS5 trigram leg. Set EMBEDDING_PROVIDER=transformers " +
|
|
50
|
+
"(npm i @huggingface/transformers) then run 'rag_reindex' for true semantic recall."
|
|
51
|
+
: `Semantic embeddings from ${EMBEDDING_MODEL}; the vector leg captures meaning, not just overlap.`;
|
|
52
|
+
}
|
|
31
53
|
export function embeddingInfo() {
|
|
32
54
|
return {
|
|
33
55
|
provider: EMBEDDING_PROVIDER,
|
|
34
56
|
dim: getEmbedDim() || expectedDim() || EMBED_DIM_LOCAL,
|
|
35
57
|
model: modelName(),
|
|
58
|
+
vectorLeg: vectorLegKind(),
|
|
59
|
+
note: vectorLegNote(),
|
|
36
60
|
};
|
|
37
61
|
}
|
|
38
62
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
39
63
|
let extractorPromise = null;
|
|
40
64
|
async function getExtractor() {
|
|
41
65
|
if (!extractorPromise) {
|
|
66
|
+
// A failed model load must not be cached for the process lifetime: reset on
|
|
67
|
+
// rejection so a transient network/first-download error can be retried.
|
|
42
68
|
extractorPromise = (async () => {
|
|
43
69
|
// @ts-expect-error — @huggingface/transformers is an optional dependency
|
|
44
70
|
const mod = await import("@huggingface/transformers");
|
|
@@ -48,15 +74,33 @@ async function getExtractor() {
|
|
|
48
74
|
}
|
|
49
75
|
return pipeline("feature-extraction", EMBEDDING_MODEL, { quantized: true });
|
|
50
76
|
})();
|
|
77
|
+
extractorPromise.catch(() => {
|
|
78
|
+
extractorPromise = null;
|
|
79
|
+
});
|
|
51
80
|
}
|
|
52
81
|
return extractorPromise;
|
|
53
82
|
}
|
|
54
83
|
/** Embed text into a normalized Float64Array. Async for provider parity. */
|
|
55
84
|
export async function embedText(text) {
|
|
85
|
+
const vec = await embedRaw(text);
|
|
86
|
+
ensureDim(vec, modelName());
|
|
87
|
+
return vec;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Embed without the store-dimension guard.
|
|
91
|
+
*
|
|
92
|
+
* `reindex` is the one operation whose entire purpose is to *replace* the stored
|
|
93
|
+
* vector space, so requiring the new vectors to already match the old ones would
|
|
94
|
+
* make the migration impossible to express. Every other caller must use
|
|
95
|
+
* `embedText`, which enforces the guard.
|
|
96
|
+
*/
|
|
97
|
+
export async function embedTextUnguarded(text) {
|
|
98
|
+
return embedRaw(text);
|
|
99
|
+
}
|
|
100
|
+
/** Provider call plus the finite-value check, shared by both entry points. */
|
|
101
|
+
async function embedRaw(text) {
|
|
56
102
|
if (EMBEDDING_PROVIDER === "local") {
|
|
57
|
-
|
|
58
|
-
ensureDim(vec, modelName());
|
|
59
|
-
return vec;
|
|
103
|
+
return embed(text);
|
|
60
104
|
}
|
|
61
105
|
const extractor = await getExtractor();
|
|
62
106
|
const out = await extractor(text, { pooling: "mean", normalize: true });
|
|
@@ -65,7 +109,15 @@ export async function embedText(text) {
|
|
|
65
109
|
throw new Error("transformers embed returned an unexpected shape");
|
|
66
110
|
}
|
|
67
111
|
const vec = Float64Array.from(data);
|
|
68
|
-
|
|
112
|
+
// A NaN/Inf from the model poisons every score it touches: dot products become
|
|
113
|
+
// NaN, comparisons go false, and the row silently stops matching anything —
|
|
114
|
+
// an invisible, permanent retrieval hole. Reject it at the boundary instead.
|
|
115
|
+
for (let i = 0; i < vec.length; i++) {
|
|
116
|
+
if (!Number.isFinite(vec[i])) {
|
|
117
|
+
throw new Error(`Embedding for this input contains a non-finite value at index ${i}. ` +
|
|
118
|
+
`The input is likely empty or degenerate; retry with more text or set EMBEDDING_PROVIDER=local.`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
69
121
|
return vec;
|
|
70
122
|
}
|
|
71
123
|
//# sourceMappingURL=embeddings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embeddings.js","sourceRoot":"","sources":["../../src/rag/embeddings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE3D,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC;AAIpC,MAAM,CAAC,MAAM,kBAAkB,GAC7B,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC;AAE/E,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAC;AAExF,mFAAmF;AACnF,MAAM,UAAU,GAA2B;IACzC,yBAAyB,EAAE,GAAG;IAC9B,8CAA8C,EAAE,GAAG;IACnD,8BAA8B,EAAE,GAAG;IACnC,kBAAkB,EAAE,GAAG;IACvB,0BAA0B,EAAE,GAAG;IAC/B,6BAA6B,EAAE,GAAG;CACnC,CAAC;AAEF,MAAM,UAAU,WAAW;IACzB,OAAO,kBAAkB,KAAK,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;AAC7F,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,kBAAkB,KAAK,OAAO,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,eAAe,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO;QACL,QAAQ,EAAE,kBAAkB;QAC5B,GAAG,EAAE,WAAW,EAAE,IAAI,WAAW,EAAE,IAAI,eAAe;QACtD,KAAK,EAAE,SAAS,EAAE;
|
|
1
|
+
{"version":3,"file":"embeddings.js","sourceRoot":"","sources":["../../src/rag/embeddings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,K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AAED,8EAA8E;AAC9E,KAAK,UAAU,QAAQ,CAAC,IAAY;IAClC,IAAI,kBAAkB,KAAK,OAAO,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,YAAY,EAAE,CAAC;IACvC,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxE,MAAM,IAAI,GAAG,GAAG,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC1E,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,IAAyB,CAAC,CAAC;IACzD,+EAA+E;IAC/E,4EAA4E;IAC5E,6EAA6E;IAC7E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,iEAAiE,CAAC,IAAI;gBACpE,gGAAgG,CACnG,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/rag/pipeline.d.ts
CHANGED
|
@@ -26,21 +26,38 @@ export interface IngestFileOptions {
|
|
|
26
26
|
source?: string;
|
|
27
27
|
contentType?: string;
|
|
28
28
|
metadata?: Record<string, unknown>;
|
|
29
|
+
/** Namespace the dedup hash, so equal text from different scopes is kept apart. */
|
|
30
|
+
dedupScope?: string;
|
|
29
31
|
}
|
|
30
32
|
export interface IngestDirectoryOptions {
|
|
31
33
|
extensions?: string[];
|
|
32
34
|
recursive?: boolean;
|
|
33
35
|
metadata?: Record<string, unknown>;
|
|
34
36
|
}
|
|
37
|
+
/** Max content accepted from a tool call or CLI, so one payload cannot stall the server for a minute. */
|
|
38
|
+
export declare const MAX_INGEST_CHARS = 1000000;
|
|
35
39
|
export declare function ingestText(content: string, title: string, opts?: IngestFileOptions): Promise<IngestResult>;
|
|
36
40
|
export declare function ingestFile(filePath: string, opts?: IngestFileOptions): Promise<IngestResult>;
|
|
37
41
|
export declare function ingestDirectory(dirPath: string, opts?: IngestDirectoryOptions): Promise<{
|
|
38
42
|
ingested: IngestResult[];
|
|
39
43
|
skipped: string[];
|
|
44
|
+
ingestedCount: number;
|
|
45
|
+
skippedCount: number;
|
|
40
46
|
}>;
|
|
41
|
-
export declare function searchDocs(query: string, topK?: number, minScore?: number, filters?: SearchChunkFilters): Promise<SearchHit[]>;
|
|
47
|
+
export declare function searchDocs(query: string, topK?: number, minScore?: number, filters?: SearchChunkFilters, explain?: boolean): Promise<SearchHit[]>;
|
|
42
48
|
export declare function retrieve(query: string, topK?: number, minScore?: number, filters?: SearchChunkFilters): Promise<RetrievedContext>;
|
|
43
|
-
|
|
49
|
+
/** Bounded by default: a big store would otherwise dump every row into one tool result. */
|
|
50
|
+
export declare const LIST_DOCS_DEFAULT = 100;
|
|
51
|
+
export declare const LIST_DOCS_MAX = 1000;
|
|
52
|
+
export declare function listDocuments(opts?: {
|
|
53
|
+
limit?: number;
|
|
54
|
+
offset?: number;
|
|
55
|
+
}): {
|
|
56
|
+
documents: Array<Record<string, unknown>>;
|
|
57
|
+
total: number;
|
|
58
|
+
limit: number;
|
|
59
|
+
offset: number;
|
|
60
|
+
};
|
|
44
61
|
export declare function deleteDocument(docId: string): {
|
|
45
62
|
deleted: boolean;
|
|
46
63
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/rag/pipeline.ts"],"names":[],"mappings":"AAKA,OAAO,EAAgB,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExE,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC5G,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/rag/pipeline.ts"],"names":[],"mappings":"AAKA,OAAO,EAAgB,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExE,MAA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