Skip to main content

ChunkingStrategy

Trait ChunkingStrategy 

Source
pub trait ChunkingStrategy: Send + Sync {
    // Required method
    fn chunk(&self, text: &str) -> Vec<TextChunk>;
}
Expand description

Core trait for text chunking strategies

This trait provides a simple interface for different chunking approaches. Implementations can range from simple text splitters to sophisticated AST-based code chunking strategies.

§Examples

use graphrag_core::{ChunkingStrategy, TextChunk};

struct SimpleChunker;

impl ChunkingStrategy for SimpleChunker {
    fn chunk(&self, text: &str) -> Vec<TextChunk> {
        // Simple implementation
        vec![]
    }
}

Required Methods§

Source

fn chunk(&self, text: &str) -> Vec<TextChunk>

Chunk text into pieces following the strategy’s logic

§Arguments
  • text - The input text to chunk
§Returns

A vector of TextChunk objects representing the chunks

Implementors§