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(hybrid): fail-loud 400 for aggregations in hybrid/fusion queries
xerj-org539bd9a9439c
diff --git a/engine/crates/xerj-engine/src/index.rs b/engine/crates/xerj-engine/src/index.rsindex 58bbfec04..8299f6d31 100644--- a/engine/crates/xerj-engine/src/index.rs+++ b/engine/crates/xerj-engine/src/index.rs@@ -3635,8 +3635,11 @@ impl Index {/// Aggregations are NOT supported in hybrid queries today (the/// natural semantics — agg over the fused result set vs over each/// sub-query — is application-specific). If the request asks for- /// aggs we surface that as the response's `aggs: null` so callers- /// notice; the v0.7-P1 scope is hits + scores only.+ /// aggs we reject it with an explicit 400 rather than silently+ /// dropping them; a bounded aggregation over the fused top-N would+ /// present under-counted `doc_count`s as if they were exact. Run+ /// the aggregation as a separate, non-hybrid search instead. The+ /// v0.7-P1 scope is hits + scores only.pub async fn run_hybrid(&self,request: &SearchRequest,@@ -3645,6 +3648,17 @@ impl Index {) -> Result<SearchResult> {let started = std::time::Instant::now();+ // Aggregations over a fused (RRF/Linear/Learned) result set have+ // no well-defined exact semantics — a bounded agg over the fused+ // top-N would silently under-count. Fail loud (400) instead of+ // returning `aggs: null`, mirroring `result_window_too_large`.+ if request.aggs.is_some() {+ return Err(EngineError::Common(xerj_common::XerjError::invalid_query(+ "aggregations are not supported with hybrid/fusion queries; \+ run the aggregation as a separate non-hybrid search",+ )));+ }+// Each sub-list needs to be deeper than the final top-N so// fusion has enough material for stable rank-merge. ES uses// 50 by default; we mirror that, growing if the caller askeddiff --git a/engine/tests/es-compat-yaml/yaml/vectors/95_hybrid_aggs_unsupported.yml b/engine/tests/es-compat-yaml/yaml/vectors/95_hybrid_aggs_unsupported.ymlnew file mode 100644index 000000000..fbd63e002--- /dev/null+++ b/engine/tests/es-compat-yaml/yaml/vectors/95_hybrid_aggs_unsupported.yml@@ -0,0 +1,72 @@+setup:++ - do:+ indices.create:+ index: hybrid_aggs_test+ body:+ settings:+ number_of_shards: 1+ mappings:+ properties:+ title:+ type: text+ category:+ type: keyword++ - do:+ bulk:+ refresh: true+ body:+ - '{ "index": { "_index": "hybrid_aggs_test", "_id": "1" } }'+ - '{ "title": "quick brown fox", "category": "a" }'+ - '{ "index": { "_index": "hybrid_aggs_test", "_id": "2" } }'+ - '{ "title": "lazy brown dog", "category": "b" }'+ - '{ "index": { "_index": "hybrid_aggs_test", "_id": "3" } }'+ - '{ "title": "quick red fox", "category": "a" }'++---+"hybrid query with aggregations is rejected (400)":++ # Aggregations over a fused (RRF) result set have no exact semantics —+ # XERJ fails loud with a 400 rather than silently dropping the aggs or+ # returning under-counted doc_counts.+ - do:+ catch: bad_request+ search:+ index: hybrid_aggs_test+ body:+ query:+ hybrid:+ queries:+ - query:+ match:+ title: "brown"+ - query:+ match:+ title: "fox"+ fusion: "rrf"+ aggs:+ by_category:+ terms:+ field: category++---+"hybrid query without aggregations still works":++ - do:+ search:+ rest_total_hits_as_int: true+ index: hybrid_aggs_test+ body:+ query:+ hybrid:+ queries:+ - query:+ match:+ title: "brown"+ - query:+ match:+ title: "fox"+ fusion: "rrf"++ - match: { hits.total: 3 }