{"data":{"slug":"github-xberg-io-xberg-ai-rulez-skills-chunking-embeddings-d77ff24f486d","title":"Chunking & Embeddings Configuration","summary":"Configure text chunking, embedding models, and RAG integration for content processing.","url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-ai-rulez-skills-chunking-embeddings-d77ff24f486d","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-xberg-io-xberg-ai-rulez-skills-chunking-embeddings-d77ff24f486d","markdown_url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-ai-rulez-skills-chunking-embeddings-d77ff24f486d.md","download_url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-ai-rulez-skills-chunking-embeddings-d77ff24f486d\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"The configuration requires the 'embeddings' feature to be active for presets to take effect. Ensure the correct serde wire names are used in config files, such as 'max_chars' and 'max_overlap'.","instructions":"---\ntype: Playbook\ntitle: Chunking Embeddings\ndescription: \"Change text chunking, embeddings or RAG configuration and code.\"\npaths:\n  - \"crates\/xberg\/src\/chunking\/**\"\n  - \"crates\/xberg\/src\/embeddings\/**\"\nx-ai-rulez:\n  kind: skill\n  id: chunking-embeddings\n  metadata:\n    priority: critical\n    name: chunking-embeddings\n---\n\n# Chunking & Embeddings\n\n**Text splitting, ONNX\/static embedding generation, RAG pipeline integration**\n\nLocations: `crates\/xberg\/src\/chunking\/` and `crates\/xberg\/src\/embeddings\/` (both directories,\nnot single files).\n\n## Chunking\n\n`ExtractionConfig.chunking: Option<ChunkingConfig>` drives it. The standalone entry points are\n`chunking::chunk_text(text, &ChunkingConfig, page_boundaries) -> Result<ChunkingResult>`\n(`chunking\/core.rs`) and `chunking::rag::chunk_for_rag(text, &ChunkingConfig)`\n(`chunking\/rag.rs`), which upgrades `ChunkerType::Text` to `Markdown` and fills each chunk's\n`heading_path`.\n\n`ChunkingResult { chunks: Vec<Chunk>, chunk_count: usize }`. `Chunk` carries `content`,\n`chunk_type`, `metadata`, and the optional vectors `embedding`, `sparse_embedding`,\n`late_interaction` (`types\/extraction.rs`).\n\n### `ChunkerType` \u2014 there is no strategy enum beyond this\n\n`Text` (default), `Markdown`, `Yaml`, `Semantic` (`core\/config\/processing.rs`).\n`Semantic` splits at embedding-based topic shifts when an `EmbeddingConfig` is present, and\nfalls back to a structural-boundary heuristic otherwise \u2014 `topic_threshold` has no effect on\nthe fallback path.\n\n### `ChunkingConfig` fields and their serde wire names\n\n| Field | Wire name (config file) | Default |\n| --- | --- | --- |\n| `max_characters` | `max_chars` (alias `max_characters`) | 1000 |\n| `overlap` | `max_overlap` (alias `overlap`) | 200 |\n| `trim` | `trim` | true |\n| `chunker_type` | `chunker_type` | `Text` |\n| `preset` | `preset` | none |\n\nThe renames are load-bearing: a config file that writes `max_characters` works only via the\nalias, and a typo'd key is silently ignored (see `config-loading-precedence`).\n\n### Presets set chunk size AND the embedding model\n\n`ChunkingConfig.preset` resolves through `resolve_preset()`, which is\n`#[cfg(feature = \"embeddings\")]`-gated \u2014 **without that feature it is a no-op and the preset\nname does nothing**. A preset overrides `max_characters` and `overlap` and, if no embedding\nconfig was given, selects the model.\n\n| Preset | chunk_size | overlap | dims | backend |\n| --- | --- | --- | --- | --- |\n| `fast` | 512 | 50 | 384 | ONNX |\n| `balanced` | 1024 | 100 | 768 | ONNX |\n| `quality` | 2000 | 200 | 1024 | ONNX |\n| `multilingual` | 1024 | 100 | 768 | ONNX |\n| `gte-modernbert-base` | 1024 | 100 | 768 | ONNX |\n| `lightweight` | 512 | 50 | 256 | static (model2vec) |\n| `arctic-embed-m-v2.0` | 1024 | 100 | 768 | ONNX |\n| `qwen3-embedding-0.6b` | 2000 | 200 | 1024 | ONNX |\n\nSource of truth: `EMBEDDING_PRESETS` in `crates\/xberg\/src\/embeddings\/mod.rs`.\n\n## Embeddings\n\nThere is no `TextEmbeddingManager`, no `embed_chunks()`, no `ChunkWithEmbedding`, no\n`RagDocument`, and **no fastembed dependency** \u2014 do not write code against any of those.\n\nModel selection is `EmbeddingModelType`, a tagged enum (`core\/config\/processing.rs`):\n`Preset { name }` (recommended), `Custom { \u2026 }` (HuggingFace ONNX), `Llm { \u2026 }`,\n`Plugin { \u2026 }`.\n\nTwo defaults disagree and both are live: `EmbeddingModelType::default()` is the\n`gte-modernbert-base` preset (what bindings and `#[serde(default)]` get), while\n`EmbeddingConfig::default()` names `balanced` via `default_balanced_embedding_model()`. Read\nthe constructor you are actually going through before assuming which model runs.\n\n`EmbeddingConfig` defaults: `normalize = true`, `batch_size = 32`,\n`max_embed_duration_secs = Some(60)`, `max_sequence_length = None` (falls back to 512, capped\nat the model's own `model_max_length`).\n\n### Feature gating\n\n```toml\nembeddings = [\"onnx-runtime\", \"dep:ndarray\", \"chunking\", \"tokio-runtime\", \"embedding-presets\"]\n```\n\n`ort-bundled` (the default ORT linkage) **downloads** ONNX Runtime at build time \u2014 no system\ninstall, no `ORT_DYLIB_PATH`. That variable matters only under `ort-dynamic`.\n\n`static-embeddings` is the pure-Rust model2vec path and the only dense embedder available on\n`no-ort-target` (WASM\/Android). `embedding-presets` carries preset metadata alone and is\nWASM-safe.\n\n## Critical Rules\n\n1. **Chunk before embedding** \u2014 vectors are attached per chunk, not per document.\n2. **A preset without the `embeddings` feature is inert** \u2014 `resolve_preset()` is compiled out.\n3. **Write serde wire names in config files** \u2014 `max_chars`\/`max_overlap`, not the Rust field names.\n4. **Degrade, don't fail** \u2014 a build without ORT should skip embeddings, not error.\n5. **Normalize for cosine similarity** \u2014 `EmbeddingConfig.normalize` defaults to true; leave it on.\n\n## Related Skills\n\n- **extraction-pipeline-patterns** \u2014 text extraction preceding chunking\n- **config-loading-precedence** \u2014 how `ChunkingConfig` is resolved and why typos are silent\n- **feature-flag-conventions** \u2014 `embeddings` vs `static-embeddings` vs `embedding-presets`\n","use_cases":["Split text into chunks for embedding generation","Integrate chunking with RAG pipelines","Select embedding models based on presets"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/xberg-io\/xberg\/blob\/ffbf7971796a126fc52f6bb8fb40418772071f61\/.ai-rulez\/skills\/chunking-embeddings\/SKILL.md","source_commit":"ffbf7971796a126fc52f6bb8fb40418772071f61","license":null,"version":null,"listing_approved_at":"2026-11-16","created_at":"2026-11-15T13:19:17.000000Z","updated_at":"2026-11-16T05:16:54.000000Z","seo_title":"Chunking & Embeddings Configuration","seo_description":"Configure text chunking, embedding models, and RAG integration for content processing.","seo_keywords":["chunking configuration","embedding model selection","rag pipeline integration","text splitting","embedding presets"]}}