Skip to content

feat(ingest): markdown parsers + heading/fixed chunkers with token bounds (T06) - #11

Merged
prateekchaplot merged 1 commit into
mainfrom
arch/caliper/t06
Nov 17, 2026
Merged

prateekchaplot merged 1 commit into
mainfrom
arch/caliper/t06

Conversation

@prateekchaplot

Copy link
Copy Markdown
Owner

Task T06 from docs/ARCHITECTURE.md §14.2 (spec §7.4).

What

  • ingest/parse.py (new): parse_page(rel_path, text) -> ParsedPage — page title = first ATX H1; BodySegment(heading_path, level, body) where heading path = "<page title> > <H2> > <H3>" as of the segment's position (H4+ extend the pattern); ParseError(rel_path, reason="no H1") surfaces the §9.4 parse-error skip reason. Pure text-in/text-out — no cache file I/O (T07 owns reads + the tarball top-dir strip).
  • ingest/chunkers.py (new): HeadingChunker (V1: H2-boundary groups, H3+ attached to their H2, greedy neighbor merge up to size_tokens; single oversized section emitted alone up to the cap), FixedChunker (V2/V3: size_tokens windows with overlap_tokens, each chunk prefixed Page: <url>\nHeading: <heading path>, prefix counted in the bound), make_chunker(cfg) -> Chunker factory (§7.4 public interface), count_tokens(text) = ceil(len(text) / 4), hard cap 1,900 tokens on every chunk — split, never truncated.

Decisions

  • Token estimator (user-frozen): tokens = ceil(len(text) / 4) — chars-per-token rule of thumb; zero deps, deterministic. To be recorded in §7.4 and the tracker Notes.
  • Fixed-window chunk heading path = path as of the window's first character.
  • Heading unit ignores overlap_tokens (§7.4 defines none for it); warning logged if set > 0.

Frozen for T07 (dependents: re-run tests before merging)

  • ParsedPage / BodySegment / Chunk dataclass shapes (Chunk: page_url, heading_path, body, body_tokens, ordinal) and make_chunker signature.
  • Build db.ChunkRow from Chunk positionally; chunk-hash (SHA-256 of normalized body + url + heading path) is T07's job.
  • Skips: catch ParseError → f"parse-error: {exc.reason}"; H1-only pages are pages_ok with zero chunks (not skips).

Verification

  • uv run pytest -q — 202 passed standalone (166 baseline + 36 new: heading paths incl. H4 continuation and no-H1 variants, exact token bounds for both chunkers, 1,900-token cap with content-coverage assertions, v1/v2 preset wiring through load_config).
  • uv run ruff check, uv run ruff format --check, uv run mypy (strict) — all clean.

@prateekchaplot
prateekchaplot merged commit 636a4b4 into main Nov 17, 2026
1 check passed
@prateekchaplot
prateekchaplot deleted the arch/caliper/t06 branch November 17, 2026 16:26
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