nox-mem 3.5.1 → 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.
@@ -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 { embedText, upsertEmbedding } = await import("./embed.js");
46
- const vec = await embedText(chunkText);
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
- /** Test seam: replaces the provider call behind embedText (null restores it). */
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 { embedText, ensureVecTable, upsertEmbedding } = await import("./embed.js");
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 embedText(chunk.chunk_text);
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++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nox-mem",
3
- "version": "3.5.1",
3
+ "version": "3.5.2",
4
4
  "description": "Pain-weighted hybrid memory engine: FTS5 + semantic search + knowledge graph, self-hosted on any Linux VPS.",
5
5
  "type": "module",
6
6
  "license": "MIT",