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(corpus): skip CSV/HDF/simulation data when indexing a reference corpus (#1985) (#2014)

ordinary beinga8b5892378a1
diff --git a/engine/crates/xerj-autoindex/src/cli.rs b/engine/crates/xerj-autoindex/src/cli.rs
index b4a85f7e4..ae0c96b4a 100644
--- a/engine/crates/xerj-autoindex/src/cli.rs
+++ b/engine/crates/xerj-autoindex/src/cli.rs
@@ -133,6 +133,11 @@ pub struct IndexCfg {
/// `xerj autoindex <folder>`. `xerj corpus index` sets `corpus.json` so
/// the hub manifest is not indexed as a document dataset.
pub exclude_rels: Vec<String>,
+ /// `xerj corpus index` only (#1985): skip data files (CSV/HDF/simulation
+ /// output — see [`crate::CORPUS_DATA_EXTS`]) instead of indexing them as
+ /// records. `--include-data` turns it off. Never set by
+ /// `xerj autoindex <folder>`: a user's own project may want its data.
+ pub skip_corpus_data: bool,
}
#[derive(Debug, Clone)]
@@ -1738,6 +1743,7 @@ pub fn parse(args: Vec<String>) -> Result<Cmd, String> {
debounce_ms.unwrap_or(crate::watch::DEFAULT_DEBOUNCE_MS),
),
exclude_rels: Vec::new(),
+ skip_corpus_data: false,
})))
}
// No folder and no subcommand. This used to print the full help and
diff --git a/engine/crates/xerj-autoindex/src/detect/e2e.rs b/engine/crates/xerj-autoindex/src/detect/e2e.rs
index b23b4596f..337acff22 100644
--- a/engine/crates/xerj-autoindex/src/detect/e2e.rs
+++ b/engine/crates/xerj-autoindex/src/detect/e2e.rs
@@ -385,6 +385,7 @@ pub(super) fn cfg(root: &Path, state_dir: &Path, url: &str) -> IndexCfg {
label: None,
debounce: std::time::Duration::from_millis(0),
exclude_rels: Vec::new(),
+ skip_corpus_data: false,
}
}
diff --git a/engine/crates/xerj-autoindex/src/failure_resume_http_tests.rs b/engine/crates/xerj-autoindex/src/failure_resume_http_tests.rs
index b6e201da4..80b671380 100644
--- a/engine/crates/xerj-autoindex/src/failure_resume_http_tests.rs
+++ b/engine/crates/xerj-autoindex/src/failure_resume_http_tests.rs
@@ -823,6 +823,7 @@ fn cfg(root: &Path, state_dir: &Path, url: &str) -> IndexCfg {
label: None,
debounce: std::time::Duration::from_millis(0),
exclude_rels: Vec::new(),
+ skip_corpus_data: false,
}
}
diff --git a/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs b/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs
index acbbe9e80..1a1a55fe7 100644
--- a/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs
+++ b/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs
@@ -974,6 +974,7 @@ fn cfg(root: &Path, state_dir: &Path, url: &str, semantic: bool) -> IndexCfg {
label: None,
debounce: std::time::Duration::from_millis(0),
exclude_rels: Vec::new(),
+ skip_corpus_data: false,
}
}
diff --git a/engine/crates/xerj-autoindex/src/label_http_tests.rs b/engine/crates/xerj-autoindex/src/label_http_tests.rs
index 89ce2f850..426ad13a9 100644
--- a/engine/crates/xerj-autoindex/src/label_http_tests.rs
+++ b/engine/crates/xerj-autoindex/src/label_http_tests.rs
@@ -393,6 +393,7 @@ fn cfg(root: &Path, state_dir: &Path, url: &str, label: &Path) -> IndexCfg {
debounce: std::time::Duration::from_millis(0),
label: Some(label.to_owned()),
exclude_rels: Vec::new(),
+ skip_corpus_data: false,
}
}
diff --git a/engine/crates/xerj-autoindex/src/lib.rs b/engine/crates/xerj-autoindex/src/lib.rs
index 5ec68f8a3..5b42d5f3d 100644
--- a/engine/crates/xerj-autoindex/src/lib.rs
+++ b/engine/crates/xerj-autoindex/src/lib.rs
@@ -1848,6 +1848,56 @@ fn without_excluded_rels(
(kept, dropped)
}
+/// Extensions that are DATA in a cloned reference repo, not reference material
+/// (#1985): `xerj corpus index` exists to retrieve code and docs, and one
+/// simulation/test-output folder in the field report produced 636,724 records
+/// — more than the rest of that corpus together. The gate is by FAMILY, not by
+/// size: the cost came from many files, so a size floor would let most of them
+/// through. `xerj corpus index --include-data` indexes them anyway.
+pub const CORPUS_DATA_EXTS: &[&str] = &[
+ // Tabular / columnar dumps.
+ "csv", "tsv", "parquet", "arrow", "feather", "orc", "avro",
+ // Scientific arrays and dataframes.
+ "h5", "hdf5", "hdf", "nc", "npy", "npz", "mat", "sav", "dta", "rds", "fits",
+ // Simulation / capture output.
+ "out", "sim", "vtk", "pcap", "pcapng",
+ // Embedded databases and serialized models.
+ "sqlite", "sqlite3", "db", "pkl", "pickle",
+];
+
+/// True when `file` carries a [`CORPUS_DATA_EXTS`] extension (case-insensitive).
+fn is_corpus_data_file(file: &walk::FileEntry) -> bool {
+ file.path
+ .extension()
+ .and_then(|e| e.to_str())
+ .is_some_and(|ext| {
+ CORPUS_DATA_EXTS
+ .iter()
+ .any(|data| ext.eq_ignore_ascii_case(data))
+ })
+}
+
+/// Drop [`is_corpus_data_file`] entries from a corpus inventory. Returns the
+/// kept files plus the skipped count and bytes so the run can say what it left
+/// out (#1985) instead of silently indexing less than the folder holds.
+fn without_corpus_data_files(files: Vec<walk::FileEntry>) -> (Vec<walk::FileEntry>, usize, u64) {
+ let before = files.len();
+ let mut skipped_bytes = 0u64;
+ let kept: Vec<walk::FileEntry> = files
+ .into_iter()
+ .filter(|file| {
+ if is_corpus_data_file(file) {
+ skipped_bytes += file.size;
+ false
+ } else {
+ true
+ }
+ })
+ .collect();
+ let dropped = before - kept.len();
+ (kept, dropped, skipped_bytes)
+}
+
#[cfg(test)]
mod generation_preflight_tests {
use super::*;
@@ -1984,6 +2034,59 @@ mod exclude_rels_tests {
}
}
+#[cfg(test)]
+mod corpus_data_skip_tests {
+ use super::*;
+
+ fn entry(rel: &str, size: u64) -> walk::FileEntry {
+ walk::FileEntry {
+ path: std::path::PathBuf::from(rel),
+ rel: rel.to_string(),
+ rel_id: rel.to_string(),
+ is_symlink: false,
+ size,
+ }
+ }
+
+ /// #1985: the data families a cloned reference repo ships are dropped —
+ /// case-insensitively — while source, docs, logs and records stay. The
+ /// skipped bytes are reported so the run can say what it left out.
+ #[test]
+ fn data_families_are_skipped_and_counted_but_source_docs_logs_and_records_stay() {
+ let files = vec![
+ entry("src/main.rs", 10),
+ entry("docs/GUIDE.md", 20),
+ entry("logs/app.log", 30),
+ entry("records.jsonl", 40),
+ entry("tests/fixtures/data.CSV", 1_000),
+ entry("sim/run1.h5", 2_000),
+ entry("sim/out.vtk", 3_000),
+ entry("db/cache.sqlite3", 4_000),
+ ];
+ let (kept, count, bytes) = without_corpus_data_files(files);
+ let rels: Vec<&str> = kept.iter().map(|f| f.rel.as_str()).collect();
+ assert_eq!(
+ rels,
+ [
+ "src/main.rs",
+ "docs/GUIDE.md",
+ "logs/app.log",
+ "records.jsonl"
+ ],
+ "the data families are skipped; code/docs/logs/records are not"
+ );
+ assert_eq!(count, 4);
+ assert_eq!(bytes, 1_000 + 2_000 + 3_000 + 4_000);
+ }
+
+ /// A file with no extension (a Makefile, a script) is not data by family.
+ #[test]
+ fn a_file_without_an_extension_is_kept() {
+ let (kept, count, bytes) = without_corpus_data_files(vec![entry("Makefile", 1)]);
+ assert_eq!((kept.len(), count, bytes), (1, 0, 0));
+ }
+}
+
/// In-process autoindex for the `xerj corpus` lifecycle (issue #977): builds
/// the same argv the wrapper script passed and routes it through the same
/// parse → run → error-route path as `run_cli`, so there is exactly ONE
@@ -1999,6 +2102,7 @@ pub fn run_with_options(
prefix: &str,
state_dir: Option<&std::path::Path>,
no_graph: bool,
+ include_data: bool,
) -> i32 {
let mut args = vec![
dir.to_string_lossy().to_string(),
@@ -2028,6 +2132,9 @@ pub fn run_with_options(
// so a project that happens to contain `corpus.json` still indexes it.
let mut cfg = *cfg;
cfg.exclude_rels = vec![CORPUS_MANIFEST_REL.to_string()];
+ // #1985: a cloned reference repo ships test outputs and datasets;
+ // index code + docs unless the operator asked for the data too.
+ cfg.skip_corpus_data = !include_data;
run_index(cfg)
}
_ => return 2,
@@ -3364,6 +3471,7 @@ mod phase_a_grouping_tests {
label: None,
debounce: std::time::Duration::from_millis(0),
exclude_rels: Vec::new(),
+ skip_corpus_data: false,
}
}
@@ -6666,6 +6774,22 @@ fn run_index_report_inner(
cfg.exclude_rels.join(", ")
));
}
+ let (discovered_files, data_files, data_bytes) = if cfg.skip_corpus_data {
+ without_corpus_data_files(discovered_files)
+ } else {
+ (discovered_files, 0, 0)
+ };
+ if data_files > 0 {
+ let size = if data_bytes >= 1 << 20 {
+ format!("{:.1} MB", data_bytes as f64 / (1u64 << 20) as f64)
+ } else {
+ format!("{} KB", data_bytes.div_ceil(1024))
+ };
+ pr.note(&format!(
+ "autoindex: left out {data_files} data file(s) ({size}): CSV/HDF/simulation output \
+ is data, not reference code — pass --include-data to index them"
+ ));
+ }
let discovered_bytes: u64 = discovered_files.iter().map(|f| f.size).sum();
pr.note(&format!(
"autoindex: {} files ({} MB) under {}",
diff --git a/engine/crates/xerj-autoindex/src/xc.rs b/engine/crates/xerj-autoindex/src/xc.rs
index 2ef35de80..564d284a8 100644
--- a/engine/crates/xerj-autoindex/src/xc.rs
+++ b/engine/crates/xerj-autoindex/src/xc.rs
@@ -235,7 +235,7 @@ const CORPUS_USAGE: &str =
xerj corpus build <name> [--recipe <path>] [--fresh]
xerj corpus sign <pack-dir> --key <seed-file>
xerj corpus keygen --out <prefix>
- xerj corpus index <name> [--fresh] [--url URL]
+ xerj corpus index <name> [--fresh] [--url URL] [--include-data]
(can outlive an agent tool timeout; stopping is safe, re-run to resume)
xerj corpus list [--url URL]
@@ -250,7 +250,10 @@ refuses the pack on failure (for a pack.zip, the sig cannot travel inside
is where the lookup falls back to); build harvests recipe sources into a
deterministic pack under builds/<name>/ (see tools/xerj-code/); sign/keygen
are the publish step (ed25519 over SHA256SUMS);
-index builds/verifies/switches the corpus (exit 3 skips junk — normal);
+index builds/verifies/switches the corpus (exit 3 skips junk — normal); it
+skips CSV/HDF/simulation output by default (reference corpora are code and
+docs, and a test-output folder can out-record the whole corpus) —
+--include-data indexes those files too, reporting how many were left out;
list shows what is loaded on this node.";
pub(crate) fn git(dir: Option<&Path>, args: &[&str]) -> Result<(i32, String)> {
@@ -1405,44 +1408,64 @@ pub(crate) fn corpus_index_duration_note() -> &'static str {
background and wait for the xerj-done line."
}
-fn run_corpus_index(args: &[String]) -> i32 {
- let mut name: Option<String> = None;
- let mut fresh = false;
- let mut url: Option<String> = None;
+/// Parsed `xerj corpus index` arguments, separated from the run so the flag
+/// set (including #1985's `--include-data`) is testable without a node.
+#[derive(Debug, Default, PartialEq)]
+struct CorpusIndexArgs {
+ name: Option<String>,
+ fresh: bool,
+ include_data: bool,
+ url: Option<String>,
+ help: bool,
+}
+
+fn parse_corpus_index_args(args: &[String]) -> Result<CorpusIndexArgs, String> {
+ let mut out = CorpusIndexArgs::default();
let mut i = 0;
while i < args.len() {
match args[i].as_str() {
"-h" | "--help" => {
- println!("{CORPUS_USAGE}");
- return 0;
+ out.help = true;
+ return Ok(out);
}
- "--fresh" => fresh = true,
+ "--fresh" => out.fresh = true,
+ // #1985: CSV/HDF/simulation output is skipped by default in a
+ // reference corpus; this flag indexes it anyway.
+ "--include-data" => out.include_data = true,
"--url" => match args.get(i + 1) {
Some(v) => {
- url = Some(v.clone());
+ out.url = Some(v.clone());
i += 1;
}
- None => {
- eprintln!("xerj corpus index: --url needs a value\n\n{CORPUS_USAGE}");
- return 2;
- }
+ None => return Err("--url needs a value".into()),
},
- a if a.starts_with('-') => {
- eprintln!("xerj corpus index: unknown flag '{a}'\n\n{CORPUS_USAGE}");
- return 2;
- }
- a if name.is_none() => name = Some(a.to_string()),
- a => {
- eprintln!("xerj corpus index: unexpected argument '{a}'\n\n{CORPUS_USAGE}");
- return 2;
- }
+ a if a.starts_with('-') => return Err(format!("unknown flag '{a}'")),
+ a if out.name.is_none() => out.name = Some(a.to_string()),
+ a => return Err(format!("unexpected argument '{a}'")),
}
i += 1;
}
- let Some(name) = name else {
+ Ok(out)
+}
+
+fn run_corpus_index(args: &[String]) -> i32 {
+ let parsed = match parse_corpus_index_args(args) {
+ Ok(p) => p,
+ Err(e) => {
+ eprintln!("xerj corpus index: {e}\n\n{CORPUS_USAGE}");
+ return 2;
+ }
+ };
+ if parsed.help {
+ println!("{CORPUS_USAGE}");
+ return 0;
+ }
+ let Some(name) = parsed.name else {
eprintln!("xerj corpus index: <name> is required\n\n{CORPUS_USAGE}");
return 2;
};
+ let fresh = parsed.fresh;
+ let include_data = parsed.include_data;
if let Err(e) = xccode::pathgate::valid_corpus_name(&name) {
eprintln!("xerj corpus index: {e}");
return 2;
@@ -1457,7 +1480,7 @@ fn run_corpus_index(args: &[String]) -> i32 {
return 2;
}
eprintln!("{}", corpus_index_duration_note());
- let url = resolve_url(url.as_deref());
+ let url = resolve_url(parsed.url.as_deref());
let es = match build_es(&url, None) {
Ok(es) => es,
Err(e) => {
@@ -1467,7 +1490,9 @@ fn run_corpus_index(args: &[String]) -> i32 {
};
corpus_index_flow(
&es,
- &|prefix, state_dir| crate::run_with_options(&dir, &url, prefix, state_dir, true),
+ &|prefix, state_dir| {
+ crate::run_with_options(&dir, &url, prefix, state_dir, true, include_data)
+ },
&stamp_secs,
&root,
&url,
@@ -2171,6 +2196,30 @@ mod tests {
assert_eq!(code, 0);
}
+ /// #1985: `--include-data` is the opt-out of the corpus data-file gate.
+ /// Parsing is separated from the run so this needs no node.
+ #[test]
+ fn corpus_index_parses_include_data() {
+ let p = parse_corpus_index_args(&["--include-data".into(), "repo".into()]).unwrap();
+ assert!(p.include_data && !p.fresh && !p.help);
+ assert_eq!(p.name.as_deref(), Some("repo"));
+
+ let p = parse_corpus_index_args(&[
+ "--fresh".into(),
+ "repo".into(),
+ "--url".into(),
+ "http://127.0.0.1:9200".into(),
+ ])
+ .unwrap();
+ assert!(p.fresh && !p.include_data);
+ assert_eq!(p.url.as_deref(), Some("http://127.0.0.1:9200"));
+
+ assert!(parse_corpus_index_args(&["--nope".into()]).is_err());
+ assert!(parse_corpus_index_args(&["repo".into(), "extra".into()]).is_err());
+ assert!(parse_corpus_index_args(&["--url".into()]).is_err());
+ assert!(parse_corpus_index_args(&["--help".into()]).unwrap().help);
+ }
+
#[test]
fn corpus_index_says_a_tool_timeout_is_not_a_failed_index() {
let note = corpus_index_duration_note();
diff --git a/engine/crates/xerj-server/src/brain.rs b/engine/crates/xerj-server/src/brain.rs
index 35b809dff..d13d51bf6 100644
--- a/engine/crates/xerj-server/src/brain.rs
+++ b/engine/crates/xerj-server/src/brain.rs
@@ -652,6 +652,7 @@ fn index_cfg(cfg: &BrainCfg, brain: &str, api_key: Option<String>) -> IndexCfg {
label: None,
debounce: std::time::Duration::from_millis(0),
exclude_rels: Vec::new(),
+ skip_corpus_data: false,
}
}
diff --git a/tools/xerj-code/README.md b/tools/xerj-code/README.md
index 8c66cc49f..a6cf7dfa5 100644
--- a/tools/xerj-code/README.md
+++ b/tools/xerj-code/README.md
@@ -15,9 +15,17 @@ not shipped at all.)
xerj corpus add xerj-storage https://github.com/spacejam/sled … # clone the peers, once
xerj corpus index xerj-storage # xerj autoindex; re-run to update in place
xerj corpus index xerj-storage --fresh # rebuild beside the old index, verify, then swap
+xerj corpus index xerj-storage --include-data # also index CSV/HDF/simulation output (skipped by default)
xerj code xerj-storage "how does sled fsync its WAL segment on rotation?"
```
+A reference corpus is code and docs. Test outputs and datasets (CSV, HDF5,
+Parquet, simulation dumps) are skipped by default because they can out-record
+the whole corpus — one test folder in the
+[field report](https://github.com/xerj-org/xerj/issues/1979) produced 636,724
+records. The run prints how many files and bytes it left out; `--include-data`
+indexes them anyway.
+
Or rebuild a corpus someone else already defined and vetted:
```sh