Repository navigation
autoindex: stemming analyzer by default for profiler-marked semantic prose (#1059) - #1070
Merged
Merged
Conversation
…prose (#1059) Motivation Issue #1059 (discussion #1054, item 9). The profiler already knows which datasets carry natural-language prose -- `FieldAcc::looks_natural_language` (word_ratio >= 0.55 && mean_tokens >= 3.0) is the same measured predicate that gates the semantic-body election, and it separates prose from identifiers reliably (measured word_ratio: 0.00 for trace_id/user_id/ numerics, 0.78-1.00 for prose). But the lexical arm of every index autoindex creates analyses with the `standard` analyzer, which does not stem, so on the BEIR NFCorpus arm 7 of 323 queries return zero hits purely because the query holds a plural whose singular is in the corpus ("bagels"). #991 made a declared `settings.analysis.analyzer.default` honoured at flush, segment query and merge; nothing in autoindex declared one. This wires the election to the create path. What changed - infer/mod.rs: `STEMMING_TEXT_ANALYZER` ("stemmer") and `elected_default_analyzer(specs, fields)` -- Some("stemmer") when any text/semantic_text field passes looks_natural_language. "stemmer" over "english" deliberately: "stemmer" is standard + lowercase + Snowball English and nothing else; "english" additionally drops stop words, which changes every document's BM25 length norm -- a scoring change, not just a recall change. The election does not consult no_semantic: stemming is a lexical-arm property, and a --no-semantic run is the run whose retrieval is all lexical. - state.rs: `PlanDataset.text_analyzer: Option<String>` with serde(default). It rides the PLAN, not FieldSpec: generation_contract_ identities hashes `dataset.specs` verbatim into schema_identity, so a serialized spec field would move that digest and abort the next run of every existing state dir on the incremental no-change arm. The digests read PlanDataset through named keys only, so a field here is invisible to them. Legacy plans deserialize None -- the honest value for an index that already exists unstemmed. - lib.rs: `dataset_create_body(dataset)` -- build_mapping + ax_paths, plus `settings.analysis.analyzer.default` when the marker is set. Used by both create paths (install_dataset_mappings on the generated route, run_index_report_inner on the legacy graph route). The declaration is outside build_mapping because that value is hashed into index_identity; the marker on the plan means a pending generation replayed after a restart still declares the analyzer. - esclient: unchanged code, new wire-level test proving the analyzer lands beside settings.index.xerj_ingest_shards (with_single_wal_shard is the precedent for a create-only setting outside the frozen contract). - catalog.rs: a GOTCHAS line stating the new behaviour and its boundary: keyword fields never stem, indexes an older build created keep `standard`, analysis settings are fixed at creation. - docs/ZERO_TOKEN_DIRECTION.md: the #937 bullet now records that autoindex turns stemming on by default for new semantic-prose indexes. New-indexes-only is by construction, not by check: analysis setti 8000 ngs are immutable server-side after creation, and Es::ensure_index tolerates resource_already_exists without re-sending the body, so an index that already exists is untouched. Tests - elected analyzer: prose dataset elects stemmer, id/enum dataset does not; --no-semantic prose still elects; prose on a keyword-typed field does not elect. - create body: semantic dataset declares /settings/analysis/analyzer/default/type == "stemmer" with mappings byte-identical to an undeclaring dataset and no per-field analyzer key (the accepted-and-ignored surface); non-semantic dataset sends no settings; legacy plan JSON deserializes None and sends no settings. - frozen identities: flipping text_analyzer None->Some leaves generation_contract_identities unchanged (pin against the #755 upgrade-abort class). - wire: PUT body carries both the analyzer and the WAL-shard setting. Also init.rs: second_run_is_idempotent now takes ENV_LOCK across its two runs. Root cause of the flake my new tests exposed: run_init_in reads process-global HOME to decide whether the Claude skill is in scope, and the auth-note Sandbox tests swap HOME under that lock; without holding it, one of them could land between this test's two runs and flip the skill line from "kept" to "wrote". Pre-existing race, scheduling- dependent, not an idempotency failure. cargo test -p xerj-autoindex: 1172 passed, 0 failed. cargo clippy --all-targets -p xerj-autoindex: clean. cargo fmt applied. Reference-code note: the xerj-code corpora are unavailable in this sandbox (reset 2026-09-29), so retrieval was not run; the in-repo precedent followed is #991's settings.analysis.analyzer.default surface and with_single_wal_shard (esclient.rs) as the create-only-settings pattern outside the frozen contract. No engine code is touched: the ES-YAML 0-failed gate is CI's ES-compat job on this PR, and the BEIR/NFCorpus zero-hit measurement is the release-time gate and remains open.
Records #1059 under Changed: autoindex declares the built-in Snowball `stemmer` analyzer as settings.analysis.analyzer.default on every index it CREATES when the profiler marked the dataset's prose semantic (the word_ratio/mean_tokens predicate that also gates the embedding election), what that does and does not touch (keyword fields, identifier datasets, existing indexes, the frozen identity hashes), and that the BEIR/NFCorpus zero-hit measurement remains the release-time gate.
This was referenced Sep 30, 2026
neoneye
pushed a commit
to agent-memory-atlas-archive/xerj-org--xerj
that referenced
this pull request
Oct 1, 2026
…FAIL), BM25 +0.0160/+0.0179 (PASS) Motivation: issue xerj-org#1059 (rc.79) ships stemming-by-default via PR xerj-org#1070 and binds a release gate: "NFCorpus zero-hit queries 25 -> <=10; BEIR BM25 >= +0.01 over 0.657 SciFact / 0.302 NFCorpus." PR xerj-org#1070 measured nothing on the BEIR arms (its motivation figure is the published docs/ZERO_TOKEN_DIRECTION.md number); this is that measurement, on the release binary. Method: release binary (version string "xerj v1.0.0-rc.78", main @ a179e1e, which includes the xerj-org#1070 merge), one node on private port 9620, --insecure --embed-mode lexical, throwaway data dir. BEIR SciFact + NFCorpus downloaded from the URLs this README already uses (sha256s in run-meta.txt). Four indexes on one node — {scifact,nfcorpus} x {std,stem} — differing only in the create-time PUT: the stem arm declares settings.analysis.analyzer.default {"type":"stemmer"} (the exact xerj-org#1070/xerj-org#991 surface, added to the load step by load_stem.py exactly as xerj-org#1070's PR body anticipated); the std arm is the plain rc.74 baseline path. eval_bm25.py replays eval.py's bm25 arm verbatim (default-OR multi_match on title+text, size=100, graded nDCG@10) and writes one raw line per test query. Numbers (paired, same binary/node/datasets): - std arm reproduces the rc.74 published row EXACTLY: SciFact 0.6572 (300 q), NFCorpus 0.3016 (323 q), zero-hit 25 — same 25 qids as the committed results/nfcorpus-lexical-gap.txt list. - stem arm: SciFact 0.6732 (+0.0160), NFCorpus 0.3195 (+0.0179) — both clear +0.01: sub-gate B PASS. - NFCorpus zero-hit 25 -> 15: sub-gate A FAIL (needed <=10). Stemming fixed exactly the 10 inflection-class queries (bagels, leeks, pineapples, turnips, whiting, deafness, antinutrients, airport scanners, canker sores, Alli); the remaining 15 are single words whose stem also occurs nowhere in the corpus (Fosamax, Zoloft, Mevacor, Splenda, eggnog, halibut, mesquite, okra, taro, amnesia, myelopathy, Peoria, Tufts, Yale, Czechoslovakia) — not bridgeable by any stemmer; recorded, not tuned. Caveats recorded in gate-summary.txt: GET _settings does not echo the analysis block and _analyze shows the standard token path even on the stem arm, while search provably honours the declared default (std "bagels" 0 hits / stem 1 hit) — an observed display gap; latencies are wall-clock on a shared 32-core sandbox and are not gate inputs. File pointers: benchmarks/beir-hybrid/{load_stem.py,eval_bm25.py}, results/2026-09-30-stemming-1059/{gate-summary.txt,run-meta.txt, <ds>-<arm>-bm25.tsv x4, <ds>-<arm>-summary.txt x4}, README.md stem-gate section.
neoneye
pushed a commit
to agent-memory-atlas-archive/xerj-org--xerj
that referenced
this pull request
Oct 1, 2026
The packaging half of the ten-item program's rule (discussion xerj-org#1054): a benchmarks/<name> directory with raw results plus a blog post with the losses left in. The gate directories landed through xerj-org#1079, xerj-org#1085, xerj-org#1086, xerj-org#1087, xerj-org#1088 and xerj-org#1090; this is the post. Structure follows the Jev posts (verdict first, wins then losses with readings, then what the next window does about each loss). Every number is verbatim from the committed gate artifacts: - PASS: /_ask macro-F1 0.9975 over 230 pairs, 0 invalid DSL, 3-run determinism, wall-clock p50 1.129 ms vs the 300 ms bar (xerj-org#1076, xerj-org#1079); xerj_map unknown-field 400s 20/30 guessed -> 0/30 map-informed, 100% vs the >=80% bar (xerj-org#1074, xerj-org#1086); calibration FiQA pair-level ECE 0.3109 raw -> 0.0088 held-out vs the <=0.10 bar, temperature 0.3163 published as the failing comparison arm, $0.2125 of provider calls over 648 queries (xerj-org#1080, xerj-org#1087). - FAIL, published as such: the lexical judge loses to its own first stage everywhere measured (0.7045->0.5967, 0.3419->0.2924, 0.2382->0.1650 vs the 0.30 FiQA bar) and stays opt-in with no quality claim per its own rule (xerj-org#1077, xerj-org#1090); the flywheel freezes as shipped (12 of 2,000 cached, xerj-org#1094) and forces 19.72% coverage at 0.9953 accuracy vs the 80%/0.97 bars (xerj-org#1075, xerj-org#1088); the tier-2 decide head misses SMS 0.9193/0.287 vs 0.95/0.05 and AG News 0.2599 vs 0.85, latency 8.4 ms PASS, ships behind the flag with the numbers published (xerj-org#1072/xerj-org#1073, xerj-org#1088). - SPLIT: stemming +0.0160/+0.0179 BM25 nDCG@10 PASS, zero-hit 25->15 vs <=10 FAIL — the 15 have no stem anywhere in the corpus (xerj-org#1070, xerj-org#1085). - The gate that caught the stock release binary built without the decide-local cargo feature (flag a no-op, stock-binary-noop.txt) is told with the fix queued ahead of the cut, not claimed as done. - Honest gaps stated, not smoothed: the /_ask token arm designed not run, the _watcher detection gate not yet measured, no HF URL for xerj-decide-v1. Four issues filed from the measurements: xerj-org#1091-xerj-org#1094. Mechanics: hand-written page at landing/blog/the-rc80-gates.html, registered in scripts/seo/pagedata.py (published/updated 2026-09-30), card prepended to the blog hub (hub dateModified bumped), head and footer owned by fix_heads/fix_links, og falls back to the site card.
7 of 8 tasks
Ravandevil25
pushed a commit
to Ravandevil25/xerj
that referenced
this pull request
Oct 6, 2026
…pelines in _analyze (xerj-org#1092) Motivation. Search honours a declared `analysis.analyzer.default`, but nothing an agent can read over the ES wire said so, so an agent verifying "is my stemmer on?" concluded it was off. Root cause, two halves: 1. `GET /{index}/_settings` and `GET /{index}` replay `engine.index_settings`, an in-memory display copy of the create body that is never reloaded at boot. After a restart it is empty and every create-time setting, analysis included, vanished from the response. A top-level `analysis` beside an `index` block was never echoed even before a restart (merge_settings_defaults takes the `index` block only). 2. `POST /{index}/_analyze` ignored the index entirely: an inline lowercase splitter (`tokenize_for_analyze`) answered every request, whatever the analyzer, field or ad-hoc chain. Fix. - Engine: `Index` keeps the `AnalysisBinding` its registry was built with. `analysis_in_force()` returns the block actually honoured, so a pre-xerj-org#204 index whose canonical block is NOT honoured reports none. `analyze(analyzer, field, text)` resolves the way the FTS writer does: text field -> segment text analyzer (xerj-org#937), other mapped types -> keyword, unmapped -> default else standard, no field -> the index default. - API: both settings responses fall back to the persisted settings.json when the display copy is gone, and report `index.analysis` from `analysis_in_force()`. `_analyze` uses the index's registry; the global endpoint uses the built-ins. Ad-hoc tokenizer/filter/char_filter chains (names or inline definitions) are built into a one-off custom analyzer by the same registry and `unsupported_analysis` gate index creation uses, with `keyword` as the tokenizer when only filters are given. Unknown analyzer/tokenizer/filter, `field` on the global endpoint and `normalizer` are 400 illegal_argument_exception; a missing index is 404. - es-yaml-runner learns `indices.analyze`. New case indices.analyze/10_analysis_in_force.yml asserts the error explicitly because the runner does not enforce `catch`. Evidence (verified): - New xerj-api test file (5 tests) fails 4/4 on upstream sources (the restart one fails at the post-restart assertion) and passes 5/5 with the fix. Added engine assertions in the xerj-org#204/xerj-org#937 integration tests pass. - New YAML case: 6/6 on this build, 6/6 on OpenSearch 3.9.0, 2/6 on an rc.83 build without the fix. - Side by side, OpenSearch 3.9.0 (opensearchproject/opensearch:latest) vs this build, 24 requests (settings, GET index, analyze by default, field, named analyzer, global built-ins, ad-hoc chains, errors): identical status codes, error types, tokens, offsets and positions. The 4 settings probes also match after a xerj restart. Only the reason text differs on 3 of the 400s. - ES-YAML gate: 1379 passed, 0 failed, 4 skipped. - cargo fmt --all --check clean; clippy -D warnings clean on xerj-fts, xerj-engine, xerj-api, es-yaml-runner. - cargo test: xerj-fts all pass; xerj-engine 1217 passed, 4 failed; xerj-api 3 failed in snapshot_is_not_a_way_around_a_brain. All 7 failures are snapshot-path tests that fail identically on upstream sources on this macOS host (/var vs /private/var). Known divergences, not changed here: the token `type` stays `word` (OpenSearch says `<ALPHANUM>` for the standard tokenizer); `explain` keeps its previous output on the global endpoint and is refused for ad-hoc chains; `{"type":"stemmer"}` as an ANALYZER type (xerj-org#1070) is a xerj extension that OpenSearch rejects. Written by an AI agent (Claude Code) for the account that opens the PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1059 (discussion #1054, item 9).
Motivation
The profiler already knows which datasets carry natural-language prose:
FieldAcc::looks_natural_language(word_ratio >= 0.55 && mean_tokens >= 3.0, engine/crates/xerj-autoindex/src/infer/mod.rs:126) is the same measured predicate that gates the semantic-body election, and it separates prose from identifiers reliably — measuredword_ratio0.00 fortrace_id/user_id/numerics, 0.78–1.00 for prose, log messages and source code (doc comment at infer/mod.rs:64).But the lexical arm of every index
xerj autoindexcreates analyses with thestandardanalyzer, which does not stem. On the BEIR NFCorpus arm, 7 of 323 queries return zero hits purely because the query holds a plural whose singular is present in the corpus (bagels). #937 (fixed by #991) made a declaredsettings.analysis.analyzer.defaulthonoured at flush, at segment query and at merge — and nothing declared one. This PR wires the election to the create path.Design decisions
The surface:
settings.analysis.analyzer.default, not a per-field mappinganalyzer. The per-fieldanalyzerin a mapping is the accepted-and-ignored surface the #937 audit named as still open; the declared default is the surface #991 made real end-to-end. The unit of the declaration is therefore the INDEX: everytext/semantic_textfield of a created index analyses one way for its whole life, and keyword fields keep the whole-valuekeywordanalyzer regardless.stemmer, notenglish.stemmeris the built-instandardpipeline (Unicode word split + lowercase) plus Snowball English and nothing else — the minimal term-space delta: plurals and inflections collapse onto their stems.englishwas considered and rejected as the default because it additionally drops stop words, which changes every document's BM25 length norm — a scoring change, not just a recall change, and one that would have to be re-measured against the same BEIR arms before it could be honest.The election is the same predicate as the embedding election.
Some("stemmer")when at least one field the profiler typedtext/semantic_textpasseslooks_natural_language; identifier/enum/numeric datasets keepstandard's exact term space. It does NOT consultno_semantic: stemming is a lexical-arm property (BM25 recall on plurals), and a--no-semanticrun is precisely the run whose retrieval is all lexical.Frozen-identity safety (the load-bearing part).
build_mapping's value is hashed into every committed generation'sindex_identity, anddataset.specsintoschema_identity(generation_contract_identities, lib.rs). Declaring the analyzer inside either would move the digests and abort the next run of every existing state dir on the incremental no-change arm — the exact #755 upgrade-abort class the frozen-contract work removed. Instead:dataset_create_body), outside both hashes — pinned by a test that flips the marker and asserts the identities do not move;PlanDataset.text_analyzer(serde(default)), which the identity digests read through named keys only, so a new field there is invisible to them.Existing indexes untouched, by construction. Analysis settings are immutable server-side after creation (a settings PUT naming
analysisis refused), andEs::ensure_indextoleratesresource_already_existswithout re-sending the body — so an index an earlier run or an older build created keepsstandard, its term space and its postings. Only an index THIS build creates gets the stemmer. Riding the plan also means a pending generation replayed after a restart still declares the analyzer (the journal round-trip is pinned by test).Create-only settings outside the frozen contract have in-repo precedent:
with_single_wal_shard(esclient.rs) addssettings.index.xerj_ingest_shardsthe same way; a wire-level test proves the two compose under onesettingsobject on the socket.What changed, file by file
engine/crates/xerj-autoindex/src/infer/mod.rs—STEMMING_TEXT_ANALYZERconst +elected_default_analyzer(specs, fields); 3 unit tests (prose elects / id-enum does not;--no-semanticprose still elects; prose on a keyword-typed field does not elect).engine/crates/xerj-autoindex/src/state.rs—PlanDataset.text_analyzer: Option<String>withserde(default, skip_serializing_if), doc comment explaining why it rides the plan and notFieldSpec.engine/crates/xerj-autoindex/src/lib.rs—dataset_create_body(dataset)(frozen mapping +ax_paths+ the analyzer settings when elected), used by BOTH create paths:install_dataset_mappings(generated route) andrun_index_report_inner(legacy graph route);build_phase_arecords the election from the same sampled accumulators that elected the semantic body; newstem_default_testsmodule (3 tests) and a frozen-identity pin ingeneration_contract_identity_tests.engine/crates/xerj-autoindex/src/esclient.rs— code unchanged; wire-level test asserting the PUT body carries/settings/analysis/analyzer/default/type == "stemmer"beside/settings/index/xerj_ingest_shards == 1.engine/crates/xerj-autoindex/src/catalog.rs— a GOTCHAS line stating the behaviour and its boundary (keyword fields never stem; indexes an older build created keepstandard; analysis settings are fixed at creation — reindex into a fresh index to change them).engine/crates/xerj-autoindex/src/init.rs— drive-by flake fix, see below.docs/ZERO_TOKEN_DIRECTION.md— the A declared analyzer stops applying at _flush: analysis.analyzer.default is memtable-only, a per-field analyzer is accepted and ignored, an unknown analyzer name is accepted #937 bullet records that autoindex now turns stemming on by default for NEW semantic-prose indexes.text_analyzer: Noneinserted in existingPlanDatasetliterals (21 sites).Drive-by flake fix (init.rs)
second_run_is_idempotentfailed in my branch's full-suite run (passed alone; clean tree also passed 1130/0) — a pre-existing race my 7 new tests' scheduling exposed.run_init_inreads process-globalHOMEviadirs_home()to decide whether the Claude skill is in scope; the auth-noteSandboxtests swapHOMEunderENV_LOCK, and this test did not hold that lock, so a sandboxed test landing between its two runs flipped the skill line from "kept" to "wrote". Fixed by takingENV_LOCKacross both runs, with a comment. Scheduling-dependent, not an idempotency failure.Tests run
cargo test -p xerj-autoindex: 1172 passed, 0 failed (includes the 8 new tests).cargo clippy --all-targets -p xerj-autoindex --release: clean.cargo fmt -p xerj-autoindex: applied, no diff.Reference-code mandate note
The
xerj codecorpora are unavailable in this sandbox (reset 2026-09-29), so retrieval was not run. The in-repo precedent followed instead: #991'ssettings.analysis.analyzer.defaultsurface (the honoured path) andwith_single_wal_shardas the create-only-settings-outside-the-frozen-contract pattern.What remains to the issue's gate
benchmarks/beir-hybrid(which creates its indices directly by PUT, not through autoindex, so the arm needs the settings added to its load step). The 7-plural-zero-hit motivation figure is the already-published measurement in docs/ZERO_TOKEN_DIRECTION.md, not a new number from this PR.