Skip to main content

Module chunk

Module chunk 

Source
Expand description

RAG chunking: Document → chunks that carry their heading context.

Two ideas carry the whole module:

  • Cut on block boundaries. A paragraph, a table or a code block is never split down the middle — only a single block bigger than the target size is, and then at the friendliest boundary it offers (line, sentence, word).
  • Every chunk knows where it sits. The chain of enclosing headings (Handbook > Onboarding > Day one) travels with the text, so an embedding of “it takes two days” still carries what “it” was.

Sizes are counted in characters, not tokens: a tokenizer means a model file or a large table inside a binary whose whole promise is that there is nothing to install. Roughly four characters per token is close enough to aim at an embedding model’s window.

byte_range indexes the Markdown rendering of the document — exactly what deepdoc file --format md prints, without front matter — and slicing it with the range gives the chunk’s text back.

Every chunk also carries a hash of its own content, so an index can tell which chunks a parser upgrade actually changed instead of re-embedding a whole corpus. See chunk_hash for what goes into it.

Structs§

Chunk
One RAG chunk.
ChunkOpts
Options for chunk.

Constants§

DEFAULT_CHUNK_SIZE
Default chunk size, in characters (see docs/PRD/02-cli-spec.md).

Functions§

chunk
Split a document into chunks. Pure.
chunk_hash
The content hash of a chunk: "sha256:<hex>" over its heading path and its text together.