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.

fix(knn): clippy 1.97 clean for the #939 scan; latency harness records what it timed

xerj-org01d936fc3355
diff --git a/benchmarks/hybrid-scan-939/compare_ranked.py b/benchmarks/hybrid-scan-939/compare_ranked.py
new file mode 100755
index 000000000..02b62a1a7
--- /dev/null
+++ b/benchmarks/hybrid-scan-939/compare_ranked.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+"""Compare the ranked `(_id, _score)` lists two latency.py runs wrote. Exit 1 on ANY difference.
+
+ python3 compare_ranked.py before.ranked.json after.ranked.json
+
+Zero tolerance: same ids, same order, same `_score` JSON number. The last arm
+(one request repeated) is compared too; it is served from the result cache on
+both sides and must still agree.
+"""
+import json
+import sys
+
+a, b = (json.load(open(p)) for p in sys.argv[1:3])
+bad = 0
+if a.keys() != b.keys():
+ print("ARMS DIFFER:", sorted(a.keys() ^ b.keys()))
+ bad += 1
+for arm in a:
+ if arm not in b:
+ continue
+ ra, rb = a[arm], b[arm]
+ if len(ra) != len(rb):
+ print(f"{arm}: query count differs {len(ra)} vs {len(rb)}")
+ bad += 1
+ continue
+ diffs = sum(1 for x, y in zip(ra, rb) if x != y)
+ hits = sum(len(x) for x in ra)
+ print(f"{arm:34s} queries={len(ra)} hits_compared={hits} differing_queries={diffs}")
+ bad += diffs
+print("IDENTICAL" if bad == 0 else f"NOT IDENTICAL: {bad} differences")
+sys.exit(1 if bad else 0)
diff --git a/benchmarks/hybrid-scan-939/latency.py b/benchmarks/hybrid-scan-939/latency.py
index 6a027c062..10fd630da 100755
--- a/benchmarks/hybrid-scan-939/latency.py
+++ b/benchmarks/hybrid-scan-939/latency.py
@@ -1,7 +1,12 @@
#!/usr/bin/env python3
"""Per-arm search latency, closed loop, one client.
- XERJ_API_KEY=... python3 latency.py http://localhost:10840 scifact /path/to/beir/scifact 300
+ XERJ_API_KEY=... python3 latency.py http://localhost:10840 scifact /path/to/beir/scifact 300 [ranked.json]
+
+With the optional last argument, every timed response's ranked `(_id, _score)`
+list is written there, per arm and query, so two binaries' latency runs can be
+checked for identical results with `compare_ranked.py` over EXACTLY the
+requests that were timed (identity.py covers fewer queries, deeper).
Read-only (`_search`, `/v1/metrics`). Every arm sends N DISTINCT query texts,
so no request inside an arm repeats. Arms differ in request body, and the
@@ -16,6 +21,7 @@ is there so the trap stays visible to whoever runs this next.
Machine load (1-minute loadavg) is printed per arm. A latency taken while
other jobs saturate the box is an upper bound, not a measurement of the engine.
"""
+import json
import sys
import time
@@ -23,6 +29,8 @@ from common import (bm25_query, cache_counters, distinct_queries, http, hybrid_q
semantic_query)
url, index, data_dir, n = sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4])
+ranked_out = sys.argv[5] if len(sys.argv) > 5 else None
+ranked = {}
qs = distinct_queries(data_dir, n)
@@ -61,11 +69,13 @@ for name, fn in arms:
hits0, _ = cache_counters(url)
load0 = loadavg()
print("ARM_START", name, time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()), flush=True)
- lat, took = [], []
+ lat, took, rows = [], [], []
for q in qs:
dt, r = fn(q)
lat.append(dt * 1000)
took.append(r.get("took", 0))
+ rows.append([[h["_id"], h.get("_score")] for h in r["hits"]["hits"]])
+ ranked[name] = rows
print("ARM_END", name, time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()), flush=True)
hits1, _ = cache_counters(url)
lat.sort()
@@ -73,3 +83,7 @@ for name, fn in arms:
print(f"{name:34s} n={len(lat)} p50={pct(lat, .5):7.1f}ms p95={pct(lat, .95):7.1f}ms"
f" server_took p50={pct(took, .5)}ms p95={pct(took, .95)}ms"
f" cache_hits={hits1 - hits0} loadavg={load0}->{loadavg()}", flush=True)
+if ranked_out:
+ with open(ranked_out, "w") as f:
+ json.dump(ranked, f)
+ print("wrote", ranked_out)
diff --git a/engine/crates/xerj-engine/src/index.rs b/engine/crates/xerj-engine/src/index.rs
index 446d4e819..615e82875 100644
--- a/engine/crates/xerj-engine/src/index.rs
+++ b/engine/crates/xerj-engine/src/index.rs
@@ -35993,11 +35993,11 @@ fn collect_filter_root_keys(filter: &QueryNode, out: &mut Vec<String>) -> bool {
match minimum_should_match {
// Runs Painless over the whole document.
Some(MinShouldMatch::Script { .. }) => return false,
- // `terms_set`: the required count is read from this field.
- Some(MinShouldMatch::Field(name)) => {
- if !push_field_root_keys(name, out) {
- return false;
- }
+ // `terms_set`: the required count is read from this field, so
+ // its root keys join the projection (the guard pushes them);
+ // a pattern field cannot be projected and declines.
+ Some(MinShouldMatch::Field(name)) if !push_field_root_keys(name, out) => {
+ return false;
}
_ => {}
}
@@ -53452,13 +53452,13 @@ mod exact_scan_hydration_tests {
rng.vector()
};
let mut doc = serde_json::json!({
- "title": format!("doc {id} {}", if id % 4 == 0 { "cell" } else { "other" }),
+ "title": format!("doc {id} {}", if id.is_multiple_of(4) { "cell" } else { "other" }),
"tag": format!("t{}", id % 5),
"n": (id * 37) % 1000,
"body": format!("body text {id}"),
"body_vector": as_json(&pooled),
});
- if id % 3 == 0 {
+ if id.is_multiple_of(3) {
let passages: Vec<Value> = (0..2 + id % 4).map(|_| as_json(&rng.vector())).collect();
doc["body_vector_chunks"] = Value::Array(passages);
}