Documentation
¶
Overview ¶
Package chunking provides text chunking functionality for RAG systems.
Index ¶
Constants ¶
View Source
const ( DefaultMaxChunkSize = 2000 DefaultMinChunkSize = 500 DefaultOverlapSize = 200 DefaultMaxEmptyLines = 2 DefaultMinWordLen = 2 DefaultTokenRatio = 1.3 )
Variables ¶
View Source
var ( ErrEmptyContent = errors.New("content cannot be empty") ErrInvalidChunkSize = errors.New("invalid chunk size configuration") ErrContextCanceled = errors.New("operation was canceled") )
View Source
var ( ErrInvalidConfig = errors.New("invalid configuration") ErrNoEmbeddingData = errors.New("no embedding data in response") ErrChunkingFailed = errors.New("chunking failed") )
Common errors.
Functions ¶
This section is empty.
Types ¶
type Chunk ¶
type Chunk struct {
Content string `json:"content"`
Type string `json:"type"`
Level int `json:"level"`
Title string `json:"title"`
StartIndex int `json:"start_index"`
EndIndex int `json:"end_index"`
Metadata map[string]string `json:"metadata"`
ID string `json:"id,omitempty"`
TokenCount int `json:"token_count,omitempty"`
Relationships []string `json:"relationships,omitempty"`
}
type ChunkerConfig ¶
type Config ¶
type Config struct {
// Required fields.
MaxChunkSize int
MinChunkSize int
Model string
// Optional fields with defaults.
OverlapSize int
SimilarityThreshold float64
MaxMergeChunks int
EnableParallel bool
}
Config defines chunking configuration.
type DocumentNode ¶
type OptimizedMarkdownChunker ¶
type OptimizedMarkdownChunker struct {
// contains filtered or unexported fields
}
func NewMarkdownChunker ¶
func NewMarkdownChunker(maxChunkSize, overlapSize int, preserveStructure bool) (*OptimizedMarkdownChunker, error)
func NewOptimizedMarkdownChunker ¶
func NewOptimizedMarkdownChunker(config ChunkerConfig) (*OptimizedMarkdownChunker, error)
func (*OptimizedMarkdownChunker) ChunkMarkdown ¶
func (omc *OptimizedMarkdownChunker) ChunkMarkdown(content string) ([]Chunk, error)
type Option ¶
type Option func(*Config)
Option configures a SemanticChunker.
func WithMaxMergeChunks ¶
WithMaxMergeChunks sets the maximum number of chunks to merge.
func WithParallelProcessing ¶
WithParallelProcessing enables parallel embedding generation.
func WithSimilarityThreshold ¶
WithSimilarityThreshold sets the similarity threshold for merging.
type SemanticChunker ¶
type SemanticChunker struct {
// contains filtered or unexported fields
}
SemanticChunker implements semantic-aware text chunking.
func NewSemanticChunker ¶
func NewSemanticChunker( maxChunkSize, minChunkSize int, embedder embedding.Embedder, opts ...Option, ) (*SemanticChunker, error)
NewSemanticChunker creates a new semantic chunker.
Click to show internal directories.
Click to hide internal directories.