Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

feat(memory): hybrid recall — `hybrid: true` fuses BM25 and semantic inside /_memory/_recall (#918)

xerj-org086317db6772
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d2f5b72de..16a4a91c7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Added
+
+- **`hybrid: true` in `POST /_memory/{ns}/_recall` fuses BM25 and server-side
+ semantic recall inside the memory API**
+ ([#918](https://github.com/xerj-org/xerj/issues/918)). Recall used to pick
+ exactly one mode — `vector`, `semantic: true`, or plain `query` — so an agent
+ that wanted fused recall over a namespace had to bypass `/_memory` and issue
+ a raw `hybrid` `_search` against the backing index, losing the memory hit
+ shape, the `recency_weight` blend, the graph coupling and the namespace
+ authorization path. `hybrid: true` now runs the BM25 leg and the semantic
+ leg over the same `query` as the two legs of the engine's `hybrid` query
+ (reciprocal rank fusion, `fusion: "linear"` opt-in), each leg keeping the
+ filter shape it dispatches with and fetching the same over-fetch width the
+ re-rankers already use. Off by default; `vector` or `semantic: true` beside
+ it, `fusion` without it, and `fusion: "learned"` are 400s, so a request
+ never silently degrades to one leg. The MCP `xerj_memory_recall` tool
+ exposes the same two parameters. Raised by @Vinz2168 from a shared-memory
+ agent integration where neither single mode was enough.
+
## [1.0.0-rc.74] - 2026-09-08
### Added
diff --git a/content/answers/coding-agent-memory-across-sessions.md b/content/answers/coding-agent-memory-across-sessions.md
index 8122de6f9..b550ed7ae 100644
--- a/content/answers/coding-agent-memory-across-sessions.md
+++ b/content/answers/coding-agent-memory-across-sessions.md
@@ -37,7 +37,7 @@ faq:
- q: "How do I delete one memory?"
a: "Send `DELETE /_memory/{namespace}/{id}`. Our capture got `{\"forgotten\": true}` and the next recall returned only the remaining memory."
- q: "Does recall use vectors?"
- a: "Only if you ask. Plain `query` runs BM25, `semantic: true` embeds server-side, and a supplied `vector` runs pure kNN. There is no fusion in `_recall`."
+ a: "Only if you ask. Plain `query` runs BM25, `semantic: true` embeds server-side, and a supplied `vector` runs pure kNN. `hybrid: true` runs the BM25 and the server-side semantic leg over the same `query` and fuses them by reciprocal rank inside `_recall`; it is off unless you set it."
---
**TL;DR** — XERJ stores each memory as an ordinary document in a reserved index named `.xerj-memory-{namespace}`. Our capture stored two memories, stopped the node, started it again against the same data directory, and recalled both by id. One forget call by id removed exactly that memory.
@@ -65,9 +65,9 @@ Durability comes from the storage layer, not from a memory subsystem. Each memor
## What recall actually runs
-Recall picks one mode in strict order and never blends them. A supplied `vector` runs pure kNN, `semantic: true` embeds the query on the server, and a plain `query` runs `{"match":{"text":q}}`, which is BM25.
+Recall picks one mode in strict order and does not blend them unless you ask. A supplied `vector` runs pure kNN, `semantic: true` embeds the query on the server, and a plain `query` runs `{"match":{"text":q}}`, which is BM25.
-There is no fusion in `_recall`. To fuse BM25 and kNN, use the `hybrid` query type on an ordinary index instead.
+Fusion is opt-in. `hybrid: true` runs the BM25 leg and the server-side semantic leg over the same `query` and fuses the two rankings by reciprocal rank (`fusion: "linear"` sums min-max-normalised scores instead). A `filter` narrows both legs, and `recency_weight` re-ranks the fused pool exactly as it does for a single mode. Sending `vector` or `semantic: true` beside `hybrid: true` is a 400, so a request never silently falls back to one leg.
The two modes disagree on our fixture, which is the point of naming them. The plain query put the deploy memory first at 1.4581499. The same question with `semantic: true` put the latency memory first at 0.627885, because the default embedder is lexical feature hashing rather than a neural model.
diff --git a/content/answers/store-agent-memory-without-llm-call.md b/content/answers/store-agent-memory-without-llm-call.md
index 33733e183..cf0cfaa28 100644
--- a/content/answers/store-agent-memory-without-llm-call.md
+++ b/content/answers/store-agent-memory-without-llm-call.md
@@ -82,7 +82,7 @@ Read that number as written. The harness sampled a loopback-bound node rather th
## Which recall mode invokes an embedder
-Recall chooses exactly one mode, in a strict order, and never blends them. There is no fusion in `_recall`.
+Recall chooses exactly one mode, in a strict order, unless you set `hybrid: true`. That mode runs the BM25 leg and the server-side semantic leg over the same `query` and fuses them by reciprocal rank. It is the only fusion in `_recall`, and it is off by default.
| request field | what runs | embedder involved |
| --- | --- | --- |
diff --git a/docs/recipes/agentic-memory.md b/docs/recipes/agentic-memory.md
index e0ec81321..5fe821ce1 100644
--- a/docs/recipes/agentic-memory.md
+++ b/docs/recipes/agentic-memory.md
@@ -45,13 +45,17 @@ paths that serve the rest of the engine. That means:
| Verb + path | What it does | Body / result |
|---|---|---|
| `POST /_memory/{ns}` | store a memory | `{text, vector?, metadata?, id?}` → `{id, namespace, created}` |
-| `POST /_memory/{ns}/_recall` | recall top-k | `{vector? \| query?, k?, filter?}` → `{hits:[{id,text,metadata,score}]}` |
+| `POST /_memory/{ns}/_recall` | recall top-k | `{vector? \| query?, semantic?, hybrid?, fusion?, k?, filter?, recency_weight?}` → `{hits:[{id,text,metadata,score}]}` |
| `GET /_memory/{ns}` | list recent (bounded) | → `{count, entries:[…]}` |
| `DELETE /_memory/{ns}/{id}` | forget one | → `{id, forgotten}` |
| `DELETE /_memory/{ns}` | drop the namespace | → `{namespace, dropped}` |
-`_recall` picks the path from the body: a `vector` runs kNN; otherwise `query`
-runs BM25 over the text; an empty body returns recent memories (`match_all`).
+`_recall` picks the path from the body: a `vector` runs kNN; `semantic: true`
+embeds `query` on the server and runs kNN; otherwise `query` runs BM25 over the
+text. `hybrid: true` runs the BM25 and the server-side semantic leg over the same
+`query` and fuses them by reciprocal rank (`fusion: "linear"` for a normalised
+score sum) — the `hybrid` query type without leaving `/_memory`. It is off by
+default, and `vector` or `semantic: true` beside it is a 400.
`filter` is a normal ES query clause applied as a `bool` filter, so it narrows
without affecting the score. Recall of an unknown namespace returns `{"hits": []}` —
that is how isolation stays clean.
diff --git a/engine/crates/xerj-api/src/memory_api.rs b/engine/crates/xerj-api/src/memory_api.rs
index 4505e8809..b5f81d11c 100644
--- a/engine/crates/xerj-api/src/memory_api.rs
+++ b/engine/crates/xerj-api/src/memory_api.rs
@@ -9,7 +9,7 @@
//! Endpoints (mounted on the ES-compat router):
//! ```text
//! POST /_memory/{namespace} store — {text, metadata?, vector?, id?, dedup?, dedup_threshold?} → {id, created} | {id, created:false, deduplicated:true}
-//! POST /_memory/{namespace}/_recall recall — {query?, vector?, semantic?, k?, filter?, recency_weight?} → {hits:[…]}
+//! POST /_memory/{namespace}/_recall recall — {query?, vector?, semantic?, hybrid?, fusion?, k?, filter?, recency_weight?} → {hits:[…]}
//! GET /_memory/{namespace}?from&size list — {count, entries:[…], next} (paged, recent first)
//! DELETE /_memory/{namespace}/{id} forget — delete one entry
//! DELETE /_memory/{namespace} drop — drop the whole namespace
@@ -38,13 +38,18 @@
//! access control depends on the deferred RBAC enforcement (see
//! `xerj_engine::rbac`).
//!
-//! Recall has three modes, tried in order: an explicit query `vector` (kNN over
-//! a caller-supplied embedding) → `semantic: true` (the server embeds `query`
-//! with the same embedder used at store time and recalls by vector similarity)
-//! → plain `query` text (BM25 relevance). All three are offline-testable with
-//! NO external embedding service — memories are stored in a `semantic_text`
-//! field, so the built-in deterministic embedder vectorises both the stored
-//! text and the recall query. Namespaces isolate — a recall in namespace A
+//! Recall has three single modes, tried in order: an explicit query `vector`
+//! (kNN over a caller-supplied embedding) → `semantic: true` (the server embeds
+//! `query` with the same embedder used at store time and recalls by vector
+//! similarity) → plain `query` text (BM25 relevance). `hybrid: true` (#918) is
+//! the opt-in fourth: the BM25 and the server-side semantic leg run over the
+//! same `query` and are fused by the engine's `hybrid` query type (reciprocal
+//! rank fusion by default, `fusion: "linear"` on request), so an agent gets
+//! fused recall without leaving `/_memory` for a raw `_search` on the backing
+//! index. All of them are offline-testable with NO external embedding service
+//! — memories are stored in a `semantic_text` field, so the built-in
+//! deterministic embedder vectorises both the stored text and the recall
+//! query. Namespaces isolate — a recall in namespace A
//! never sees namespace B's entries because they live in physically distinct
//! backing indices.
@@ -455,6 +460,20 @@ pub struct RecallBody {
/// BM25 text-relevance recall. Ignored when an explicit `vector` is given.
#[serde(default)]
pub semantic: Option<bool>,
+ /// When `true`, run BM25 and server-side semantic recall over `query`
+ /// together and fuse the two rankings — the engine's `hybrid` query type
+ /// lifted into `_recall` (#918). Requires a non-empty `query`; a
+ /// caller-supplied `vector` or `semantic: true` beside it is a 400, so a
+ /// request never silently picks one leg. Default (`false`/absent) keeps
+ /// the single-mode behaviour bit-for-bit.
+ #[serde(default)]
+ pub hybrid: Option<bool>,
+ /// Fusion strategy for `hybrid: true`: `"rrf"` (default; reciprocal rank
+ /// fusion, k=60) or `"linear"` (min-max-normalised score sum). Anything
+ /// else — including `"learned"`, which the engine does not implement — is
+ /// a 400. Only meaningful with `hybrid: true`; a 400 otherwise.
+ #[serde(default)]
+ pub fusion: Option<String>,
/// Number of memories to return. Defaults to 10.
#[serde(default)]
pub k: Option<usize>,
@@ -567,6 +586,49 @@ pub async fn recall(
"`vector` must be a non-empty array of numbers",
);
}
+ // Hybrid recall (#918) fuses the two `query`-driven legs; it cannot take a
+ // caller-supplied `vector` (nothing lexical to fuse it with) and it already
+ // contains the semantic leg, so both combinations are refused rather than
+ // silently resolved to one mode.
+ let hybrid = body.hybrid == Some(true);
+ if hybrid && body.vector.is_some() {
+ return error_response(
+ StatusCode::BAD_REQUEST,
+ "hybrid recall fuses BM25 and server-side semantic recall over \
+ `query`; it cannot take a caller-supplied `vector`",
+ );
+ }
+ if hybrid && body.semantic == Some(true) {
+ return error_response(
+ StatusCode::BAD_REQUEST,
+ "`hybrid: true` already runs the semantic leg; drop `semantic`",
+ );
+ }
+ let fusion = match body.fusion.as_deref() {
+ None => "rrf",
+ Some(_) if !hybrid => {
+ return error_response(
+ StatusCode::BAD_REQUEST,
+ "`fusion` only applies with `hybrid: true`",
+ );
+ }
+ Some("rrf") => "rrf",
+ Some("linear") => "linear",
+ // Mirror the `hybrid` query type: learned fusion is not implemented,
+ // and substituting RRF would misrepresent the ranking asked for.
+ Some("learned") => {
+ return error_response(
+ StatusCode::BAD_REQUEST,
+ "hybrid fusion learned is not yet supported; use rrf or linear",
+ );
+ }
+ Some(other) => {
+ return error_response(
+ StatusCode::BAD_REQUEST,
+ format!("unknown hybrid fusion strategy `{other}`; use rrf or linear"),
+ );
+ }
+ };
let k = body.k.unwrap_or(DEFAULT_K).max(1);
// Recency blending needs a wider candidate pool than the final k so the
// re-rank can actually promote recent-but-slightly-less-relevant memories.
@@ -680,8 +742,37 @@ pub async fn recall(
search_body.knn = Some(knn);
}
}
+ } else if hybrid {
+ // (2) Hybrid recall (#918): BM25 and server-side semantic recall over
+ // the same `query`, run as the two legs of the engine's `hybrid` query
+ // and fused by rank (RRF, k=60) or by min-max-normalised score
+ // (`linear`). Each leg keeps the filter shape its single-mode
+ // counterpart uses: the BM25 leg wraps in `bool.must` + `bool.filter`,
+ // the semantic leg carries `filter` inside the `semantic` node —
+ // a `semantic` clause nested under a `bool` is not dispatched to the
+ // vector path (#395), whereas `hybrid.queries` are dispatched leg by
+ // leg (`dispatching_vector_fields`). Both legs fetch `fetch` (the
+ // recency/graph over-fetch width, not the caller's `k`), so the fused
+ // pool the re-rankers see is as deep as it is in single mode.
+ let q = body.query.as_deref().unwrap_or_default(); // validated non-empty above
+ let lexical = match &filter_opt {
+ Some(filter) => json!({
+ "bool": { "must": [ { "match": { "text": q } } ], "filter": [ filter ] }
+ }),
+ None => json!({ "match": { "text": q } }),
+ };
+ let mut semantic = json!({ "field": "text", "query": q, "k": fetch });
+ if let Some(filter) = filter_opt {
+ semantic["filter"] = filter;
+ }
+ search_body.query = Some(json!({
+ "hybrid": {
+ "queries": [ { "query": lexical }, { "query": { "semantic": semantic } } ],
+ "fusion": fusion
+ }
+ }));
} else if body.semantic == Some(true) {
- // (2) Server-side semantic recall: embed `query` with the same embedder
+ // (3) Server-side semantic recall: embed `query` with the same embedder
// used at store time (via the `semantic` query over the `text`
// semantic_text field) and recall by vector similarity. No client-side
// embedding required.
@@ -704,7 +795,7 @@ pub async fn recall(
}
search_body.query = Some(json!({ "semantic": semantic }));
} else {
- // (3) Text recall (BM25). Empty/absent query → match_all (recent memories).
+ // (4) Text recall (BM25). Empty/absent query → match_all (recent memories).
let inner = match body.query.as_deref() {
Some(q) if !q.is_empty() => json!({ "match": { "text": q } }),
_ => json!({ "match_all": {} }),
@@ -1549,6 +1640,184 @@ mod tests {
);
}
+ /// #918: `hybrid: true` runs the BM25 leg and the server-side semantic
+ /// leg over the same `query` and fuses them inside `_recall` — no raw
+ /// `_search` on the backing index. Memories are stored text-only (the
+ /// `semantic_text` field auto-embeds them), exactly as for `semantic`.
+ #[tokio::test]
+ async fn store_recall_hybrid_fuses_lexical_and_semantic() {
+ let state = test_state();
+ for (id, text) in [
+ (
+ "i1",
+ "host 1.2.3.4 brute forced ssh with hundreds of failed passwords",
+ ),
+ ("i2", "nightly database backup completed without errors"),
+ (
+ "i3",
+ "repeated ssh authentication failures from an unknown attacker",
+ ),
+ ] {
+ let (s, _) = store_mem(&state, "soc", json!({"text": text, "id": id})).await;
+ assert_eq!(s, StatusCode::CREATED);
+ }
+
+ let (s, body) = recall_mem(
+ &state,
+ "soc",
+ json!({"query": "ssh brute force attack", "hybrid": true, "k": 2}),
+ )
+ .await;
+ assert_eq!(s, StatusCode::OK, "{body}");
+ let hits = body["hits"].as_array().unwrap();
+ assert_eq!(hits.len(), 2, "hybrid k=2 → exactly 2 hits");
+ let ids: Vec<&str> = hits.iter().map(|h| h["id"].as_str().unwrap()).collect();
+ assert!(
+ ids.contains(&"i1") && ids.contains(&"i3"),
+ "both ssh incidents must surface, got {ids:?}"
+ );
+ assert!(
+ !ids.contains(&"i2"),
+ "the backup note must not, got {ids:?}"
+ );
+ // Teeth: the scores are reciprocal-rank-fusion sums, not BM25 or
+ // cosine. With k=60 and two legs a document contributes at most
+ // 1/61 per leg, so no fused score can exceed 2/61 — a BM25 or
+ // cosine score for this query would be well above that.
+ for h in hits {
+ let score = h["score"].as_f64().unwrap();
+ assert!(
+ score > 0.0 && score <= 2.0 / 61.0 + 1e-6,
+ "hybrid recall must return RRF-fused scores, got {score}"
+ );
+ }
+ // The top memory is within the top-2 of BOTH legs, so its fused score
+ // is at least 1/61 + 1/62 — a single-leg document never exceeds 1/61.
+ let top = hits[0]["score"].as_f64().unwrap();
+ assert!(
+ top >= 1.0 / 61.0 + 1.0 / 62.0 - 1e-6,
+ "the top memory must be fused from both legs, got {top}"
+ );
+
+ // `fusion: "linear"` is the other supported combiner: each leg is
+ // min-max-normalised to [0, 1] and summed, so the top hit scores 2.0
+ // when both legs agree on it and 1.0 when they disagree — either way
+ // it is >= 1.0, which no RRF sum can reach.
+ let (s, body) = recall_mem(
+ &state,
+ "soc",
+ json!({"query": "ssh brute force attack", "hybrid": true, "fusion": "linear", "k": 2}),
+ )
+ .await;
+ assert_eq!(s, StatusCode::OK, "{body}");
+ let hits = body["hits"].as_array().unwrap();
+ assert_eq!(hits.len(), 2);
+ let top = hits[0]["score"].as_f64().unwrap();
+ assert!(
+ (1.0 - 1e-6..=2.0 + 1e-6).contains(&top),
+ "linear fusion sums normalised leg scores, got {top}"
+ );
+
+ // A metadata filter narrows BOTH legs (it is applied per leg, in the
+ // shape each leg dispatches with).
+ store_mem(
+ &state,
+ "soc",
+ json!({"text":"ssh attack from host 9.9.9.9","id":"i4","metadata":{"sev":"high"}}),
+ )
+ .await;
+ let (s, body) = recall_mem(
+ &state,
+ "soc",
+ json!({"query":"ssh attack","hybrid":true,"k":10,"filter":{"term":{"metadata.sev":"high"}}}),
+ )
+ .await;
+ assert_eq!(s, StatusCode::OK, "{body}");
+ let hits = body["hits"].as_array().unwrap();
+ assert!(
+ !hits.is_empty(),
+ "filtered hybrid recall returns the high-sev memory"
+ );
+ assert!(
+ hits.iter().all(|h| h["id"] == "i4"),
+ "only the high-sev memory passes the filter on both legs"
+ );
+
+ // Composes with the recency re-rank (over-fetch + blend + truncate).
+ let (s, body) = recall_mem(
+ &state,
+ "soc",
+ json!({"query":"ssh brute force attack","hybrid":true,"k":2,"recency_weight":0.5}),
+ )
+ .await;
+ assert_eq!(s, StatusCode::OK, "{body}");
+ assert_eq!(body["hits"].as_array().unwrap().len(), 2);
+ }
+
+ /// #918: hybrid recall keeps the fail-loud contract — every ambiguous or
+ /// unsupported combination is a 400 with a specific reason, never a
+ /// silent fallback to one leg.
+ #[tokio::test]
+ async fn recall_hybrid_rejects_ambiguous_requests() {
+ let state = test_state();
+ store_mem(
+ &state,
+ "soc",
+ json!({"text": "ssh brute force", "id": "i1"}),
+ )
+ .await;
+
+ let cases: [(Value, &str); 6] = [
+ (json!({"hybrid": true}), "hybrid without a query"),
+ (
+ json!({"query": "", "hybrid": true}),
+ "hybrid with an empty query",
+ ),
+ (
+ json!({"vector": [1.0, 0.0, 0.0], "hybrid": true}),
+ "hybrid with a caller-supplied vector",
+ ),
+ (
+ json!({"query": "ssh", "semantic": true, "hybrid": true}),
+ "hybrid beside semantic",
+ ),
+ (
+ json!({"query": "ssh", "fusion": "rrf"}),
+ "fusion without hybrid",
+ ),
+ (
+ json!({"query": "ssh", "hybrid": true, "fusion": "learned"}),
+ "learned fusion",
+ ),
+ ];
+ for (body, what) in cases {
+ let (s, resp) = recall_mem(&state, "soc", body).await;
+ assert_eq!(
+ s,
+ StatusCode::BAD_REQUEST,
+ "{what} must be a 400, got {resp}"
+ );
+ }
+ let (s, resp) = recall_mem(
+ &state,
+ "soc",
+ json!({"query": "ssh", "hybrid": true, "fusion": "bogus"}),
+ )
+ .await;
+ assert_eq!(s, StatusCode::BAD_REQUEST);
+ assert!(
+ resp.to_string()
+ .contains("unknown hybrid fusion strategy `bogus`"),
+ "{resp}"
+ );
+
+ // `hybrid: false` is the documented default — plain BM25, byte-identical.
+ let (s, off) = recall_mem(&state, "soc", json!({"query": "ssh", "hybrid": false})).await;
+ assert_eq!(s, StatusCode::OK);
+ let (_, plain) = recall_mem(&state, "soc", json!({"query": "ssh"})).await;
+ assert_eq!(off, plain, "hybrid:false must not change the BM25 path");
+ }
+
async fn count_of(state: &AppState, ns: &str) -> u64 {
let resp = list(
State(state.clone()),
diff --git a/engine/crates/xerj-mcp/src/lib.rs b/engine/crates/xerj-mcp/src/lib.rs
index ca45cf551..28c042141 100644
--- a/engine/crates/xerj-mcp/src/lib.rs
+++ b/engine/crates/xerj-mcp/src/lib.rs
@@ -517,7 +517,8 @@ pub fn tool_specs() -> Value {
"description":
"Recall the most relevant memories from a namespace. Default is BM25 text \
recall; set `semantic:true` to embed the query server-side and recall by \
- meaning; supply `vector` for pure vector recall. Proxies \
+ meaning; set `hybrid:true` to run both over the same `query` and fuse them \
+ by reciprocal rank; supply `vector` for pure vector recall. Proxies \
POST /_memory/{namespace}/_recall.",
"inputSchema": {
"type": "object",
@@ -525,6 +526,18 @@ pub fn tool_specs() -> Value {
"namespace": { "type": "string" },
"query": { "type": "string", "description": "Query text (BM25, or embedded when semantic:true)." },
"semantic": { "type": "boolean", "description": "Embed `query` server-side and recall by meaning." },
+ "hybrid": {
+ "type": "boolean",
+ "description":
+ "Run BM25 and server-side semantic recall over `query` and fuse the \
+ two rankings (reciprocal rank fusion). Off by default; cannot be \
+ combined with `vector` or `semantic`."
+ },
+ "fusion": {
+ "type": "string",
+ "enum": ["rrf", "linear"],
+ "description": "Fusion for hybrid:true — `rrf` (default) or `linear`."
+ },
"vector": {
"type": "array",
"items": { "type": "number" },
@@ -965,6 +978,8 @@ fn build_memory_recall(args: &Value) -> Result<BuiltRequest, String> {
"query",
"vector",
"semantic",
+ "hybrid",
+ "fusion",
"k",
"filter",
"recency_weight",
diff --git a/landing/answers/coding-agent-memory-across-sessions.html b/landing/answers/coding-agent-memory-across-sessions.html
index 1ccf02b2e..ab7854841 100644
--- a/landing/answers/coding-agent-memory-across-sessions.html
+++ b/landing/answers/coding-agent-memory-across-sessions.html
@@ -268,8 +268,8 @@
</table>
<p>Durability comes from the storage layer, not from a memory subsystem. Each memory is an ordinary document, and our capture found the backing directory <code class="inline">.xerj-memory-agentmem</code> at the top level of the node data directory.</p>
<h2>What recall actually runs</h2>
- <p>Recall picks one mode in strict order and never blends them. A supplied <code class="inline">vector</code> runs pure kNN, <code class="inline">semantic: true</code> embeds the query on the server, and a plain <code class="inline">query</code> runs <code class="inline">{"match":{"text":q}}</code>, which is BM25.</p>
- <p>There is no fusion in <code class="inline">_recall</code>. To fuse BM25 and kNN, use the <code class="inline">hybrid</code> query type on an ordinary index instead.</p>
+ <p>Recall picks one mode in strict order and does not blend them unless you ask. A supplied <code class="inline">vector</code> runs pure kNN, <code class="inline">semantic: true</code> embeds the query on the server, and a plain <code class="inline">query</code> runs <code class="inline">{"match":{"text":q}}</code>, which is BM25.</p>
+ <p>Fusion is opt-in. <code class="inline">hybrid: true</code> runs the BM25 leg and the server-side semantic leg over the same <code class="inline">query</code> and fuses the two rankings by reciprocal rank (<code class="inline">fusion: "linear"</code> sums min-max-normalised scores instead). A <code class="inline">filter</code> narrows both legs, and <code class="inline">recency_weight</code> re-ranks the fused pool exactly as it does for a single mode. Sending <code class="inline">vector</code> or <code class="inline">semantic: true</code> beside <code class="inline">hybrid: true</code> is a 400, so a request never silently falls back to one leg.</p>
<p>The two modes disagree on our fixture, which is the point of naming them. The plain query put the deploy memory first at 1.4581499. The same question with <code class="inline">semantic: true</code> put the latency memory first at 0.627885, because the default embedder is lexical feature hashing rather than a neural model.</p>
<h2>A misspelled key fails loudly</h2>
<p>Recall uses strict field parsing, so an unknown key is a hard 400 rather than a silent match-all at score 1.0. The strictness matters for an agent that trusts whatever recall hands back.</p>
@@ -303,7 +303,7 @@
<h3>How do I delete one memory?</h3>
<p>Send <code class="inline">DELETE /_memory/{namespace}/{id}</code>. Our capture got <code class="inline">{"forgotten": true}</code> and the next recall returned only the remaining memory.</p>
<h3>Does recall use vectors?</h3>
- <p>Only if you ask. Plain <code class="inline">query</code> runs BM25, <code class="inline">semantic: true</code> embeds server-side, and a supplied <code class="inline">vector</code> runs pure kNN. There is no fusion in <code class="inline">_recall</code>.</p>
+ <p>Only if you ask. Plain <code class="inline">query</code> runs BM25, <code class="inline">semantic: true</code> embeds server-side, and a supplied <code class="inline">vector</code> runs pure kNN. <code class="inline">hybrid: true</code> runs the BM25 and the server-side semantic leg over the same <code class="inline">query</code> and fuses them by reciprocal rank inside <code class="inline">_recall</code>; it is off unless you set it.</p>
<h2>Related</h2>
<ul>
<li><a href="/answers/agent-memory-without-postgres-qdrant">What's a simple way to give an agent long-term memory on my laptop without Qdrant?</a></li>
diff --git a/landing/answers/coding-agent-memory-across-sessions.md b/landing/answers/coding-agent-memory-across-sessions.md
index 0d653558b..bd71ac55f 100644
--- a/landing/answers/coding-agent-memory-across-sessions.md
+++ b/landing/answers/coding-agent-memory-across-sessions.md
@@ -65,9 +65,9 @@ Durability comes from the storage layer, not from a memory subsystem. Each memor
## What recall actually runs
-Recall picks one mode in strict order and never blends them. A supplied `vector` runs pure kNN, `semantic: true` embeds the query on the server, and a plain `query` runs `{"match":{"text":q}}`, which is BM25.
+Recall picks one mode in strict order and does not blend them unless you ask. A supplied `vector` runs pure kNN, `semantic: true` embeds the query on the server, and a plain `query` runs `{"match":{"text":q}}`, which is BM25.
-There is no fusion in `_recall`. To fuse BM25 and kNN, use the `hybrid` query type on an ordinary index instead.
+Fusion is opt-in. `hybrid: true` runs the BM25 leg and the server-side semantic leg over the same `query` and fuses the two rankings by reciprocal rank (`fusion: "linear"` sums min-max-normalised scores instead). A `filter` narrows both legs, and `recency_weight` re-ranks the fused pool exactly as it does for a single mode. Sending `vector` or `semantic: true` beside `hybrid: true` is a 400, so a request never silently falls back to one leg.
The two modes disagree on our fixture, which is the point of naming them. The plain query put the deploy memory first at 1.4581499. The same question with `semantic: true` put the latency memory first at 0.627885, because the default embedder is lexical feature hashing rather than a neural model.
@@ -133,7 +133,7 @@ Send `DELETE /_memory/{namespace}/{id}`. Our capture got `{"forgotten": true}` a
### Does recall use vectors?
-Only if you ask. Plain `query` runs BM25, `semantic: true` embeds server-side, and a supplied `vector` runs pure kNN. There is no fusion in `_recall`.
+Only if you ask. Plain `query` runs BM25, `semantic: true` embeds server-side, and a supplied `vector` runs pure kNN. `hybrid: true` runs the BM25 and the server-side semantic leg over the same `query` and fuses them by reciprocal rank inside `_recall`; it is off unless you set it.
## Related
diff --git a/landing/answers/store-agent-memory-without-llm-call.html b/landing/answers/store-agent-memory-without-llm-call.html
index 718d8d401..4c98b9590 100644
--- a/landing/answers/store-agent-memory-without-llm-call.html
+++ b/landing/answers/store-agent-memory-without-llm-call.html
@@ -277,7 +277,7 @@
</code></pre>
<p>Read that number as written. The harness sampled a loopback-bound node rather than denying it a network. A connection that opens and closes inside one 50 ms gap escapes the sampler.</p>
<h2>Which recall mode invokes an embedder</h2>
- <p>Recall chooses exactly one mode, in a strict order, and never blends them. There is no fusion in <code class="inline">_recall</code>.</p>
+ <p>Recall chooses exactly one mode, in a strict order, unless you set <code class="inline">hybrid: true</code>. That mode runs the BM25 leg and the server-side semantic leg over the same <code class="inline">query</code> and fuses them by reciprocal rank. It is the only fusion in <code class="inline">_recall</code>, and it is off by default.</p>
<table>
<thead><tr><th>request field</th><th>what runs</th><th>embedder involved</th></tr></thead>
<tbody>
diff --git a/landing/answers/store-agent-memory-without-llm-call.md b/landing/answers/store-agent-memory-without-llm-call.md
index 3bcad5896..39e19d4c8 100644
--- a/landing/answers/store-agent-memory-without-llm-call.md
+++ b/landing/answers/store-agent-memory-without-llm-call.md
@@ -86,7 +86,7 @@ Read that number as written. The harness sampled a loopback-bound node rather th
## Which recall mode invokes an embedder
-Recall chooses exactly one mode, in a strict order, and never blends them. There is no fusion in `_recall`.
+Recall chooses exactly one mode, in a strict order, unless you set `hybrid: true`. That mode runs the BM25 leg and the server-side semantic leg over the same `query` and fuses them by reciprocal rank. It is the only fusion in `_recall`, and it is off by default.
| request field | what runs | embedder involved |
| --- | --- | --- |
diff --git a/landing/docs/agents/schemas/mcp-tools.json b/landing/docs/agents/schemas/mcp-tools.json
index 5818d67bd..7d810cfdf 100644
--- a/landing/docs/agents/schemas/mcp-tools.json
+++ b/landing/docs/agents/schemas/mcp-tools.json
@@ -202,7 +202,7 @@
},
{
"name": "xerj_memory_recall",
- "description": "Recall the most relevant memories from a namespace. Default is BM25 text recall; set `semantic:true` to embed the query server-side and recall by meaning; supply `vector` for pure vector recall. Proxies POST /_memory/{namespace}/_recall.",
+ "description": "Recall the most relevant memories from a namespace. Default is BM25 text recall; set `semantic:true` to embed the query server-side and recall by meaning; set `hybrid:true` to run both over the same `query` and fuse them by reciprocal rank; supply `vector` for pure vector recall. Proxies POST /_memory/{namespace}/_recall.",
"inputSchema": {
"type": "object",
"properties": {
@@ -217,6 +217,18 @@
"type": "boolean",
"description": "Embed `query` server-side and recall by meaning."
},
+ "hybrid": {
+ "type": "boolean",
+ "description": "Run BM25 and server-side semantic recall over `query` and fuse the two rankings (reciprocal rank fusion). Off by default; cannot be combined with `vector` or `semantic`."
+ },
+ "fusion": {
+ "type": "string",
+ "enum": [
+ "rrf",
+ "linear"
+ ],
+ "description": "Fusion for hybrid:true — `rrf` (default) or `linear`."
+ },
"vector": {
"type": "array",
"items": {
diff --git a/landing/llms.txt b/landing/llms.txt
index 7b7d50bda..c5ab783af 100644
--- a/landing/llms.txt
+++ b/landing/llms.txt
@@ -56,7 +56,7 @@ Then, from an unknown folder to an answered question: `xerj autoindex <folder>`
- **xerj_vector_search** — kNN over a `dense_vector` field: `{"query":{"knn":{"field":"embedding","query_vector":[…],"k":10,"num_candidates":100,"filter":{…}}}}`, or the top-level `{"knn":{…}}` form. Bring your own query vector. (HNSW-served unfiltered, exact scan when filtered — see Caveats.)
- **xerj_hybrid_search** — fuse lexical + vector/semantic: `{"query":{"hybrid":{"queries":[…],"fusion":"rrf"}}}` with a `weight` per clause. `fusion` is `"rrf"` (default, k=60) or `"linear"` — nothing else (see Caveats).
- **xerj_memory_store** — `POST /_memory/{namespace}` with `{"text":"user prefers dark mode","metadata":{…},"id":"opt","vector":[…]?,"dedup":true?,"dedup_threshold":0.95?}`. Text is auto-embedded; namespaces are isolated.
-- **xerj_memory_recall** — `POST /_memory/{namespace}/_recall` with `{"query":"what UI theme?","semantic":true,"k":5,"filter":{…}?,"recency_weight":0.2?}`. Modes in order: explicit `vector` kNN → `semantic:true` (server embeds) → plain `query` text (BM25). Same embedder caveat as `xerj_semantic_search`.
+- **xerj_memory_recall** — `POST /_memory/{namespace}/_recall` with `{"query":"what UI theme?","semantic":true,"k":5,"filter":{…}?,"recency_weight":0.2?}`. Modes in order: explicit `vector` kNN → `hybrid:true` (BM25 + server-side semantic over the same `query`, fused by reciprocal rank; `fusion:"linear"` opt-in) → `semantic:true` (server embeds) → plain `query` text (BM25). Same embedder caveat as `xerj_semantic_search`.
**Endpoint map (Elasticsearch-compatible, :9200)** — the wire surface those operations ride on: