pub struct ChunkMetadata {
pub chapter: Option<String>,
pub section: Option<String>,
pub subsection: Option<String>,
pub topic: Option<String>,
pub keywords: Vec<String>,
pub summary: Option<String>,
pub structural_level: Option<u8>,
pub position_in_document: Option<f32>,
pub heading_path: Vec<String>,
pub confidence: Option<f32>,
pub custom: HashMap<String, String>,
}Expand description
Metadata associated with a text chunk, providing semantic context
This structure enriches chunks with information about their position in the document hierarchy, extracted keywords, automatically generated summaries, and other contextual information useful for retrieval and understanding.
Fields§
§chapter: Option<String>Chapter name/title this chunk belongs to
Examples: “Chapter 1: Introduction”, “Part I”
section: Option<String>Section name/title within the chapter
Examples: “1.1 Background”, “Introduction”
subsection: Option<String>Subsection name/title within the section
Examples: “1.1.1 Historical Context”, “Early Development”
topic: Option<String>Automatically detected or manually assigned topic
Examples: “Machine Learning”, “Neural Networks”, “Data Processing”
keywords: Vec<String>Extracted keywords from the chunk content (TF-IDF or similar)
Ordered by relevance/importance, typically 3-10 keywords
summary: Option<String>Automatically generated summary of the chunk content
Typically 1-3 sentences capturing the main points
structural_level: Option<u8>Hierarchical level in document structure (0 = root/chapter, 1 = section, 2 = subsection, etc.)
Used to understand the depth of this chunk in the document hierarchy
position_in_document: Option<f32>Relative position in the document (0.0 to 1.0)
0.0 = beginning, 0.5 = middle, 1.0 = end Useful for positional weighting in retrieval
heading_path: Vec<String>Full heading path from document root to this chunk
Example: [“Chapter 1”, “Section 1.1”, “Subsection 1.1.1”] Provides complete context of the chunk’s location in document hierarchy
confidence: Option<f32>Confidence score for metadata extraction (0.0 to 1.0)
Indicates how confident the system is about the assigned metadata
custom: HashMap<String, String>Custom metadata key-value pairs
Allows for extensibility with domain-specific metadata
Implementations§
Source§impl ChunkMetadata
impl ChunkMetadata
Sourcepub fn with_chapter(self, chapter: String) -> Self
pub fn with_chapter(self, chapter: String) -> Self
Create metadata with chapter information
Sourcepub fn with_section(self, section: String) -> Self
pub fn with_section(self, section: String) -> Self
Create metadata with section information
Sourcepub fn with_subsection(self, subsection: String) -> Self
pub fn with_subsection(self, subsection: String) -> Self
Create metadata with subsection information
Sourcepub fn with_keywords(self, keywords: Vec<String>) -> Self
pub fn with_keywords(self, keywords: Vec<String>) -> Self
Create metadata with keywords
Sourcepub fn with_summary(self, summary: String) -> Self
pub fn with_summary(self, summary: String) -> Self
Create metadata with summary
Sourcepub fn with_structural_level(self, level: u8) -> Self
pub fn with_structural_level(self, level: u8) -> Self
Create metadata with structural level
Sourcepub fn with_position(self, position: f32) -> Self
pub fn with_position(self, position: f32) -> Self
Create metadata with position in document
Sourcepub fn with_heading_path(self, path: Vec<String>) -> Self
pub fn with_heading_path(self, path: Vec<String>) -> Self
Create metadata with heading path
Sourcepub fn add_custom(self, key: String, value: String) -> Self
pub fn add_custom(self, key: String, value: String) -> Self
Add a custom metadata field
Sourcepub fn has_structure_info(&self) -> bool
pub fn has_structure_info(&self) -> bool
Check if metadata has any structural information (chapter, section, or subsection)
Sourcepub fn has_semantic_info(&self) -> bool
pub fn has_semantic_info(&self) -> bool
Check if metadata has semantic enrichment (keywords or summary)
Sourcepub fn get_deepest_heading(&self) -> Option<&String>
pub fn get_deepest_heading(&self) -> Option<&String>
Get the deepest level heading (subsection > section > chapter)
Sourcepub fn get_hierarchy_string(&self) -> Option<String>
pub fn get_hierarchy_string(&self) -> Option<String>
Get full hierarchical context as a formatted string
Example: “Chapter 1 > Section 1.1 > Subsection 1.1.1”
Sourcepub fn completeness_score(&self) -> f32
pub fn completeness_score(&self) -> f32
Calculate completeness score (0.0 to 1.0) based on populated fields
Higher scores indicate more complete metadata
Trait Implementations§
Source§impl Clone for ChunkMetadata
impl Clone for ChunkMetadata
Source§fn clone(&self) -> ChunkMetadata
fn clone(&self) -> ChunkMetadata
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChunkMetadata
impl Debug for ChunkMetadata
Source§impl Default for ChunkMetadata
impl Default for ChunkMetadata
Source§fn default() -> ChunkMetadata
fn default() -> ChunkMetadata
Source§impl<'de> Deserialize<'de> for ChunkMetadata
impl<'de> Deserialize<'de> for ChunkMetadata
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ChunkMetadata
impl PartialEq for ChunkMetadata
Source§impl Serialize for ChunkMetadata
impl Serialize for ChunkMetadata
impl StructuralPartialEq for ChunkMetadata
Auto Trait Implementations§
impl Freeze for ChunkMetadata
impl RefUnwindSafe for ChunkMetadata
impl Send for ChunkMetadata
impl Sync for ChunkMetadata
impl Unpin for ChunkMetadata
impl UnsafeUnpin for ChunkMetadata
impl UnwindSafe for ChunkMetadata
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more