/** * Smart Chunker - Language/format-aware semantic chunking * * Instead of treating all files the same, this module splits content * based on file type: * * - **Markdown** (.md): Split by headings (## sections), preserving hierarchy. * Each section becomes a chunk with its heading chain as context prefix. * * - **JSON** (.json): Split by top-level keys. Each key→value pair is a chunk. * Nested objects are kept together (not split further). * * - **YAML** (.yaml, .yml): Split by top-level keys or YAML document separators (---). * * - **Code** (.ts, .js, .tsx, .jsx, .py, .go, .rs, etc.): * Existing brace-counting approach for functions/classes, * with improved chunk size limits and overlap. * * Design goals: * - Each chunk should be self-contained and understandable in isolation * - Chunk size targets 200-800 lines for docs, 10-100 lines for code * - Include context prefixes (file path, heading chain) for better embedding quality * - Never produce empty chunks */ export interface Chunk { /** The text content of the chunk */ content: string; /** 1-indexed start line in the original file */ lineStart: number; /** 1-indexed end line in the original file */ lineEnd: number; /** Chunk type for metadata */ type: "heading_section" | "json_key" | "yaml_block" | "code_block" | "fixed"; /** Optional label (heading text, JSON key, etc.) */ label?: string; fileImports?: string; parentSymbol?: string; } /** * Configuration for the smart chunker */ export interface ChunkerConfig { /** Max lines for a single chunk before splitting further */ maxChunkLines: number; /** Min lines for a chunk (smaller gets merged with previous) */ minChunkLines: number; /** For code: target chunk size in lines */ codeChunkTarget: number; /** For fixed fallback: chunk size in lines */ fixedChunkSize: number; /** Whether to add file-path context prefix to each chunk */ addFileContext: boolean; /** * Max characters per chunk. Takes precedence over line count for files with * very long lines (minified JS, single-line JSON, i18n files). Should stay * below the embedding provider's maxChars to avoid truncation. */ maxChunkChars: number; /** * Number of lines of overlap between adjacent code chunks. Each chunk's tail * extends this many lines into the next chunk's territory, so a concept that * straddles a chunk boundary is embedded in BOTH chunks (boundary-recall * insurance). 0 disables overlap (legacy behavior). Only applied to the * semantic code path (chunkCode), not fixed/markdown/json/yaml chunkers. */ chunkOverlapLines: number; } /** * Main entry point: chunk a file based on its extension */ export declare function smartChunk(content: string, filePath: string, config?: Partial): Chunk[]; //# sourceMappingURL=smart-chunker.d.ts.map