Every accepted brand fact carries a pointer to the chunk of the page that supports it. That pointer has to survive the page being read again next week. If re-reading renumbered the chunks, every pointer would dangle, and "this sentence came from that passage" would be true only until the next readout.
The problem
The simple way to chunk is a fixed window: every 700 characters, with some overlap. It has two properties that are wrong for evidence.
- Boundaries move. Insert one sentence near the top of a page and every boundary after it shifts by the length of that sentence. Every later chunk now has different text, so every later chunk is new.
- Ids are positions. If a chunk is “page 3, chunk 7”, then an edit above it makes chunk 7 a different passage with the same name.
Both come from the boundary depending on what precedes it. The fix is a boundary that depends only on the content at the boundary, and an id that depends only on the content of the chunk.
How a page is cut

The chunker is named sec-line-cdc-v1: sections, then lines, by content-defined chunking. It works on the normalised text, in which headings are lines that begin with #.
- A heading closes the current span. The headings above a span are kept as a path, joined with “ > “, and stored with the chunk.
- Inside a section, a span may end at the end of a line when two things hold: the span is at least 300 characters long, and a hash of that line is divisible by 8.
- A span longer than 1,500 characters is cut at 1,500, even in the middle of a line. This is the safety net for a page with no line breaks.
Step 2 is the content-defined part.
def chunk_id(source_key: str, text_hash: str, dup_index: int) -> str:
raw = "\x1f".join((source_key, CHUNKER_VERSION, text_hash, str(dup_index)))
return "ch_" + hashlib.sha256(raw.encode("utf-8")).hexdigest()[:24]
def _cut_here(line: str) -> bool:
return int(hashlib.sha256(line.encode("utf-8")).hexdigest()[:8], 16) % _CUT_MODULUS == 0
Whether a line is a cut point depends on that line’s text and nothing else. With a modulus of 8, about one line in eight qualifies, and the 300-character minimum keeps chunks from being too small to mean anything. Insert a paragraph in the middle of a section and the cut points before and after it are exactly where they were. Only the span that contains the new paragraph has new text.
| Constant | Value | Role |
|---|---|---|
CHUNKER_VERSION | sec-line-cdc-v1 | part of every chunk id |
CHUNK_MIN_CHARS | 300 | no cut before this length |
_CUT_MODULUS | 8 | a line is a cut point when its hash is divisible by this |
CHUNK_MAX_CHARS | 1,500 | hard split above this length |
What goes into an id
A chunk id is a hash of four things: the source key, the chunker version, the hash of the chunk’s text, and a repeat index.
- The source key is the page’s address in a normal form: the host without “www”, the path without a trailing slash, the query string kept. The same sentence on two pages is two chunks, because evidence is a claim about a specific page.
- The chunker version means a future change to the cutting rules produces new ids on purpose. Chunks cut by different rules are not the same chunks, even with the same text.
- The text hash is the content.
- The repeat index counts identical chunks within one page, so a line that appears twice gets two ids.
Nothing in the id is a position or a timestamp. Read the same page a hundred times and the ids are the same hundred times.
What the store does
Each stored page keeps a hash of its normalised text. When a page is read again, the store compares hashes first.
| Situation | What is written |
|---|---|
| The page hash is unchanged | nothing: the chunk sync is skipped |
| The page changed | chunks whose ids are still present stay as they are |
| A chunk id is no longer present | that chunk is marked retired, with the run that retired it |
| A new chunk id appears | inserted as active |
| A retired id appears again | reactivated |
Nothing is deleted. A retired chunk keeps its text, so an evidence reference that points at it can still show what the page said when the fact was accepted. If the brand restores a paragraph it removed, the chunk comes back with the same id it had.
A unique index on brand and chunk id makes the insert idempotent. A readout that is interrupted and run again inserts the same ids and collides with nothing new.
Failure modes
| What goes wrong | What happens | Regression test |
|---|---|---|
| The same page is read twice | the second read adds nothing | test_same_page_twice_adds_nothing_the_second_time |
| One section is edited | only that section’s chunk is retired and replaced | test_edited_section_retires_only_its_chunk |
| Ids must be stable across runs | they are, and only the edited section’s id changes | test_chunk_ids_are_stable_and_only_edited_section_changes |
| The same text appears on another page | it gets another id | test_same_text_on_another_source_gets_another_id |
| Offsets and heading paths must match the text | chunks cover the text with correct offsets | test_chunks_cover_text_with_offsets_and_heading_paths |
| A re-read fails | earlier text and chunks are kept | test_failed_reread_keeps_previous_text_and_chunks |
Limits I know about
An unchanged page is not free yet. The store writes nothing for it, but the page is still fetched, normalised and chunked in memory, and the extractor is still called on it. The design says extraction should run only for sources that changed. That part is not built, so the saving today is in storage writes and in id stability, not in model calls.
The hard split ignores lines. A span over 1,500 characters is cut at exactly 1,500. That boundary does depend on what precedes it, so on a page with very long unbroken text an insertion can still shift chunks. Real pages with headings and paragraphs rarely reach it.
The id does not include the brand. The design’s version of the id included the brand id. The code leaves it out and relies on the unique index over brand and chunk id. Two brands that read the same public page get chunks with the same id in different documents, which is correct and slightly surprising when debugging.
No retention rule. The design mentions removing retired chunks after a period. No such cleanup exists, so retired chunks accumulate. At hundreds of chunks per brand that is a small cost.
