/** * Text Chunker for Gemini RAG Service * * Handles text chunking with configurable token limits, * overlap calculation, and line number tracking. */ /** * Configuration options for text chunking */ export interface ChunkOptions { /** Maximum number of tokens per chunk (default: 512) */ maxTokens?: number; /** Number of overlapping tokens between chunks (default: 50) */ overlapTokens?: number; /** Approximate characters per token (default: 4) */ charsPerToken?: number; /** Preserve line boundaries when possible (default: true) */ preserveLines?: boolean; /** Minimum chunk size in tokens (default: 100) */ minChunkTokens?: number; } /** * Represents a single chunk of text with metadata */ export interface TextChunk { /** The chunk content */ content: string; /** Zero-based chunk index */ index: number; /** Starting line number (1-based) */ startLine: number; /** Ending line number (1-based, inclusive) */ endLine: number; /** Starting character offset in original text */ startOffset: number; /** Ending character offset in original text */ endOffset: number; /** Estimated token count */ tokenCount: number; /** Whether this chunk overlaps with the previous */ hasOverlap: boolean; } /** * Result of chunking operation */ export interface ChunkResult { /** Array of text chunks */ chunks: TextChunk[]; /** Total number of chunks */ totalChunks: number; /** Total estimated tokens */ totalTokens: number; /** Original text length */ originalLength: number; /** Total lines in original text */ totalLines: number; } /** * Text Chunker class for splitting text into manageable chunks */ export declare class TextChunker { private readonly options; constructor(options?: ChunkOptions); /** * Estimate token count for a string */ estimateTokens(text: string): number; /** * Convert token count to approximate character count */ private tokensToChars; /** * Get line number for a character offset */ private getLineNumber; /** * Find the nearest line boundary for a position */ private findLineBoundary; /** * Find a good split point near the target position */ private findSplitPoint; /** * Chunk text into smaller pieces */ chunk(text: string): ChunkResult; /** * Chunk text by semantic sections (code-aware) */ chunkBySection(text: string, sectionDelimiters?: RegExp[]): ChunkResult; } /** * Create a chunker with default options */ export declare function createChunker(options?: ChunkOptions): TextChunker; /** * Convenience function to chunk text with default settings */ export declare function chunkText(text: string, options?: ChunkOptions): ChunkResult; /** * Convenience function to chunk text by semantic sections */ export declare function chunkTextBySection(text: string, options?: ChunkOptions): ChunkResult; //# sourceMappingURL=chunker.d.ts.map