Skip to content

feat(#407): embed-aware chunking — chunk size from embedder.max_seq_len() - #424

Merged
ajianaz merged 3 commits into
developfrom
feat/407-embed-aware-chunking
Jun 21, 2026
Merged

ajianaz merged 3 commits into
developfrom
feat/407-embed-aware-chunking

Conversation

@ajianaz

@ajianaz ajianaz commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Implements #407.

Summary

Add chunk_markdown_embed_aware() — derives chunk size from embedder token limit.

Formula

max_chars = embedder.max_seq_len() * 4 (~4 chars per token)

Backend Tokens Chars/chunk
ONNX 256 1,024
Ollama 2,048 8,192
OpenAI 8,191 32,764

Guard: if seq_len < 25 tokens, falls back to 1024 chars.

Milestone: v0.3.0 — Graph RAG

…en()

Add chunk_markdown_embed_aware() that derives max_chars from the
embedder token limit using the heuristic ~4 chars per token:

- ONNX (256 tokens): 1024 chars per chunk
- OpenAI (8191 tokens): 32764 chars per chunk
- Ollama (2048 tokens): 8192 chars per chunk

Uses the existing Embedder::max_seq_len() trait method.

Test: mock embedder with 256 tokens validates chunk size constraint.
pub fn chunk_markdown_embed_aware<E: crate::embed::Embedder>(
text: &str,
embedder: &E,
) -> Vec<TextChunk> {
@github-actions

github-actions Bot commented Jun 21, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (1)

  • crates/uteke-core/src/chunker.rs:49 — In chunk_markdown_embed_aware, max_chars is derived as embedder.max_seq_len().saturating_mul(4) and then passed directly to chunk_markdown. This assumes all inputs average ~4 chars/token, but many markdown inputs produce far more than 1 token per 4 characters (for example punctuation-heavy, code-heavy, non-ASCII, or whitespace-separated content). As a result, chunks produced by this function can still exceed embedder.max_seq_len(), causing downstream embedding calls to fail even though the function is intended to be sequence-window aware.

Review powered by cora-cli · BYOK · MIT

Comment thread crates/uteke-core/src/chunker.rs Fixed
@ajianaz
ajianaz merged commit 2f47454 into develop Jun 21, 2026
8 of 9 checks passed
@ajianaz
ajianaz deleted the feat/407-embed-aware-chunking branch June 21, 2026 13:38
ajianaz added a commit that referenced this pull request Aug 13, 2026
…en() (#424)

* feat(#407): embed-aware chunking — chunk size from embedder.max_seq_len()

Add chunk_markdown_embed_aware() that derives max_chars from the
embedder token limit using the heuristic ~4 chars per token:

- ONNX (256 tokens): 1024 chars per chunk
- OpenAI (8191 tokens): 32764 chars per chunk
- Ollama (2048 tokens): 8192 chars per chunk

Uses the existing Embedder::max_seq_len() trait method.

Test: mock embedder with 256 tokens validates chunk size constraint.

* style: fmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants