agentdb 3.1.0 → 3.2.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 +13 -0
- package/dist/src/controllers/ReflexionMemory.d.ts +20 -0
- package/dist/src/controllers/ReflexionMemory.d.ts.map +1 -1
- package/dist/src/controllers/ReflexionMemory.js +83 -5
- package/dist/src/controllers/ReflexionMemory.js.map +1 -1
- package/dist/src/controllers/episode-hybrid.d.ts +63 -0
- package/dist/src/controllers/episode-hybrid.d.ts.map +1 -0
- package/dist/src/controllers/episode-hybrid.js +117 -0
- package/dist/src/controllers/episode-hybrid.js.map +1 -0
- package/dist/src/mcp/agentdb-mcp-server.js +6 -2
- package/dist/src/mcp/agentdb-mcp-server.js.map +1 -1
- package/dist/src/search/conversation-retrieval.d.ts +56 -0
- package/dist/src/search/conversation-retrieval.d.ts.map +1 -0
- package/dist/src/search/conversation-retrieval.js +161 -0
- package/dist/src/search/conversation-retrieval.js.map +1 -0
- package/dist/src/search/cross-encoder.d.ts +17 -0
- package/dist/src/search/cross-encoder.d.ts.map +1 -0
- package/dist/src/search/cross-encoder.js +52 -0
- package/dist/src/search/cross-encoder.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in cross-encoder reranking (ADR-016). A cross-encoder reads the query and a candidate together, so it ranks
|
|
3
|
+
* far better than either embedding similarity or BM25, at about 200 ms per 60 candidates on CPU for the default
|
|
4
|
+
* 22M-parameter model (q8). It is therefore applied only to a bounded candidate set, and only when a caller asks.
|
|
5
|
+
*
|
|
6
|
+
* The model is downloaded once by @huggingface/transformers. Every input is bounded: at most MAX_CANDIDATES
|
|
7
|
+
* candidates, each cut to MAX_CHARS before tokenising, and the tokenizer truncates pairs at 512 tokens.
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_RERANKER = process.env.AGENTDB_RERANKER_MODEL || 'Xenova/ms-marco-MiniLM-L-6-v2';
|
|
10
|
+
/** Two candidate lists of RERANK_DEPTH (60) each, deduplicated, fit. */
|
|
11
|
+
export const MAX_CANDIDATES = 128;
|
|
12
|
+
const MAX_CHARS = 4_096;
|
|
13
|
+
const BATCH = 32;
|
|
14
|
+
const loading = new Map();
|
|
15
|
+
async function load(modelId) {
|
|
16
|
+
let p = loading.get(modelId);
|
|
17
|
+
if (!p) {
|
|
18
|
+
p = (async () => {
|
|
19
|
+
const t = await import('@huggingface/transformers');
|
|
20
|
+
const tokenizer = await t.AutoTokenizer.from_pretrained(modelId);
|
|
21
|
+
const model = await t.AutoModelForSequenceClassification.from_pretrained(modelId, { dtype: 'q8' });
|
|
22
|
+
return { tokenizer: tokenizer, model: model };
|
|
23
|
+
})();
|
|
24
|
+
// A failed load is not cached, so a later call can retry (e.g. after the network returns).
|
|
25
|
+
p.catch(() => loading.delete(modelId));
|
|
26
|
+
loading.set(modelId, p);
|
|
27
|
+
}
|
|
28
|
+
return p;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Relevance logits of each candidate for the query, in input order. Throws if the model cannot be loaded;
|
|
32
|
+
* callers fall back to their unreranked order.
|
|
33
|
+
*/
|
|
34
|
+
export async function crossEncoderScores(query, candidates, modelId = DEFAULT_RERANKER) {
|
|
35
|
+
if (candidates.length > MAX_CANDIDATES)
|
|
36
|
+
throw new RangeError(`at most ${MAX_CANDIDATES} candidates`);
|
|
37
|
+
const out = new Float64Array(candidates.length);
|
|
38
|
+
if (candidates.length === 0)
|
|
39
|
+
return out;
|
|
40
|
+
const { tokenizer, model } = await load(modelId);
|
|
41
|
+
const q = query.slice(0, MAX_CHARS);
|
|
42
|
+
for (let i = 0; i < candidates.length; i += BATCH) {
|
|
43
|
+
const docs = candidates.slice(i, i + BATCH).map(d => d.slice(0, MAX_CHARS));
|
|
44
|
+
const enc = tokenizer(new Array(docs.length).fill(q), { text_pair: docs, padding: true, truncation: true, max_length: 512 });
|
|
45
|
+
const { logits } = await model(enc);
|
|
46
|
+
const width = logits.dims[1] ?? 1;
|
|
47
|
+
for (let j = 0; j < docs.length; j++)
|
|
48
|
+
out[i + j] = Number(logits.data[j * width + (width - 1)]);
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=cross-encoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-encoder.js","sourceRoot":"","sources":["../../../src/search/cross-encoder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,+BAA+B,CAAC;AACtG,wEAAwE;AACxE,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAClC,MAAM,SAAS,GAAG,KAAK,CAAC;AACxB,MAAM,KAAK,GAAG,EAAE,CAAC;AAOjB,MAAM,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;AAEnD,KAAK,UAAU,IAAI,CAAC,OAAe;IACjC,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,IAAI,CAAC,CAAC,EAAE,CAAC;QACP,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;YACd,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAC;YACpD,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;YACjE,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,kCAAkC,CAAC,eAAe,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACnG,OAAO,EAAE,SAAS,EAAE,SAA2C,EAAE,KAAK,EAAE,KAAmC,EAAE,CAAC;QAChH,CAAC,CAAC,EAAE,CAAC;QACL,2FAA2F;QAC3F,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAA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CAAC,CAAC;QACpC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE;YAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentdb",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Self-learning vector memory for AI agents — single-file .rvf cognitive container with HNSW search, episodic Reflexion memory, causal graph + Cypher, 9 RL algorithms, Thompson Sampling bandit, 41 MCP tools, hybrid (BM25 + dense) retrieval, GNN attention. 150x faster than SQLite. Up to +36% search quality from feedback. Runs in Node, browsers (WASM), edge, offline. Backs the agentic-flow / ruflo / Claude Code memory layer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -210,7 +210,7 @@
|
|
|
210
210
|
"commander": "^12.1.0",
|
|
211
211
|
"hnswlib-node": "^3.0.0",
|
|
212
212
|
"inquirer": "^9.3.8",
|
|
213
|
-
"ruvector": "^0.
|
|
213
|
+
"ruvector": "^0.3.5",
|
|
214
214
|
"ruvector-attention-wasm": "^0.1.32",
|
|
215
215
|
"ruvector-graph-transformer-wasm": "^2.0.4"
|
|
216
216
|
},
|