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.

style: cargo fmt on this session's engine changes

xerj-org206a560e18d8
diff --git a/engine/crates/xerj-api/src/es_compat.rs b/engine/crates/xerj-api/src/es_compat.rs
index c4bebdd81..3e0ba10bc 100644
--- a/engine/crates/xerj-api/src/es_compat.rs
+++ b/engine/crates/xerj-api/src/es_compat.rs
@@ -5820,7 +5820,8 @@ pub async fn search(
.map(|v| v.clone())
.and_then(|s| {
let as_int = |v: &Value| {
- v.as_u64().or_else(|| v.as_str().and_then(|s| s.parse().ok()))
+ v.as_u64()
+ .or_else(|| v.as_str().and_then(|s| s.parse().ok()))
};
s.pointer("/index/max_script_fields")
.and_then(as_int)
@@ -5839,7 +5840,8 @@ pub async fn search(
[{max_sf}] but was [{n}]. This limit can be set by changing the \
[index.max_script_fields] index level setting."
);
- return ApiError::new(xerj_common::XerjError::invalid_query(reason)).into_response();
+ return ApiError::new(xerj_common::XerjError::invalid_query(reason))
+ .into_response();
}
}
}
diff --git a/engine/crates/xerj-api/src/memory_api.rs b/engine/crates/xerj-api/src/memory_api.rs
index 0bb58fd55..2dc5d161b 100644
--- a/engine/crates/xerj-api/src/memory_api.rs
+++ b/engine/crates/xerj-api/src/memory_api.rs
@@ -680,18 +680,31 @@ mod tests {
let state = test_state();
for (id, text) in [
- ("i1", "host 1.2.3.4 brute forced ssh with hundreds of failed passwords"),
+ (
+ "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"),
+ (
+ "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, "text-only store must succeed (auto-embedded)");
+ assert_eq!(
+ s,
+ StatusCode::CREATED,
+ "text-only store must succeed (auto-embedded)"
+ );
}
// Pass query TEXT + semantic:true, NO vector. The server embeds it.
- let (s, body) =
- recall_mem(&state, "soc", json!({"query": "ssh brute force attack", "semantic": true, "k": 2}))
- .await;
+ let (s, body) = recall_mem(
+ &state,
+ "soc",
+ json!({"query": "ssh brute force attack", "semantic": true, "k": 2}),
+ )
+ .await;
assert_eq!(s, StatusCode::OK);
let hits = body["hits"].as_array().unwrap();
assert_eq!(hits.len(), 2, "semantic k=2 → exactly 2 hits");
@@ -707,7 +720,11 @@ mod tests {
// semantic:true with no query text → 400 (nothing to embed).
let (s, _) = recall_mem(&state, "soc", json!({"semantic": true})).await;
- assert_eq!(s, StatusCode::BAD_REQUEST, "semantic recall needs a `query` to embed");
+ assert_eq!(
+ s,
+ StatusCode::BAD_REQUEST,
+ "semantic recall needs a `query` to embed"
+ );
// A metadata filter still narrows semantic recall.
store_mem(
@@ -723,7 +740,10 @@ mod tests {
)
.await;
let hits = body["hits"].as_array().unwrap();
- assert!(!hits.is_empty(), "filtered semantic recall returns the high-sev memory");
+ assert!(
+ !hits.is_empty(),
+ "filtered semantic recall returns the high-sev memory"
+ );
assert!(
hits.iter().all(|h| h["id"] == "i4"),
"only the high-sev memory passes the filter"
diff --git a/engine/crates/xerj-engine/src/index.rs b/engine/crates/xerj-engine/src/index.rs
index a6ebd14c6..58bbfec04 100644
--- a/engine/crates/xerj-engine/src/index.rs
+++ b/engine/crates/xerj-engine/src/index.rs
@@ -3435,15 +3435,15 @@ impl Index {
}
.into_iter()
.map(|(id, score, source)| Hit {
- id,
- score,
- source,
- sort: Vec::new(),
- explain: None,
- highlight: None,
- matched_queries: Vec::new(),
- })
- .collect();
+ id,
+ score,
+ source,
+ sort: Vec::new(),
+ explain: None,
+ highlight: None,
+ matched_queries: Vec::new(),
+ })
+ .collect();
Ok(SearchResult {
hits,
diff --git a/engine/crates/xerj-engine/tests/integration.rs b/engine/crates/xerj-engine/tests/integration.rs
index 79c9f3387..a8bb24abf 100644
--- a/engine/crates/xerj-engine/tests/integration.rs
+++ b/engine/crates/xerj-engine/tests/integration.rs
@@ -3181,12 +3181,22 @@ async fn test_knn_size_windows_into_k() {
// k=4 pool, size=2 requested → exactly 2 hits, total reports the k pool.
let res = idx.search(&knn(json!({"size": 2}))).await.unwrap();
- assert_eq!(res.hits.len(), 2, "size must cap returned hits (pre-fix returned k=4)");
- assert_eq!(res.total.value, 4, "total.value is the k-neighbor pool, not the 6-doc corpus");
+ assert_eq!(
+ res.hits.len(),
+ 2,
+ "size must cap returned hits (pre-fix returned k=4)"
+ );
+ assert_eq!(
+ res.total.value, 4,
+ "total.value is the k-neighbor pool, not the 6-doc corpus"
+ );
assert_eq!(res.hits[0].id, "d1", "top hit is the exact match");
// from paginates within the pool: page [1..3) skips the top neighbor.
- let res2 = idx.search(&knn(json!({"from": 1, "size": 2}))).await.unwrap();
+ let res2 = idx
+ .search(&knn(json!({"from": 1, "size": 2})))
+ .await
+ .unwrap();
assert_eq!(res2.hits.len(), 2, "from+size windows within the k pool");
assert_eq!(res2.total.value, 4, "total is unaffected by from/size");
assert_ne!(res2.hits[0].id, res.hits[0].id, "from=1 skips the top hit");