Repository navigation
feat(ingest): markdown parsers + heading/fixed chunkers with token bounds (T06) - #11
Merged
Merged
Conversation
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.
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.4parse-errorskip 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 tosize_tokens; single oversized section emitted alone up to the cap),FixedChunker(V2/V3:size_tokenswindows withoverlap_tokens, each chunk prefixedPage: <url>\nHeading: <heading path>, prefix counted in the bound),make_chunker(cfg) -> Chunkerfactory (§7.4 public interface),count_tokens(text) = ceil(len(text) / 4), hard cap 1,900 tokens on every chunk — split, never truncated.Decisions
tokens = ceil(len(text) / 4)— chars-per-token rule of thumb; zero deps, deterministic. To be recorded in §7.4 and the tracker Notes.overlap_tokens(§7.4 defines none for it); warning logged if set > 0.Frozen for T07 (dependents: re-run tests before merging)
ParsedPage/BodySegment/Chunkdataclass shapes (Chunk:page_url, heading_path, body, body_tokens, ordinal) andmake_chunkersignature.db.ChunkRowfromChunkpositionally; chunk-hash (SHA-256 of normalized body + url + heading path) is T07's job.ParseError→f"parse-error: {exc.reason}"; H1-only pages arepages_okwith 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 throughload_config).uv run ruff check,uv run ruff format --check,uv run mypy(strict) — all clean.