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.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(es-compat): complete the knn+query hybrid_safe guard — every run_hybrid-dropped field (#458)
xerj-org9d9e9c810503
diff --git a/engine/crates/xerj-api/src/es_compat.rs b/engine/crates/xerj-api/src/es_compat.rsindex ae7f6fdd4..34d2ed321 100644--- a/engine/crates/xerj-api/src/es_compat.rs+++ b/engine/crates/xerj-api/src/es_compat.rs@@ -8942,6 +8942,14 @@ async fn search_impl(&& body.sort.is_none()&& body.collapse.is_none()&& body.search_after.is_none()+ // The fusion executor also hard-drops rescore and highlight and+ // ignores explain/profile (run_hybrid_with_deadline zeroes them on+ // every sub-query) — keep bool.should when any is present so they+ // are honoured rather than silently dropped (#458).+ && body.rescore.is_none()+ && body.highlight.is_none()+ && !body.explain+ && !body.profile// A BM25-tuned `min_score` (e.g. 2.0) applied post-fusion to RRF// micro-scores (~1/61) would drop EVERY hit — keep bool.should,// where min_score compares against the BM25 sum it was tuned for.diff --git a/engine/crates/xerj-api/tests/knn_beside_query_with_aggs_stays_200.rs b/engine/crates/xerj-api/tests/knn_beside_query_with_aggs_stays_200.rsindex d60c4d6fc..20bbcf4b2 100644--- a/engine/crates/xerj-api/tests/knn_beside_query_with_aggs_stays_200.rs+++ b/engine/crates/xerj-api/tests/knn_beside_query_with_aggs_stays_200.rs@@ -189,3 +189,72 @@ async fn knn_beside_query_returns_the_vector_only_document() {"the lexical match must still be present: hits={ids:?} body={body}");}++/// A hybrid-incompatible feature (here `rescore`, which the fusion executor+/// silently drops) must keep the request on the lexical `bool.should` path where+/// rescore is honoured — NOT route it to `hybrid`. Observable proxy: the+/// vector-only document that ONLY the hybrid path surfaces must be ABSENT, so a+/// present-`rescore` request is provably not on the hybrid branch.+#[tokio::test]+async fn knn_beside_query_with_rescore_stays_on_the_lexical_path() {+ let (app, _dir) = app().await;++ let (st, b) = json_req(+ &app,+ "PUT",+ "/r",+ json!({ "mappings": { "properties": {+ "body": { "type": "text" },+ "v": { "type": "dense_vector", "dims": 3 }+ } } }),+ )+ .await;+ assert!(st.is_success(), "create index: {st} {b}");+ for (id, body, vec) in [+ ("lex", "alpha beta", [1.0_f32, 0.0, 0.0]),+ ("vec", "zzz qqq", [0.1_f32, 0.2, 0.3]),+ ] {+ let (st, b) = json_req(+ &app,+ "POST",+ &format!("/r/_doc/{id}"),+ json!({ "body": body, "v": vec }),+ )+ .await;+ assert!(st.is_success(), "index {id}: {st} {b}");+ }+ let (_s, _b) = json_req(&app, "POST", "/r/_refresh", json!({})).await;++ let (status, body) = json_req(+ &app,+ "POST",+ "/r/_search",+ json!({+ "query": { "match": { "body": "alpha" } },+ "knn": { "field": "v", "query_vector": [0.1, 0.2, 0.3], "k": 2, "num_candidates": 10 },+ "rescore": { "window_size": 10, "query": { "rescore_query": { "match": { "body": "alpha" } } } }+ }),+ )+ .await;+ assert_eq!(+ status,+ StatusCode::OK,+ "knn+query+rescore status: {status} {body}"+ );++ let ids: Vec<String> = body+ .pointer("/hits/hits")+ .and_then(Value::as_array)+ .map(|hits| {+ hits.iter()+ .filter_map(|h| h.get("_id").and_then(Value::as_str).map(String::from))+ .collect()+ })+ .unwrap_or_default();+ assert!(+ !ids.iter().any(|id| id == "vec"),+ "#458: knn+query+rescore must stay on bool.should (rescore honoured), not route to the \+ hybrid executor that silently drops rescore — the hybrid-only vector doc must be \+ absent: hits={ids:?} body={body}"+ );+}