nox-mem 3.5.0 → 3.5.2
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/dist/api-server.js +1 -12
- package/dist/crystallize.js +2 -2
- package/dist/embed.js +23 -2
- package/dist/ingest.js +2 -2
- package/dist/lib/query-params.js +19 -0
- package/package.json +1 -1
package/dist/api-server.js
CHANGED
|
@@ -16,6 +16,7 @@ import { getVaultFacts } from "./lib/spo-injection.js";
|
|
|
16
16
|
import { execFileSync } from "child_process";
|
|
17
17
|
import { applyCorsHeaders, handlePreflight } from "./api/cors.js";
|
|
18
18
|
import { safeErrorMessage } from "./lib/api/safe-error-message.js";
|
|
19
|
+
import { parseQuery } from "./lib/query-params.js";
|
|
19
20
|
import { registerWireUpRoutes } from "./api/wire-up.js";
|
|
20
21
|
import { handleBrief } from "./api/brief.js";
|
|
21
22
|
import { parseTemporalFilter, TemporalParseError } from "./lib/dates.js";
|
|
@@ -33,18 +34,6 @@ function json(res, data, status = 200) {
|
|
|
33
34
|
});
|
|
34
35
|
res.end(JSON.stringify(data));
|
|
35
36
|
}
|
|
36
|
-
function parseQuery(url) {
|
|
37
|
-
const idx = url.indexOf("?");
|
|
38
|
-
if (idx === -1)
|
|
39
|
-
return {};
|
|
40
|
-
const params = {};
|
|
41
|
-
for (const part of url.substring(idx + 1).split("&")) {
|
|
42
|
-
const [k, v] = part.split("=");
|
|
43
|
-
if (k)
|
|
44
|
-
params[decodeURIComponent(k)] = decodeURIComponent(v || "");
|
|
45
|
-
}
|
|
46
|
-
return params;
|
|
47
|
-
}
|
|
48
37
|
function readBody(req, limit = 65536) {
|
|
49
38
|
return new Promise((resolve, reject) => {
|
|
50
39
|
let data = "";
|
package/dist/crystallize.js
CHANGED
|
@@ -42,8 +42,8 @@ export async function crystallize(input) {
|
|
|
42
42
|
// Skip silently if GEMINI_API_KEY is missing or embed fails — FTS still works.
|
|
43
43
|
try {
|
|
44
44
|
if (process.env.GEMINI_API_KEY) {
|
|
45
|
-
const {
|
|
46
|
-
const vec = await
|
|
45
|
+
const { embedDocument, upsertEmbedding } = await import("./embed.js");
|
|
46
|
+
const vec = await embedDocument(chunkText);
|
|
47
47
|
upsertEmbedding(db, id, vec);
|
|
48
48
|
}
|
|
49
49
|
}
|
package/dist/embed.js
CHANGED
|
@@ -200,14 +200,17 @@ export function queryEmbedTimeoutMs(env = process.env) {
|
|
|
200
200
|
const n = Number(raw);
|
|
201
201
|
return Number.isFinite(n) && n >= 0 ? n : 5000;
|
|
202
202
|
}
|
|
203
|
-
/**
|
|
203
|
+
/**
|
|
204
|
+
* Test seam: replaces the provider call behind embedText and embedDocument (null
|
|
205
|
+
* restores it). `kind` tells which side of retrieval the call embeds.
|
|
206
|
+
*/
|
|
204
207
|
let embedOverride = null;
|
|
205
208
|
export function __setEmbedForTests(fn) {
|
|
206
209
|
embedOverride = fn;
|
|
207
210
|
}
|
|
208
211
|
async function embedTextUnbounded(text, signal) {
|
|
209
212
|
if (embedOverride)
|
|
210
|
-
return embedOverride(text, signal);
|
|
213
|
+
return embedOverride(text, signal, "query");
|
|
211
214
|
// Route to abstract provider when configured; keep native Gemini path as default.
|
|
212
215
|
const provider = activeEmbeddingProvider();
|
|
213
216
|
if (provider !== null) {
|
|
@@ -217,6 +220,24 @@ async function embedTextUnbounded(text, signal) {
|
|
|
217
220
|
const values = await geminiEmbedQuery(text, signal);
|
|
218
221
|
return new Float32Array(values);
|
|
219
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Embeds a text that will be STORED and retrieved (a chunk, a procedure), with
|
|
225
|
+
* taskType RETRIEVAL_DOCUMENT. embedText is the query side (RETRIEVAL_QUERY) and
|
|
226
|
+
* must not be used for stored text: Gemini embeds the two task types into
|
|
227
|
+
* different spaces. Until 2026-10-14 the inline auto-vectorize in ingest and
|
|
228
|
+
* crystallize called embedText, so ~2.6% of a production corpus was stored with
|
|
229
|
+
* query embeddings while the batch `vectorize` path used RETRIEVAL_DOCUMENT.
|
|
230
|
+
*/
|
|
231
|
+
export async function embedDocument(text) {
|
|
232
|
+
if (embedOverride)
|
|
233
|
+
return embedOverride(text, undefined, "document");
|
|
234
|
+
const provider = activeEmbeddingProvider();
|
|
235
|
+
if (provider !== null) {
|
|
236
|
+
const vecs = await provider.embed([text]);
|
|
237
|
+
return vecs[0];
|
|
238
|
+
}
|
|
239
|
+
return new Float32Array(await geminiEmbed(text));
|
|
240
|
+
}
|
|
220
241
|
/**
|
|
221
242
|
* True batch embedding via Gemini batchEmbedContents API.
|
|
222
243
|
* Sends up to `batchSize` texts per HTTP call (default 50) — on gemini-embedding-001
|
package/dist/ingest.js
CHANGED
|
@@ -184,14 +184,14 @@ export async function ingestFile(filePath, externalDb, skipDelete) {
|
|
|
184
184
|
// by a batch vectorize phase; embedding per file there is too expensive.
|
|
185
185
|
if (!externalDb && process.env.GEMINI_API_KEY) {
|
|
186
186
|
try {
|
|
187
|
-
const {
|
|
187
|
+
const { embedDocument, ensureVecTable, upsertEmbedding } = await import("./embed.js");
|
|
188
188
|
const db = getDb();
|
|
189
189
|
ensureVecTable(db);
|
|
190
190
|
const newChunks = db.prepare("SELECT id, chunk_text FROM chunks WHERE source_file = ? ORDER BY id DESC LIMIT 20").all(relPath);
|
|
191
191
|
let embedded = 0;
|
|
192
192
|
for (const chunk of newChunks) {
|
|
193
193
|
try {
|
|
194
|
-
const emb = await
|
|
194
|
+
const emb = await embedDocument(chunk.chunk_text);
|
|
195
195
|
if (emb && emb.length > 0) {
|
|
196
196
|
upsertEmbedding(db, chunk.id, emb);
|
|
197
197
|
embedded++;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Query-string parsing for the HTTP API.
|
|
2
|
+
//
|
|
3
|
+
// The hand-rolled split("&") / split("=") parser this replaces had three defects:
|
|
4
|
+
// "+" stayed a literal plus (URLSearchParams, and so most JS clients, encode a
|
|
5
|
+
// space as "+", which turned `salience formula` into a search for
|
|
6
|
+
// `salience+formula`); a value containing "=" was truncated at it; and keys went
|
|
7
|
+
// into a plain object, so `__proto__` / `hasOwnProperty` could collide with
|
|
8
|
+
// Object.prototype. URLSearchParams handles the first two and never throws on a
|
|
9
|
+
// malformed "%" escape. For the third, the prototype-reaching keys are dropped
|
|
10
|
+
// (no route reads them) and the object has no prototype as a second layer.
|
|
11
|
+
const RESERVED_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
12
|
+
export function parseQuery(url) {
|
|
13
|
+
const idx = url.indexOf("?");
|
|
14
|
+
const pairs = idx === -1 ? [] : [...new URLSearchParams(url.substring(idx + 1))];
|
|
15
|
+
// fromEntries defines own data properties (a later duplicate key wins, as
|
|
16
|
+
// before) instead of assigning through a computed key.
|
|
17
|
+
const params = Object.fromEntries(pairs.filter(([k]) => k && !RESERVED_KEYS.has(k)));
|
|
18
|
+
return Object.setPrototypeOf(params, null);
|
|
19
|
+
}
|