Skip to content

fix: cap max passage length to prevent cascading window merges#67

Merged
asvarnon merged 2 commits into
mainfrom
fix/passage-length-cap
Apr 4, 2026
Merged

fix: cap max passage length to prevent cascading window merges#67
asvarnon merged 2 commits into
mainfrom
fix/passage-length-cap

Conversation

@asvarnon

@asvarnon asvarnon commented Apr 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds max_passage_sentences to ExtractionConfig (default: 6)
  • After window merging, ranges exceeding the cap are split at sentence boundaries
  • Each split chunk re-evaluates which triggering terms are present (no blind inheritance)
  • Chunks with no matching terms are discarded

Context

Post-classification validation (#49) showed passage length explosion (309 → 3,037 chars avg) causing corrective (19% → 42.5%) and decisive (2% → 17.5%) false positive spikes. The classifiers are calibrated for ~300-char passages — this fix restores that granularity.

Review

  • Codex implementation
  • Review Agent — engineering quality
    • W-1: Pre-compute lowercased sentences in collect_terms_in_range (perf fix)
    • W-2: Document triggering_terms re-evaluation semantics
    • N-1: Simplify cap=0 guard to .max(1)
    • N-2: Remove dead dedup() call
    • N-3: Add debug_assert for chunk bounds

Test plan

  • Passages under cap unchanged (existing tests pass)
  • Over-cap passages split correctly (extract_over_cap_splits_into_multiple_passages)
  • Cap=0 degenerates to per-sentence (extract_cap_zero_emits_single_sentence_passages)
  • Term re-evaluation per chunk (extract_split_re_evaluates_triggering_terms_per_chunk)
  • Empty chunks discarded (extract_split_discards_chunks_without_matching_terms)
  • cargo test --workspace passes (166 tests)
  • cargo clippy --workspace -- -D warnings passes
  • cargo fmt --all passes

Post-classification validation showed context extraction producing 3,037-char
average passages (10x prior runs) due to cascading window merges in large entries.
Long passages cause proximity-based classifiers (corrective, decisive) to degrade
to random co-occurrence. Adds max_passage_sentences config (default 6) that splits
over-long merged ranges at sentence boundaries, with per-chunk term re-evaluation.

Review Agent fixes applied:
- W-1: Pre-compute lowercased sentences in collect_terms_in_range (perf)
- W-2: Document triggering_terms re-evaluation semantics
- N-1: Simplify cap=0 guard to .max(1)
- N-2: Remove dead dedup() call
- N-3: Add debug_assert for chunk bounds

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a configurable cap on extracted passage length (in sentences) to prevent oversized merged windows, keeping passage granularity aligned with classifier calibration.

Changes:

  • Introduces max_passage_sentences on ExtractionConfig (default 6).
  • Splits merged extraction ranges into sentence-boundary chunks when they exceed the cap.
  • Re-evaluates triggering_terms per split chunk and drops chunks with no matching terms; adds tests for the new behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/analysis/src/extraction.rs
Comment thread crates/analysis/src/extraction.rs
Comment thread crates/analysis/src/extraction.rs
C1: Document chunk discard behavior and context_window interaction
C2: Restore dedup() in collect_terms_in_range for defensive duplicate handling
C3: Expand debug_assert to check start bounds and start <= end invariant
@asvarnon asvarnon merged commit 95c8a61 into main Apr 4, 2026
11 checks passed
@asvarnon asvarnon deleted the fix/passage-length-cap branch April 4, 2026 01:58
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.

2 participants