#[non_exhaustive]pub struct Chunk {
pub heading_path: Vec<String>,
pub markdown: String,
}markdown only.Expand description
A piece of a document’s Markdown, small enough for an embedding model or a
prompt, with the headings it sits under — so every chunk stands on its
own. Built by Dom::to_markdown_chunks.
With the serde feature, Chunk implements serde::Serialize
({"heading_path": [...], "markdown": "..."}).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.heading_path: Vec<String>The plain-text titles of the headings this chunk sits under, outermost
first (["Guide", "Install"]). Empty before the first heading. A title
longer than 256 characters is cut to its first 256, followed by …
(the heading line itself stays whole in Chunk::markdown).
markdown: StringThe chunk’s Markdown. It starts with its section’s heading line when it is the first chunk of that section.
Implementations§
Source§impl Chunk
impl Chunk
Sourcepub fn context(&self) -> String
pub fn context(&self) -> String
The heading path as one line of context, joined with " > " — e.g.
"Guide > Install" — to prepend to the chunk when embedding it. Empty
when the chunk comes before any heading.
let dom = domq::parse("<h1>Guide</h1><h2>Install</h2><p>Run it.</p>");
let chunks = dom.to_markdown_chunks(1000);
assert_eq!(chunks[0].context(), "Guide > Install");