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

Two bands. sec-line-cdc-v1: normalised text with headings as hash lines becomes section spans, where a heading line closes the current span; inside a section a line-hash cut happens when the span is at least 300 characters and the sha256 of the line modulo 8 is zero; any span over 1,500 characters is hard split. What the store does with them: a chunk id is a hash of source key, chunker version, text hash and repeat index; when the same page is read again and the page hash is equal, chunk sync is skipped; for an edited section the old chunk is retired and the new chunk inserted; nothing is deleted and a retired chunk can come back active. A note explains why a hash of the line decides the cut: a fixed-size window shifts every boundary after an insertion, while a boundary that depends only on its own line stays where it was.
Figure 1. Chunking and storage. Cut points are decided by headings and by a hash of each line. The store compares hashes, so an unchanged page writes nothing and an edited section replaces only its own chunks.

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 #.

  1. A heading closes the current span. The headings above a span are kept as a path, joined with “ > “, and stored with the chunk.
  2. 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.
  3. 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.

ConstantValueRole
CHUNKER_VERSIONsec-line-cdc-v1part of every chunk id
CHUNK_MIN_CHARS300no cut before this length
_CUT_MODULUS8a line is a cut point when its hash is divisible by this
CHUNK_MAX_CHARS1,500hard 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.

SituationWhat is written
The page hash is unchangednothing: the chunk sync is skipped
The page changedchunks whose ids are still present stay as they are
A chunk id is no longer presentthat chunk is marked retired, with the run that retired it
A new chunk id appearsinserted as active
A retired id appears againreactivated

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 wrongWhat happensRegression test
The same page is read twicethe second read adds nothingtest_same_page_twice_adds_nothing_the_second_time
One section is editedonly that section’s chunk is retired and replacedtest_edited_section_retires_only_its_chunk
Ids must be stable across runsthey are, and only the edited section’s id changestest_chunk_ids_are_stable_and_only_edited_section_changes
The same text appears on another pageit gets another idtest_same_text_on_another_source_gets_another_id
Offsets and heading paths must match the textchunks cover the text with correct offsetstest_chunks_cover_text_with_offsets_and_heading_paths
A re-read failsearlier text and chunks are kepttest_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.