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(autoindex): #673 prefix-scope correlation catalog ids (corr:/tcorr:)

xerj-orgc8909f3e31d9
diff --git a/engine/crates/xerj-autoindex/src/correlate.rs b/engine/crates/xerj-autoindex/src/correlate.rs
index b966897e5..a3838abac 100644
--- a/engine/crates/xerj-autoindex/src/correlate.rs
+++ b/engine/crates/xerj-autoindex/src/correlate.rs
@@ -38,10 +38,15 @@ pub struct KeyCorr {
}
impl KeyCorr {
- pub fn id(&self) -> String {
+ /// Catalog doc id, corpus-prefix-scoped (#673). The `autoindex-catalog`
+ /// index is shared across corpora, so a correlation keyed only by dataset
+ /// slugs (`corr:reports:orders:…`) would overwrite the same-slug
+ /// correlation from another corpus. Threading `prefix` — exactly as #416
+ /// did for `file:`/`ds:` ids — keeps them distinct.
+ pub fn id(&self, prefix: &str) -> String {
format!(
- "corr:{}:{}:{}:{}",
- self.a_slug, self.b_slug, self.a_field, self.b_field
+ "corr:{}:{}:{}:{}:{}",
+ prefix, self.a_slug, self.b_slug, self.a_field, self.b_field
)
}
pub fn to_value(&self) -> Value {
@@ -341,3 +346,51 @@ pub fn time_alignment(series: &[TimeSeries]) -> Vec<Value> {
}
out
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn sample_corr() -> KeyCorr {
+ KeyCorr {
+ a_slug: "reports".into(),
+ a_index: "ax-reports".into(),
+ a_field: "order_id".into(),
+ b_slug: "orders".into(),
+ b_index: "ax-orders".into(),
+ b_field: "id".into(),
+ kind: "keyword".into(),
+ a_set: 100,
+ b_set: 100,
+ overlap: 80,
+ containment: 0.8,
+ grade: "strong".into(),
+ examples: vec!["500001".into()],
+ confirmed: None,
+ confirm_details: Vec::new(),
+ }
+ }
+
+ /// #673: the `autoindex-catalog` index is shared across corpora, so a
+ /// correlation keyed only by dataset slugs must carry the corpus prefix in
+ /// its id — otherwise `(reports, orders)` in corpus A overwrites the
+ /// same-slug correlation in corpus B (silent cross-corpus data-loss).
+ #[test]
+ fn correlation_id_is_prefix_scoped_across_corpora() {
+ let c = sample_corr();
+ // Same correlation, different corpus prefix -> distinct ids (no overwrite).
+ assert_ne!(
+ c.id("ax-a"),
+ c.id("ax-b"),
+ "#673: same-slug correlations from two corpora must not collide"
+ );
+ // Idempotent within one corpus (a re-run upserts, does not duplicate).
+ assert_eq!(c.id("ax-a"), c.id("ax-a"));
+ // The prefix is actually in the id (not merely concatenated onto slugs).
+ assert!(
+ c.id("ax-a").starts_with("corr:ax-a:"),
+ "id was {:?}",
+ c.id("ax-a")
+ );
+ }
+}
diff --git a/engine/crates/xerj-autoindex/src/lib.rs b/engine/crates/xerj-autoindex/src/lib.rs
index 5bd18f150..cf7435e68 100644
--- a/engine/crates/xerj-autoindex/src/lib.rs
+++ b/engine/crates/xerj-autoindex/src/lib.rs
@@ -5521,11 +5521,14 @@ pub fn run_index_report(cfg: IndexCfg) -> Result<(i32, Option<Value>)> {
for c in &key_corrs {
let mut v = c.to_value();
v["run_id"] = json!(run_id);
- push_doc(&c.id(), &v, &mut cat_buf);
+ push_doc(&c.id(&cfg.prefix), &v, &mut cat_buf);
}
for (i, tc) in time_corrs.iter().enumerate() {
+ // Prefix-scoped for the same cross-corpus reason as `corr:` above (#673):
+ // time correlations are keyed by dataset slugs and share the catalog.
let id = format!(
- "tcorr:{}:{}",
+ "tcorr:{}:{}:{}",
+ cfg.prefix,
tc.get("a_dataset").and_then(|v| v.as_str()).unwrap_or(""),
tc.get("b_dataset")
.and_then(|v| v.as_str())