Skip to content

feat: add shared Rust level-one normalizer and pyo3 batch surface - #171

Merged
SkyeAv merged 1 commit into
mainfrom
stronger-l1/rust-core
Sep 15, 2026
Merged

SkyeAv merged 1 commit into
mainfrom
stronger-l1/rust-core

Conversation

@SkyeAv

@SkyeAv SkyeAv commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Adds the shared Rust level-one normalizer — clean → Unicode lowercase → Snowball English (Porter2) stemming of all-ASCII-alphabetic tokens → dedupe → byte-wise sort → single-space join — plus a rayon-parallel, GIL-releasing pyo3 batch surface, as the foundation for stronger fullmap matching.

Normalizer (rust/src/nlp.rs)

  • normalize_l1: returns Cow<str> with a zero-copy borrowed fast path for already-clean single tokens; digit-bearing (51), punctuation-bearing (tnf-alpha), and non-ASCII tokens pass through unstemmed after lowercasing.
  • Shared cleaning: clean_and_lower in rust/src/fullmap.rs becomes pub(crate) and is reused verbatim by nlp, so cleaning semantics literally cannot drift from the fullmap emit path.
  • Unit tests: 12 cases with WHY comments — reorder, dedupe, whitespace collapse, stemming folds (genesgene, inhibitinginhibit), digit/punctuation pass-through, Unicode lowercase, empty string, Cow borrow fast path.

pyo3 surface

  • normalize_terms: index-aligned batch function, rayon-parallel, releases the GIL via py.detach (pyo3 0.29); registered in rust/src/lib.rs, stubbed in src/tablassert/rs.pyi.
  • normalize_l1 re-export: plain Rust export for the fullmap build side (landed in a later PR of this stack) and integration tests; intent documented at the export site.

Design

  • rust-stemmers = "1" (docs.rs): pure-Rust Snowball implementations (English = Porter2), MIT/BSD-3 with only serde deps, Send+Sync fn-pointer stemmer shared via OnceLock, Cow-returning stem. Rejected alternatives: PyStemmer/snowballstemmer (Python-side cost), lemmatizers (dictionary weight, no throughput), pure-polars token chains (measured ~25× slower: 0.8M rows/s vs 20.5M).
  • Deferred: lemmatization (dictionary weight vs. throughput) and stop-word removal (precision); no per-column opt-out exists today.

Testing

  • cargo test --manifest-path rust/Cargo.toml nlp12 passed
  • cargo test --manifest-path rust/Cargo.toml --lib124 passed
  • cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings → clean
  • cargo fmt --check → clean

- rust/src/nlp.rs: normalize_l1 (clean -> Unicode lowercase -> Snowball English/Porter2 stem of all-ASCII-alphabetic tokens -> dedupe -> byte-sort -> space-join) returning Cow, with a zero-copy borrowed fast path for unchanged single tokens
- #[pyfunction] normalize_terms: index-aligned, rayon-parallel, GIL-released batch surface registered in lib.rs, stubbed in rs.pyi
- clean_and_lower made pub(crate) and reused verbatim by nlp so cleaning semantics cannot drift from the fullmap emit path
- rust-stemmers = "1" (MIT/BSD-3, serde-only deps) added with rationale
- 12 unit tests: reorder, dedupe, whitespace collapse, stemming folds, digit/punctuation pass-through, unicode lowercase, empty, Cow borrow fast path

Verified: cargo test nlp (12 passed), cargo test --lib (124 passed), cargo clippy --all-targets -D warnings clean, cargo fmt clean.
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: fb6d7e01-2249-4f9f-bbd7-c8ace34bba79


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SkyeAv
SkyeAv added this pull request to stack #177 September 15, 2026 17:41
@SkyeAv SkyeAv changed the title stronger l1/rust core feat: add shared Rust level-one normalizer and pyo3 batch surface Sep 15, 2026
@SkyeAv
SkyeAv marked this pull request as ready for review September 15, 2026 17:42
@SkyeAv
SkyeAv removed this pull request from stack #177 September 15, 2026 17:50
@SkyeAv
SkyeAv added this pull request to stack #179 September 15, 2026 17:51
@SkyeAv
SkyeAv merged commit cc755c2 into main Sep 15, 2026
5 checks passed
SkyeAv added a commit that referenced this pull request Sep 15, 2026
Cut 19.0.0 and bump the package version in pyproject.toml, CITATION.cff,
and uv.lock.

Major: five breaking changes ship. The `tablassert` console command now
requires the optional `[cli]` extra, since `cyclopts` and `rich` left the
base install (#187). Level-one normalization redefines fullmap keys as
cleaned Unicode-lowercase, Porter2-normalized, byte-ordered token sets and
moves the database to schema v6, so every schema-v5 fullmap is rejected and
must be rebuilt (#171, #172, #174, #175, #176). `build-fullmap --aria2c`
is gone -- aria2c is used automatically whenever the `[aria2]` extra is
installed (#178) -- and `--taxon-allowlist` is gone because the built-in
top-100 experimental-taxon allowlist now applies to every build, guarding
both reuse paths by `META.taxon_allowlist` identity (#153). Logging now
requires the `[log]` extra and is fully disabled without it (#152).

Features: `tablassert.net` is a new stdlib-only transient/permanent
classification and retry seam shared by the agent and the BABEL downloader
(#163, #164), with one bounded jittered retry layer across the inner agent,
reflexion, and judge (#167) and machine-readable `error_code` values on
skipped checkpoint records (#166). `build-kg` gained an automatic ephemeral
shared-prefix TCode cache keyed by content-addressed XXH64 op digests
(#155-#159, #161). The `--distill` corpus became schema-uniform v2 with a
sibling `outcomes.ndjson`, a deterministic `RewardConfig`-tunable reward,
and the new zero-dependency `tablassert distill-weigh` command (#180-#183).
`CLASS_FIELD_OVERRIDES` grants the DAKP sparse qualifier stack on the pinned
association classes (#188).

Fixes: `distill-export` partitions its corpus by content and unions the
schema across record files, so a mixed v1/v2 directory no longer CastErrors
or silently stringifies a column (#184); BABEL retry warnings survive the
loguru sink; PMC downloads are idempotent, atomic, and bounded-parallel
(#165); reflexion and judge prompts are hard-bounded (#168).

Changelog:
- versioned the Unreleased section as 19.0.0 - 2026-09-15
- merged three duplicate `### Added` blocks into one
- moved the two `BREAKING:` entries from `### Changed` into
  `### Breaking Changes` and added a `**Migration:**` note to all five
- added PR links to all 17 entries, which carried none
- added the missing entries: the distill v2 corpus/reward/distill-weigh
  stack (#180-#183), the distill-export schema-drift fix (#184), the
  TCode run-cache detail (#155-#161), and the README badge removal (#154)

Docs: none needed here. Every shipped doc change landed with its own PR,
and the docs source-of-truth gate passes against the bumped tree.

Testing:
- make check -> exit 0
- uv run ruff check . -> All checks passed!
- uv run pyright -> 0 errors, 0 warnings, 0 informations
- uv run pytest -> 1622 passed, 52 skipped
- cargo test --manifest-path rust/Cargo.toml -> 156 passed, 0 failed
- cargo clippy --all-targets -- -D warnings -> clean
- uv lock --check -> resolved 169 packages, lock current
- uv run mkdocs build --strict -> exit 0
- docs SSOT + CLI coverage after the changelog edit -> 204 passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant