nox-mem 3.0.0 → 3.1.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/README.md +57 -18
- package/dist/db.js +42 -2
- package/dist/embed.d.ts +12 -0
- package/dist/embed.js +75 -4
- package/dist/reflect.js +22 -21
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -78,18 +78,18 @@ nox-mem stats
|
|
|
78
78
|
|
|
79
79
|
| Var | Default | Purpose |
|
|
80
80
|
|---|---|---|
|
|
81
|
-
| `NOX_LLM_PROVIDER` | `gemini` | `gemini
|
|
82
|
-
| `NOX_LLM_MODEL` | `gemini-2.5-flash-lite`
|
|
83
|
-
| `NOX_LLM_BASE_URL` | provider default | OpenAI-compat
|
|
84
|
-
| `NOX_LLM_API_KEY` | falls back to `GEMINI_API_KEY` / `OPENAI_API_KEY` | LLM key. |
|
|
81
|
+
| `NOX_LLM_PROVIDER` | `gemini` | `gemini`, `openai` (any OpenAI-compatible endpoint), or `anthropic`. |
|
|
82
|
+
| `NOX_LLM_MODEL` | `gemini-2.5-flash-lite` | LLM model id (e.g. `gpt-4o-mini`, `claude-3-5-haiku-20241022`). |
|
|
83
|
+
| `NOX_LLM_BASE_URL` | provider default | OpenAI-compat base URL — DeepSeek/OpenRouter/Together/Ollama/vLLM. Ignored for `anthropic`. |
|
|
84
|
+
| `NOX_LLM_API_KEY` | falls back to `GEMINI_API_KEY` / `OPENAI_API_KEY` / `ANTHROPIC_API_KEY` | LLM key. |
|
|
85
85
|
| `NOX_LLM_FALLBACK` | — | Fallback chain, e.g. `openai:gpt-4o-mini`. |
|
|
86
|
-
| `NOX_EMBEDDING_PROVIDER` | `gemini` | `gemini` or `
|
|
87
|
-
| `NOX_EMBEDDING_MODEL` | `gemini-embedding-001`
|
|
88
|
-
| `NOX_EMBEDDING_BASE_URL` | provider default | Embedding
|
|
86
|
+
| `NOX_EMBEDDING_PROVIDER` | `gemini` | `gemini`, `openai` (any OpenAI-compat endpoint), or `voyage`. Alias: `NOX_EMBED_PROVIDER`. |
|
|
87
|
+
| `NOX_EMBEDDING_MODEL` | `gemini-embedding-001` | Embedding model id (e.g. `text-embedding-3-large`, `voyage-3`). Alias: `NOX_EMBED_MODEL`. |
|
|
88
|
+
| `NOX_EMBEDDING_BASE_URL` | provider default | Embedding base URL for OpenAI-compat providers. Alias: `NOX_EMBED_BASE_URL`. |
|
|
89
89
|
| `NOX_EMBEDDING_API_KEY` | falls back to provider key | Embedding key. Alias: `NOX_EMBED_API_KEY`. |
|
|
90
|
-
| `NOX_EMBEDDING_DIM` | `3072` | Vector
|
|
90
|
+
| `NOX_EMBEDDING_DIM` | `3072` | Vector dimension. **MUST equal the vec0 table dim** — changing it requires re-embedding the whole corpus. Alias: `NOX_EMBED_DIM`. |
|
|
91
91
|
|
|
92
|
-
> ⚠️
|
|
92
|
+
> ⚠️ **Dimension lock:** the sqlite-vec table is created with a fixed dimension. Switching embedding provider or model requires re-embedding the **entire corpus** with a single model at a single dimension, and that dimension must match the `vec0` table. `text-embedding-3-large` supports `dimensions=3072` (matches the default Gemini table); `text-embedding-3-small` is 1536 — only usable with a fresh/empty database. Set `NOX_EMBEDDING_MODEL` + `NOX_EMBEDDING_DIM` deliberately. Vectors from different models are not comparable — mixing silently corrupts semantic search.
|
|
93
93
|
|
|
94
94
|
### Advanced (safe to leave unset — defaults are standalone-neutral)
|
|
95
95
|
|
|
@@ -111,23 +111,62 @@ nox-mem stats
|
|
|
111
111
|
|
|
112
112
|
## Multi-provider support
|
|
113
113
|
|
|
114
|
-
By default nox-mem uses **Gemini via AI Studio** (`gemini
|
|
114
|
+
By default nox-mem uses **Gemini via Google AI Studio** for both LLM synthesis and embeddings (`GEMINI_API_KEY`, model `gemini-2.5-flash-lite`, embeddings `gemini-embedding-001` at 3072 dimensions).
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
Both axes are independently pluggable at runtime — no rebuild required.
|
|
117
117
|
|
|
118
|
+
### LLM synthesis (reflect, answer, kg-extract)
|
|
119
|
+
|
|
120
|
+
Supported values for `NOX_LLM_PROVIDER`: `gemini` (default) · `openai` (any OpenAI-compatible endpoint) · `anthropic`.
|
|
121
|
+
|
|
122
|
+
**Example — DeepSeek via direct API (OpenAI-compat):**
|
|
118
123
|
```bash
|
|
119
124
|
NOX_LLM_PROVIDER=openai
|
|
120
|
-
NOX_LLM_BASE_URL=https://
|
|
121
|
-
NOX_LLM_MODEL=deepseek
|
|
125
|
+
NOX_LLM_BASE_URL=https://api.deepseek.com/v1
|
|
126
|
+
NOX_LLM_MODEL=deepseek-chat
|
|
122
127
|
NOX_LLM_API_KEY=sk-...
|
|
128
|
+
```
|
|
123
129
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
130
|
+
**Example — Anthropic Claude:**
|
|
131
|
+
```bash
|
|
132
|
+
NOX_LLM_PROVIDER=anthropic
|
|
133
|
+
NOX_LLM_MODEL=claude-3-5-haiku-20241022
|
|
134
|
+
NOX_LLM_API_KEY=sk-ant-... # or set ANTHROPIC_API_KEY
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Example — local Ollama:**
|
|
138
|
+
```bash
|
|
139
|
+
NOX_LLM_PROVIDER=openai
|
|
140
|
+
NOX_LLM_BASE_URL=http://127.0.0.1:11434/v1
|
|
141
|
+
NOX_LLM_MODEL=llama3.2
|
|
142
|
+
NOX_LLM_API_KEY=ollama
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Fallback chain:** `NOX_LLM_FALLBACK=openai:gpt-4o-mini` — tried if the primary LLM call fails.
|
|
146
|
+
|
|
147
|
+
### Embedding provider
|
|
148
|
+
|
|
149
|
+
Supported values for `NOX_EMBEDDING_PROVIDER` (alias `NOX_EMBED_PROVIDER`): `gemini` (default) · `openai` (any OpenAI-compat endpoint, including local Ollama/vLLM) · `voyage`.
|
|
150
|
+
|
|
151
|
+
**Example — OpenAI native (3072-dim parity with default Gemini table):**
|
|
152
|
+
```bash
|
|
153
|
+
NOX_EMBEDDING_PROVIDER=openai
|
|
154
|
+
NOX_EMBEDDING_BASE_URL=https://api.openai.com/v1
|
|
155
|
+
NOX_EMBEDDING_MODEL=text-embedding-3-large
|
|
156
|
+
NOX_EMBEDDING_DIM=3072
|
|
157
|
+
NOX_EMBEDDING_API_KEY=sk-...
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Example — local Ollama embedding:**
|
|
161
|
+
```bash
|
|
162
|
+
NOX_EMBEDDING_PROVIDER=openai
|
|
163
|
+
NOX_EMBEDDING_BASE_URL=http://127.0.0.1:11434/v1
|
|
164
|
+
NOX_EMBEDDING_MODEL=nomic-embed-text
|
|
165
|
+
NOX_EMBEDDING_DIM=768 # must match the model's output dim
|
|
166
|
+
NOX_EMBEDDING_API_KEY=ollama
|
|
128
167
|
```
|
|
129
168
|
|
|
130
|
-
|
|
169
|
+
> ⚠️ **Dimension lock:** the sqlite-vec table is created once with a fixed dimension. Switching embedding provider or model requires re-embedding the **entire corpus** with a single model at a single dimension, and that dimension must match the `vec0` table. `text-embedding-3-large` supports `dimensions=3072` (matches the default Gemini table). `text-embedding-3-small` outputs 1536 — only usable with a fresh/empty database. Set `NOX_EMBEDDING_MODEL` + `NOX_EMBEDDING_DIM` deliberately and do not mix vectors from different models.
|
|
131
170
|
|
|
132
171
|
---
|
|
133
172
|
|
package/dist/db.js
CHANGED
|
@@ -2,6 +2,8 @@ import Database from "better-sqlite3";
|
|
|
2
2
|
import { resolve, dirname } from "path";
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
4
|
import { copyFileSync, existsSync, mkdirSync, readdirSync, unlinkSync } from "fs";
|
|
5
|
+
// @ts-ignore - sqlite-vec ships no type declarations for this helper
|
|
6
|
+
import { getLoadablePath as vecLoadablePath } from "sqlite-vec";
|
|
5
7
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
8
|
const _ws = process.env.OPENCLAW_WORKSPACE;
|
|
7
9
|
// DB path resolution — priority order (postmortem 2026-05-19 fix):
|
|
@@ -71,8 +73,18 @@ export function getDb() {
|
|
|
71
73
|
// when CLI runs DELETE/INSERT on chunks. Source fix migrated 2026-05-30 from
|
|
72
74
|
// tactical dist/db.js patch; persists across npm build.
|
|
73
75
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
// Resolve the vec0 extension for the CURRENT platform via sqlite-vec's own
|
|
77
|
+
// resolver (it reads the matching sqlite-vec-<os>-<arch> optional dependency).
|
|
78
|
+
// The previous hardcoded "sqlite-vec-linux-x64" path broke every non-Linux-x64
|
|
79
|
+
// install (macOS, ARM, Windows) — semantic search silently fell back to BM25.
|
|
80
|
+
let vec0Path;
|
|
81
|
+
try {
|
|
82
|
+
vec0Path = vecLoadablePath();
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
vec0Path = resolve(__dirname, "..", "node_modules", "sqlite-vec-linux-x64", "vec0");
|
|
86
|
+
}
|
|
87
|
+
_db.loadExtension(vec0Path);
|
|
76
88
|
}
|
|
77
89
|
catch (err) {
|
|
78
90
|
console.error("[db] sqlite-vec load failed (vec_chunks triggers may fail):", err.message);
|
|
@@ -158,8 +170,36 @@ function ensureSchema(db) {
|
|
|
158
170
|
migrateToV6(db);
|
|
159
171
|
if (currentVersion < 7)
|
|
160
172
|
migrateToV7(db);
|
|
173
|
+
if (currentVersion < 18)
|
|
174
|
+
migrateToV8(db);
|
|
161
175
|
db.prepare("INSERT OR REPLACE INTO meta (key, value, updated_at) VALUES ('schema_version', ?, datetime('now'))").run(String(SCHEMA_VERSION));
|
|
162
176
|
}
|
|
177
|
+
function migrateToV8(db) {
|
|
178
|
+
// Standalone consolidation of the column additions that the canonical engine
|
|
179
|
+
// introduced across schema v8–v18 (typed retention, pain-weighting, entity
|
|
180
|
+
// sections). The ingest path (ingest.ts / ingest-entity.ts) writes these
|
|
181
|
+
// columns, but the v1–v7 migrations shipped in this repo never create them —
|
|
182
|
+
// so a clean install crashed on the first `ingest` with
|
|
183
|
+
// "table chunks has no column named retention_days".
|
|
184
|
+
// Per-column try/catch keeps this idempotent on DBs already patched at any version.
|
|
185
|
+
try {
|
|
186
|
+
db.exec(`ALTER TABLE chunks ADD COLUMN retention_days INTEGER`);
|
|
187
|
+
}
|
|
188
|
+
catch { }
|
|
189
|
+
try {
|
|
190
|
+
db.exec(`ALTER TABLE chunks ADD COLUMN pain REAL DEFAULT 0.2`);
|
|
191
|
+
}
|
|
192
|
+
catch { }
|
|
193
|
+
try {
|
|
194
|
+
db.exec(`ALTER TABLE chunks ADD COLUMN section TEXT`);
|
|
195
|
+
}
|
|
196
|
+
catch { }
|
|
197
|
+
try {
|
|
198
|
+
db.exec(`ALTER TABLE chunks ADD COLUMN section_boost REAL`);
|
|
199
|
+
}
|
|
200
|
+
catch { }
|
|
201
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_chunks_section ON chunks(section);`);
|
|
202
|
+
}
|
|
163
203
|
function migrateToV7(db) {
|
|
164
204
|
// Fase 1.7a — Core Memory Quality
|
|
165
205
|
// - kg_entities.attributes: JSON com campos ricos por tipo (ontology grounding)
|
package/dist/embed.d.ts
CHANGED
|
@@ -2,9 +2,21 @@
|
|
|
2
2
|
* embed.ts - Semantic embedding via Gemini API (gemini-embedding-001, 768-dim)
|
|
3
3
|
* Uses the same API key already configured in the OpenClaw gateway.
|
|
4
4
|
* Zero local model weight, zero sqlite-vec binding issues.
|
|
5
|
+
*
|
|
6
|
+
* Provider routing (added 2026-06-15):
|
|
7
|
+
* When NOX_EMBEDDING_PROVIDER / NOX_EMBED_PROVIDER is set to anything other
|
|
8
|
+
* than "gemini" (the default), embedding calls are delegated to the abstract
|
|
9
|
+
* EmbeddingProvider from src/providers/. The native Gemini path (taskType-aware
|
|
10
|
+
* RETRIEVAL_DOCUMENT / RETRIEVAL_QUERY) is preserved 100% when using gemini.
|
|
5
11
|
*/
|
|
6
12
|
import Database from "better-sqlite3";
|
|
7
13
|
declare const EMBEDDING_DIM = 3072;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the effective embedding dimension for the current provider.
|
|
16
|
+
* Priority: provider.dimensions > NOX_EMBEDDING_DIM / NOX_EMBED_DIM env > EMBEDDING_DIM (3072).
|
|
17
|
+
* Used by ensureVecTable so the vec0 column matches whatever provider is active.
|
|
18
|
+
*/
|
|
19
|
+
export declare function activeEmbeddingDim(): number;
|
|
8
20
|
export declare function embedText(text: string): Promise<Float32Array>;
|
|
9
21
|
/**
|
|
10
22
|
* True batch embedding via Gemini batchEmbedContents API.
|
package/dist/embed.js
CHANGED
|
@@ -2,12 +2,27 @@
|
|
|
2
2
|
* embed.ts - Semantic embedding via Gemini API (gemini-embedding-001, 768-dim)
|
|
3
3
|
* Uses the same API key already configured in the OpenClaw gateway.
|
|
4
4
|
* Zero local model weight, zero sqlite-vec binding issues.
|
|
5
|
+
*
|
|
6
|
+
* Provider routing (added 2026-06-15):
|
|
7
|
+
* When NOX_EMBEDDING_PROVIDER / NOX_EMBED_PROVIDER is set to anything other
|
|
8
|
+
* than "gemini" (the default), embedding calls are delegated to the abstract
|
|
9
|
+
* EmbeddingProvider from src/providers/. The native Gemini path (taskType-aware
|
|
10
|
+
* RETRIEVAL_DOCUMENT / RETRIEVAL_QUERY) is preserved 100% when using gemini.
|
|
5
11
|
*/
|
|
6
12
|
import * as path from "path";
|
|
13
|
+
import { selectEmbeddingProvider } from "./providers/index.js";
|
|
7
14
|
// @ts-ignore
|
|
8
|
-
import { load as loadVec } from "sqlite-vec";
|
|
9
|
-
//
|
|
10
|
-
|
|
15
|
+
import { load as loadVec, getLoadablePath as vecLoadablePath } from "sqlite-vec";
|
|
16
|
+
// Resolve the vec0 extension for the CURRENT platform. The previous hardcoded
|
|
17
|
+
// "sqlite-vec-linux-x64" path only worked on Linux x64; sqlite-vec's own
|
|
18
|
+
// resolver picks the right sqlite-vec-<os>-<arch> optional dependency.
|
|
19
|
+
const VEC0_PATH = (() => {
|
|
20
|
+
try {
|
|
21
|
+
return vecLoadablePath();
|
|
22
|
+
}
|
|
23
|
+
catch { /* fall back to legacy path below */ }
|
|
24
|
+
return path.join(import.meta.dirname || __dirname, "../node_modules/sqlite-vec-linux-x64/vec0");
|
|
25
|
+
})();
|
|
11
26
|
// Wrapper para garantir que vec0 carrega corretamente
|
|
12
27
|
function loadVecSafe(db) {
|
|
13
28
|
try {
|
|
@@ -106,8 +121,47 @@ async function geminiEmbedQuery(text) {
|
|
|
106
121
|
function sleep(ms) {
|
|
107
122
|
return new Promise((r) => setTimeout(r, ms));
|
|
108
123
|
}
|
|
124
|
+
// ─── Provider abstraction (lazy singleton) ───────────────────────────────────
|
|
125
|
+
// undefined = not yet resolved; null = use native gemini path
|
|
126
|
+
let _embProvider;
|
|
127
|
+
/**
|
|
128
|
+
* Returns the active non-Gemini provider, or null when the native Gemini path
|
|
129
|
+
* should be used (default). Resolved once and cached for the process lifetime.
|
|
130
|
+
*/
|
|
131
|
+
function activeEmbeddingProvider() {
|
|
132
|
+
if (_embProvider !== undefined)
|
|
133
|
+
return _embProvider;
|
|
134
|
+
const name = (process.env.NOX_EMBEDDING_PROVIDER ??
|
|
135
|
+
process.env.NOX_EMBED_PROVIDER ??
|
|
136
|
+
"gemini").trim();
|
|
137
|
+
_embProvider = name === "gemini" ? null : selectEmbeddingProvider(name);
|
|
138
|
+
return _embProvider;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Returns the effective embedding dimension for the current provider.
|
|
142
|
+
* Priority: provider.dimensions > NOX_EMBEDDING_DIM / NOX_EMBED_DIM env > EMBEDDING_DIM (3072).
|
|
143
|
+
* Used by ensureVecTable so the vec0 column matches whatever provider is active.
|
|
144
|
+
*/
|
|
145
|
+
export function activeEmbeddingDim() {
|
|
146
|
+
const provider = activeEmbeddingProvider();
|
|
147
|
+
if (provider !== null)
|
|
148
|
+
return provider.dimensions;
|
|
149
|
+
const raw = process.env.NOX_EMBEDDING_DIM ?? process.env.NOX_EMBED_DIM;
|
|
150
|
+
if (raw) {
|
|
151
|
+
const n = Number(raw);
|
|
152
|
+
if (Number.isFinite(n) && n > 0)
|
|
153
|
+
return n;
|
|
154
|
+
}
|
|
155
|
+
return EMBEDDING_DIM;
|
|
156
|
+
}
|
|
109
157
|
// ─── Public API ──────────────────────────────────────────────────────────────
|
|
110
158
|
export async function embedText(text) {
|
|
159
|
+
// Route to abstract provider when configured; keep native Gemini path as default.
|
|
160
|
+
const provider = activeEmbeddingProvider();
|
|
161
|
+
if (provider !== null) {
|
|
162
|
+
const vecs = await provider.embed([text]);
|
|
163
|
+
return vecs[0];
|
|
164
|
+
}
|
|
111
165
|
const values = await geminiEmbedQuery(text);
|
|
112
166
|
return new Float32Array(values);
|
|
113
167
|
}
|
|
@@ -118,6 +172,21 @@ export async function embedText(text) {
|
|
|
118
172
|
* Pauses `pauseMs` between batches to stay under 100 RPM on the free tier.
|
|
119
173
|
*/
|
|
120
174
|
export async function embedBatchAPI(texts, options = {}) {
|
|
175
|
+
// Delegate to abstract provider when configured; keep Gemini batch path as default.
|
|
176
|
+
const provider = activeEmbeddingProvider();
|
|
177
|
+
if (provider !== null) {
|
|
178
|
+
const batchSize = Math.max(1, options.batchSize ?? 50);
|
|
179
|
+
const results = new Array(texts.length);
|
|
180
|
+
for (let start = 0; start < texts.length; start += batchSize) {
|
|
181
|
+
const slice = texts.slice(start, start + batchSize);
|
|
182
|
+
const vecs = await provider.embed(slice);
|
|
183
|
+
for (let i = 0; i < slice.length; i++) {
|
|
184
|
+
results[start + i] = vecs[i];
|
|
185
|
+
}
|
|
186
|
+
options.onProgress?.(Math.min(start + batchSize, texts.length), texts.length);
|
|
187
|
+
}
|
|
188
|
+
return results;
|
|
189
|
+
}
|
|
121
190
|
if (!GEMINI_API_KEY)
|
|
122
191
|
throw new Error("GEMINI_API_KEY not set");
|
|
123
192
|
const batchSize = Math.max(1, Math.min(options.batchSize ?? 50, 100));
|
|
@@ -192,9 +261,11 @@ export async function embedBatch(texts) {
|
|
|
192
261
|
*/
|
|
193
262
|
export function ensureVecTable(db) {
|
|
194
263
|
loadVecSafe(db);
|
|
264
|
+
// Use activeEmbeddingDim() so the vec0 column dimension matches the active provider.
|
|
265
|
+
// For the default Gemini path this resolves to EMBEDDING_DIM (3072) — no behaviour change.
|
|
195
266
|
db.exec(`
|
|
196
267
|
CREATE VIRTUAL TABLE IF NOT EXISTS vec_chunks USING vec0(
|
|
197
|
-
embedding FLOAT[${
|
|
268
|
+
embedding FLOAT[${activeEmbeddingDim()}]
|
|
198
269
|
);
|
|
199
270
|
CREATE TABLE IF NOT EXISTS vec_chunk_map (
|
|
200
271
|
vec_rowid INTEGER PRIMARY KEY,
|
package/dist/reflect.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* reflect.ts — Deep KG synthesis: gather evidence + synthesize
|
|
2
|
+
* reflect.ts — Deep KG synthesis: gather evidence + synthesize via LLM provider
|
|
3
|
+
*
|
|
4
|
+
* Provider selection: NOX_LLM_PROVIDER env (default 'gemini').
|
|
5
|
+
* Model override: NOX_LLM_MODEL env (default 'gemini-2.5-flash-lite' per CLAUDE.md regra #3).
|
|
6
|
+
* Fallback chain: NOX_LLM_FALLBACK env (handled transparently by selectLLMProviderWithFallback).
|
|
3
7
|
*/
|
|
4
8
|
import { getDb } from "./db.js";
|
|
5
9
|
import { search, searchHybrid } from "./search.js";
|
|
6
10
|
import { queryEntity, listDecisions } from "./knowledge-graph.js";
|
|
7
11
|
import { findPath } from "./cross-agent-v2.js";
|
|
8
12
|
import { embedText } from "./embed.js";
|
|
9
|
-
|
|
10
|
-
const GEMINI_MODEL = "gemini-2.5-flash-lite";
|
|
11
|
-
const API_BASE = "https://generativelanguage.googleapis.com/v1beta";
|
|
13
|
+
import { selectLLMProviderWithFallback, MissingKeyError } from "./providers/index.js";
|
|
12
14
|
const MAX_EVIDENCE_CHARS = 2000;
|
|
13
15
|
const CACHE_TTL_HOURS = 24;
|
|
14
16
|
// E11 (2026-05-03): semantic key cache
|
|
@@ -173,9 +175,6 @@ function formatEvidence(evidence) {
|
|
|
173
175
|
return result;
|
|
174
176
|
}
|
|
175
177
|
async function synthesize(question, evidence) {
|
|
176
|
-
if (!GEMINI_API_KEY)
|
|
177
|
-
return "[reflect error: GEMINI_API_KEY not set]";
|
|
178
|
-
const url = `${API_BASE}/models/${GEMINI_MODEL}:generateContent?key=${GEMINI_API_KEY}`;
|
|
179
178
|
const prompt = `You are a memory synthesis agent. Given the evidence below, answer the question concisely.
|
|
180
179
|
Cite sources when possible. If the evidence is insufficient, say so.
|
|
181
180
|
Answer in the same language as the question. Max 500 characters.
|
|
@@ -186,20 +185,22 @@ EVIDENCE:
|
|
|
186
185
|
${evidence}
|
|
187
186
|
|
|
188
187
|
SYNTHESIZED ANSWER:`;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
188
|
+
try {
|
|
189
|
+
const llm = selectLLMProviderWithFallback();
|
|
190
|
+
const result = await llm.complete({
|
|
191
|
+
user: prompt,
|
|
192
|
+
maxTokens: 256,
|
|
193
|
+
temperature: 0.3,
|
|
194
|
+
});
|
|
195
|
+
return result.text.trim() || "[reflect: empty response]";
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
if (err instanceof MissingKeyError) {
|
|
199
|
+
return `[reflect error: ${err.message}]`;
|
|
200
|
+
}
|
|
201
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
202
|
+
return `[reflect error: ${msg.substring(0, 150)}]`;
|
|
200
203
|
}
|
|
201
|
-
const data = await resp.json();
|
|
202
|
-
return data?.candidates?.[0]?.content?.parts?.[0]?.text?.trim() || "[reflect: empty response]";
|
|
203
204
|
}
|
|
204
205
|
export async function reflect(question, options = {}) {
|
|
205
206
|
ensureReflectCache();
|
|
@@ -267,7 +268,7 @@ export async function reflect(question, options = {}) {
|
|
|
267
268
|
ON CONFLICT(query_hash) DO UPDATE SET
|
|
268
269
|
response=excluded.response, evidence_sources=excluded.evidence_sources,
|
|
269
270
|
model=excluded.model, ttl_hours=excluded.ttl_hours, created_at=datetime('now')
|
|
270
|
-
`).run(qHash, question, answer, JSON.stringify(sources),
|
|
271
|
+
`).run(qHash, question, answer, JSON.stringify(sources), process.env.NOX_LLM_MODEL ?? "gemini-2.5-flash-lite", CACHE_TTL_HOURS);
|
|
271
272
|
// CODE-FIX MEDIUM: embedding capture deferred (don't block user response)
|
|
272
273
|
if (SEMANTIC_CACHE_ENABLED) {
|
|
273
274
|
embedText(question).then((emb) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nox-mem",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
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",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@google-cloud/documentai": "^9.6.1",
|
|
57
|
-
"@xenova/transformers": "^2.
|
|
57
|
+
"@xenova/transformers": "^2.0.1",
|
|
58
58
|
"better-sqlite3": "^11.0.0",
|
|
59
59
|
"commander": "^12.0.0",
|
|
60
60
|
"sqlite-vec": "^0.1.10-alpha.1"
|