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.

test(api): lock the multi-knn & nested-knn declared-but-empty -> 200 invariants (#547)

xerj-org22af06db6c0b
diff --git a/engine/crates/xerj-api/tests/knn_on_missing_field_400s.rs b/engine/crates/xerj-api/tests/knn_on_missing_field_400s.rs
index 4a50a1fbb..d56105f4c 100644
--- a/engine/crates/xerj-api/tests/knn_on_missing_field_400s.rs
+++ b/engine/crates/xerj-api/tests/knn_on_missing_field_400s.rs
@@ -270,3 +270,79 @@ async fn nested_knn_on_absent_field_is_400_not_silent_empty() {
"the 400 must name the field: {body}"
);
}
+
+/// #547: the #529-class invariant for MULTI-knn — a 2-clause array on
+/// DECLARED-but-empty dense_vector fields returns an empty 200, not a 400.
+#[tokio::test]
+async fn multi_knn_on_declared_but_empty_vector_fields_is_empty_200() {
+ let (app, _dir) = app().await;
+ let (status, body) = json_req(
+ &app,
+ "PUT",
+ "/vecs",
+ json!({ "mappings": { "properties": {
+ "a": { "type": "dense_vector", "dims": 3 },
+ "b": { "type": "dense_vector", "dims": 3 }
+ } } }),
+ )
+ .await;
+ assert!(status.is_success(), "create index: {status} {body}");
+ // No documents indexed — both fields are declared vectors with nothing to match.
+ let (status, body) = json_req(
+ &app,
+ "POST",
+ "/vecs/_search",
+ json!({ "knn": [
+ { "field": "a", "query_vector": [0.1, 0.2, 0.3], "k": 5, "num_candidates": 50 },
+ { "field": "b", "query_vector": [0.4, 0.5, 0.6], "k": 5, "num_candidates": 50 }
+ ] }),
+ )
+ .await;
+ assert!(
+ status.is_success(),
+ "multi-knn on declared-but-empty vector fields is a real empty result, not 400 (#547/#529): {status} {body}"
+ );
+ assert_eq!(
+ body.pointer("/hits/total/value").and_then(Value::as_u64),
+ Some(0),
+ "expected empty: {body}"
+ );
+}
+
+/// #547: the #529-class invariant for NESTED knn — a nested knn on a
+/// DECLARED-but-empty nested dense_vector returns an empty 200, not a 400.
+#[tokio::test]
+async fn nested_knn_on_declared_but_empty_vector_field_is_empty_200() {
+ let (app, _dir) = app().await;
+ let (status, body) = json_req(
+ &app,
+ "PUT",
+ "/docs",
+ json!({ "mappings": { "properties": {
+ "items": { "type": "nested", "properties": {
+ "vector": { "type": "dense_vector", "dims": 3 }
+ } }
+ } } }),
+ )
+ .await;
+ assert!(status.is_success(), "create index: {status} {body}");
+ // No documents indexed — the nested vector field is declared, just empty.
+ let (status, body) = json_req(
+ &app,
+ "POST",
+ "/docs/_search",
+ json!({ "query": { "nested": { "path": "items", "query": { "knn": {
+ "field": "items.vector", "query_vector": [0.1, 0.2, 0.3], "k": 5, "num_candidates": 50
+ } } } } }),
+ )
+ .await;
+ assert!(
+ status.is_success(),
+ "nested knn on a declared-but-empty nested dense_vector is a real empty result, not 400 (#547/#529): {status} {body}"
+ );
+ assert_eq!(
+ body.pointer("/hits/total/value").and_then(Value::as_u64),
+ Some(0),
+ "expected empty: {body}"
+ );
+}