Documentation
¶
Overview ¶
Package chunk defines the chunker contract for the document corpus and the line-window fallback chunker. Structural chunkers live in subpackages (chunk/markdown, chunk/gosrc).
Chunkers are pure functions of file bytes: no I/O, no network, no model. The corpus design depends on that -- the no-LLM-in-ingest pillar from docs/document-corpus.md is enforced by an import-graph test over this package tree, which is why nothing here may import the root memstore package (it carries an LLM client) or anything that reaches the network.
Index ¶
Constants ¶
const ( // Target is what the splitter aims for when it must split. Target = 2000 // Max is the hard ceiling above which a section or declaration must // split. A single atomic block (fence, table, statement) over Max becomes // an oversized chunk; half a code fence retrieves as noise, an oversized // chunk is merely inefficient. Max = 8000 // Min is the floor below which a piece merges with its siblings. Min = 400 )
Sizing thresholds in non-whitespace characters (docs/document-chunking.md). Non-whitespace characters, not tokens: token counts would put a model dependency inside the ingest path and shift every boundary when the model changes. Not bytes: indentation would inflate measured size, severely so in nested code.
const LineWindowVersion = 1
LineWindowVersion identifies boundary-affecting behavior of the line-window chunker.
Variables ¶
This section is empty.
Functions ¶
func TrimTrailingWS ¶
TrimTrailingWS returns the end offset of span [start, end) with trailing whitespace removed. It never trims past start.
Types ¶
type Chunk ¶
type Chunk struct {
Ordinal int
Content string
ByteStart int
ByteEnd int
LineStart int
LineEnd int
// Markdown-derived context.
HeadingPath string // ancestor headings only, never the chunk's own
HeadingLevel int
Lang string // set on split-out fences
// Code-derived context.
Package string
ImportPath string
Symbol string
Receiver string
DeclKind string // func | method | type | const | var | import | package_doc
Exported bool
Signature string
ScopePath string // package > receiver > symbol
ImportsUsed []string
}
Chunk is one verbatim span of a file. Content must equal file[ByteStart:ByteEnd] exactly; the derived fields carry context for embed-time assembly and are never prepended to Content.
type Chunker ¶
type Chunker interface {
Chunk(path string, content []byte) (*Result, error)
// Version identifies boundary-affecting behavior. Bump it on any change
// that can move a cut; a differing version is grounds for re-ingest even
// when the file hash matches.
Version() int
// Strategy names the chunker on the document row (e.g. "markdown", "go",
// "line-window").
Strategy() string
}
Chunker cuts one file's bytes into verbatim chunks.
path is provenance context only -- it may inform derived metadata (import path, package naming) but must never influence where boundaries fall: chunking must be a pure function of content for file_sha256 to be a sufficient staleness check.
type LineIndex ¶
type LineIndex struct {
// contains filtered or unexported fields
}
LineIndex maps byte offsets to 1-based line numbers for one file.
func NewLineIndex ¶
NewLineIndex builds the index for content.
type LineWindow ¶
type LineWindow struct{}
LineWindow is the fallback chunker for plain text with no structure to cut on: non-markdown text files, and source files that fail to parse (docs/code-chunking.md). It packs whole lines into windows of roughly Target non-whitespace characters and, unlike the structural chunkers, keeps a small overlap between windows -- with no structural boundary to cut at, the overlap is what keeps a match near a window edge retrievable with its context.
type Result ¶
type Result struct {
Chunks []Chunk
Title string // from front matter when present
FrontMatter json.RawMessage // parsed front matter as JSON; nil when absent
Generated bool // file carries a "Code generated ... DO NOT EDIT." line
}
Result is one file's chunking output plus the document-level provenance the chunker derives from the bytes.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package gosrc implements the Go source chunker from docs/code-chunking.md: cAST-style split-then-merge over the stdlib AST.
|
Package gosrc implements the Go source chunker from docs/code-chunking.md: cAST-style split-then-merge over the stdlib AST. |
|
Package markdown implements the markdown chunker from docs/document-chunking.md: front matter parsed into document fields, sections segmented at headings, oversized sections split at top-level block boundaries, undersized sibling sections merged, fences and tables never split.
|
Package markdown implements the markdown chunker from docs/document-chunking.md: front matter parsed into document fields, sections segmented at headings, oversized sections split at top-level block boundaries, undersized sibling sections merged, fences and tables never split. |