nox-mem 3.11.1 → 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 +5 -0
- package/dist/api-server.js +2 -1
- package/dist/kg-llm.js +1 -1
- package/dist/search-expansion.js +16 -2
- package/dist/search.js +19 -5
- package/package.json +1 -1
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
|
|
@@ -251,6 +253,9 @@ nox-mem vectorize — embed any unembedded chunks
|
|
|
251
253
|
nox-mem stats — chunk/entity/vector counts
|
|
252
254
|
nox-mem kg-build — extract knowledge graph entities
|
|
253
255
|
nox-mem reflect "question" — synthesis over memory + KG, with cited sources
|
|
256
|
+
nox-mem session-distill — distill memories from agent session JSONL files (Gemini; oldest first; --dry-run,
|
|
257
|
+
--agents, --lookback-days, --max-sessions); stored as `distilled`, which never decays.
|
|
258
|
+
Multi-agent layouts only (NOX_AGENTS_DIR); on a standalone install there is nothing to read
|
|
254
259
|
nox-mem-api — start HTTP API on $NOX_API_PORT (default 18802)
|
|
255
260
|
nox-mem-mcp — start MCP server over stdio (22 tools, incl. nox_mem_answer and nox_mem_get, for agents)
|
|
256
261
|
nox-mem doctor — health check (core + optional integrations)
|
package/dist/api-server.js
CHANGED
|
@@ -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
|
}
|
package/dist/kg-llm.js
CHANGED
|
@@ -82,7 +82,7 @@ export function normalizeRelationReason(raw, relationType) {
|
|
|
82
82
|
// ─── Fast-path regex (PT-BR) ────────────────────────────────────────────────
|
|
83
83
|
//
|
|
84
84
|
// Detecta entidades óbvias sem LLM. Se ≥3 encontradas, pula Gemini.
|
|
85
|
-
// Patterns calibrados para
|
|
85
|
+
// Patterns calibrados para documentos de negócio em PT-BR.
|
|
86
86
|
const RE_VALUE_BRL = /R\$\s?\d[\d\.,]*(?:\s?(?:mil|milh[ãa]o|milh[õo]es|bi|bilh[ãa]o|k|m|b))?/gi;
|
|
87
87
|
const RE_VALUE_USD = /US?\$\s?\d[\d\.,]*(?:\s?(?:k|m|b|million|thousand|billion))?/gi;
|
|
88
88
|
const RE_VALUE_EUR = /€\s?\d[\d\.,]*/gi;
|
package/dist/search-expansion.js
CHANGED
|
@@ -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
|
-
*
|
|
27
|
-
*
|
|
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
|
-
|
|
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
|
|
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,
|