nox-mem 3.11.2 → 3.11.3

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 CHANGED
@@ -239,6 +239,8 @@ nox-mem search "query" — hybrid search (FTS5 + semantic + RRF)
239
239
  nox-mem search "q" --as-of 2026-05-01 — time-travel: chunks that existed then
240
240
  nox-mem search "q" --changed-since 7d — recency window (15m, 2h, 7d, 1w or ISO)
241
241
  NOX_FTS_OR_FALLBACK=auto|on|off — FTS5 OR retry (stopwords dropped) when the AND query finds nothing; auto (default) = only when the key of the resolved embedding provider (NOX_EMBEDDING_PROVIDER, default gemini) is missing, so natural-language questions work on keyless installs and keyed setups are unchanged. An unrelated key such as OPENAI_API_KEY under the default gemini provider does not turn it off
242
+ NOX_HYBRID_FTS_QUERY=or|and — how the hybrid search (with embeddings) queries its FTS5 leg. or (default since 3.11.3) = the content words joined by OR; and = the whole question, which FTS5 ANDs (3.11.2 behaviour). With and, a natural-language question only matched chunks that contain every word, fillers included, so the two legs almost never agreed and hybrid search was in effect semantic-only
243
+ NOX_QUERY_EXPANSION=off|on — LLM query rewrites (gemini-2.5-flash-lite) fused as extra FTS lists. off by default since 3.11.3: each rewrite weighs as much as the whole semantic list, so the lexical side outweighed the semantic one. The meta row expansion_enabled='false' still switches it off when on
242
244
  NOX_QUERY_EMBED_TIMEOUT_MS=5000 — time budget for embedding a search/reflect query (retries included). When the provider is slower than this, search falls back to FTS5 instead of waiting. 0 disables the budget. Ingest and vectorize are not affected
243
245
  nox-mem answer "question" — grounded answer with citations (needs GEMINI_API_KEY); --as-of / --changed-since filter the evidence
244
246
  nox-mem ingest <files...> — ingest one or more markdown/json files; a directory is an error naming it, the other files still run, exit 1 if any failed
@@ -22,6 +22,7 @@ import { handleBrief } from "./api/brief.js";
22
22
  import { parseTemporalFilter, TemporalParseError } from "./lib/dates.js";
23
23
  import { handleIngestEvent } from "./api/ingest-event.js";
24
24
  import { resolveApiPort } from "./lib/api-port.js";
25
+ import { expansionEnvEnabled } from "./search-expansion.js";
25
26
  import { handleObsHealth, handleObsRecentOps, handleObsCanaryTail, } from "./observability.js";
26
27
  const PORT = resolveApiPort();
27
28
  // Security 2026-04-23: bind to loopback by default (was 0.0.0.0).
@@ -202,7 +203,7 @@ async function handleRequest(req, res) {
202
203
  avg_results: Math.round(agg.avg_r * 100) / 100,
203
204
  semantic_ratio: Math.round(agg.sem_ratio * 1000) / 1000,
204
205
  p95_latency_ms: p95,
205
- expansion_enabled: !cfg || (cfg.value !== "false" && cfg.value !== "0"),
206
+ expansion_enabled: expansionEnvEnabled() && (!cfg || (cfg.value !== "false" && cfg.value !== "0")),
206
207
  skip_reasons: Object.fromEntries(reasons.map((r) => [r.r, r.c])),
207
208
  };
208
209
  }
@@ -23,10 +23,24 @@ Regras: CADA variante deve ter 3-10 palavras. NUNCA repita a query original. NUN
23
23
  Query original:
24
24
  `;
25
25
  /**
26
- * Lê config `expansion_enabled` da tabela meta. Default = true (plano Fase 1.6).
27
- * Toggle sem redeploy: UPDATE meta SET value='false' WHERE key='expansion_enabled';
26
+ * Query expansion is OFF by default since 3.11.3. Each variant is fused as one more FTS batch with
27
+ * the same RRF weight as the single semantic batch, so with three variants the lexical side
28
+ * outweighs the semantic one three to one; on the IP&M revision benchmark (LoCoMo + LongMemEval,
29
+ * 2,482 queries) that cost 0.077 nDCG@10 on LoCoMo once the FTS leg queried with OR (memoria-nox,
30
+ * protocol v2 §11, rounds 2 and 3). Opt in with NOX_QUERY_EXPANSION=on.
31
+ */
32
+ export function expansionEnvEnabled(env = process.env) {
33
+ const v = (env.NOX_QUERY_EXPANSION ?? "off").trim().toLowerCase();
34
+ return v === "on" || v === "1" || v === "true";
35
+ }
36
+ /**
37
+ * True only when NOX_QUERY_EXPANSION is on AND the `expansion_enabled` row of the meta table does
38
+ * not switch it off (the row stays a kill switch: UPDATE meta SET value='false' WHERE key='expansion_enabled').
39
+ * db.ts seeds that row as 'true' in every database, so it cannot carry the default by itself.
28
40
  */
29
41
  export function isExpansionEnabled() {
42
+ if (!expansionEnvEnabled())
43
+ return false;
30
44
  try {
31
45
  const db = getDb();
32
46
  const row = db.prepare("SELECT value FROM meta WHERE key = 'expansion_enabled'").get();
package/dist/search.js CHANGED
@@ -369,7 +369,19 @@ export function buildFtsOrQuery(sanitized) {
369
369
  }
370
370
  return terms.length > 0 ? terms.join(" OR ") : null;
371
371
  }
372
- export function search(query, limit = 5, trackAccess = true, filter) {
372
+ /**
373
+ * How searchHybrid queries its FTS leg. "or" (default since 3.11.3): the OR expression of the
374
+ * content terms (buildFtsOrQuery). "and": the sanitized question as is, which FTS5 ANDs, so every
375
+ * word of a natural-language question, fillers included, must occur in the chunk (3.11.2
376
+ * behaviour). With AND the FTS leg returned chunks the semantic leg almost never returned: on the
377
+ * IP&M revision benchmark 2,423 of 2,482 fused top results came from one list only, and the
378
+ * hybrid search was in effect semantic-only (memoria-nox, protocol v2 §11). Rollback:
379
+ * NOX_HYBRID_FTS_QUERY=and.
380
+ */
381
+ export function hybridFtsQueryMode(env = process.env) {
382
+ return (env.NOX_HYBRID_FTS_QUERY ?? "or").trim().toLowerCase() === "and" ? "and" : "or";
383
+ }
384
+ export function search(query, limit = 5, trackAccess = true, filter, opts = {}) {
373
385
  const db = getDb();
374
386
  const sanitized = query.replace(/[^\p{L}\p{N}\s]/gu, " ").replace(/\s+/g, " ").trim();
375
387
  if (!sanitized)
@@ -392,15 +404,16 @@ export function search(query, limit = 5, trackAccess = true, filter) {
392
404
  ORDER BY rank LIMIT 20
393
405
  `).all(match, ...(temporal?.params ?? []));
394
406
  let rows;
407
+ const orFirst = opts.ftsQuery === "or" ? buildFtsOrQuery(sanitized) : null;
395
408
  try {
396
- rows = runFts(sanitized);
409
+ rows = runFts(orFirst ?? sanitized);
397
410
  }
398
411
  catch {
399
412
  return [];
400
413
  }
401
414
  // OR fallback: only when the AND query found nothing, so an existing result
402
415
  // set is never reordered or extended. Same temporal fragment and params.
403
- if (rows.length === 0 && ftsOrFallbackEnabled()) {
416
+ if (rows.length === 0 && !orFirst && ftsOrFallbackEnabled()) {
404
417
  const orQuery = buildFtsOrQuery(sanitized);
405
418
  if (orQuery) {
406
419
  try {
@@ -594,13 +607,14 @@ export async function searchHybrid(query, limit = 5, trackAccess = true, filter,
594
607
  // Kick off original-query searches IMMEDIATELY and expansion in parallel.
595
608
  // Total time = max(expansion + variantFTS, originalFTS+semantic) — does not block
596
609
  // the original search behind a 500-1500ms Gemini call.
597
- const originalFtsPromise = Promise.resolve(search(query.trim(), perVariantLimit, trackAccess, filter));
610
+ const ftsOpts = { ftsQuery: hybridFtsQueryMode() };
611
+ const originalFtsPromise = Promise.resolve(search(query.trim(), perVariantLimit, trackAccess, filter, ftsOpts));
598
612
  const semPromise = searchSemantic(query.trim(), perVariantLimit * 2, trackAccess, filter);
599
613
  const expansionPromise = expandQuery(query);
600
614
  const expansion = await expansionPromise;
601
615
  const variants = expansion.variants;
602
616
  // Variants (excluding the original, which is already running) → FTS only.
603
- const extraVariantFtsPromises = variants.slice(1).map((v) => Promise.resolve(search(v, perVariantLimit, trackAccess, filter)));
617
+ const extraVariantFtsPromises = variants.slice(1).map((v) => Promise.resolve(search(v, perVariantLimit, trackAccess, filter, ftsOpts)));
604
618
  const allBatches = await Promise.all([
605
619
  originalFtsPromise,
606
620
  ...extraVariantFtsPromises,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nox-mem",
3
- "version": "3.11.2",
3
+ "version": "3.11.3",
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",