Skip to main content
Glama

evaluate_chunking

Benchmark chunking strategies on your RAG corpus with cost estimates or full evaluation. Configure options like top_k, max_docs, and embedding models for tailored analysis.

Instructions

Dry-run cost estimate or full evaluation (DummyEmbeddingFunction if no model).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
use_caseNorag_qa
content_typeNo
strategiesNo
max_docsNo
top_kNo
dry_runNo
embedding_modelNo

Implementation Reference

  • Core implementation of evaluate_chunking_impl - handles dry-run cost estimates and full evaluation with embeddings. Validates path, strategies, ingests docs, and runs evaluation via Evaluator.
    def evaluate_chunking_impl(
        path: str,
        use_case: str,
        *,
        content_type: str | None = None,
        strategies: list[str] | None = None,
        max_docs: int = 20,
        top_k: int = 5,
        dry_run: bool = False,
        embedding_model: str | None = None,
    ) -> dict:
        p = require_under_base(path)
        if not p.exists():
            raise ValueError("path does not exist")
        if strategies is not None:
            _validate_strategies(strategies)
        names = strategies or ["fixed_tokens", "recursive_character"]
        if dry_run:
            fi = FileIngestor(root=p.parent if p.is_file() else p)
            docs = fi.ingest_path(p) if p.is_file() else fi.ingest_dir(p)
            docs = docs[:max_docs]
            grid: dict[str, list[dict]] = {
                n: build_full_registry().get(n).default_param_grid() for n in names
            }
            est = CostEstimator().estimate(
                docs, names, grid, embedding_model or "text-embedding-3-small"
            )
            return est.model_dump()
        embed = (
            LiteLLMEmbeddingFunction(embedding_model) if embedding_model else DummyEmbeddingFunction()
        )
        fi = FileIngestor(root=p.parent if p.is_file() else p)
        docs = fi.ingest_path(p) if p.is_file() else fi.ingest_dir(p)
        docs = docs[:max_docs]
        ds = trivial_dataset_for_docs(docs)
        reg = build_full_registry()
        ev = Evaluator(embed, top_k=top_k)
        scorer = ScoreCalculator(cast(UseCase, use_case))
        results = []
        for n in names:
            strat = reg.get(n)
            for params in strat.default_param_grid():
                cfg = ChunkConfig(name=n, params=dict(params))
                results.append(ev.evaluate(strat, cfg, docs, ds, scorer=scorer))
        return {
            "dataset_summary": {"queries": len(ds.queries)},
            "results": [r.model_dump() for r in results],
        }
  • MCP tool registration of 'evaluate_chunking' as a FastMCP tool with parameters: path, use_case, content_type, strategies, max_docs, top_k, dry_run, embedding_model.
    @mcp.tool()
    def evaluate_chunking(
        path: str,
        use_case: str = "rag_qa",
        content_type: str | None = None,
        strategies: list[str] | None = None,
        max_docs: int = 20,
        top_k: int = 5,
        dry_run: bool = False,
        embedding_model: str | None = None,
    ) -> dict:
        """Dry-run cost estimate or full evaluation (``DummyEmbeddingFunction`` if no model)."""
        t0 = time.perf_counter()
        with _eval_sem:
            try:
                out = evaluate_chunking_impl(
                    path,
                    use_case,
                    content_type=content_type,
                    strategies=strategies,
                    max_docs=max_docs,
                    top_k=top_k,
                    dry_run=dry_run,
                    embedding_model=embedding_model,
                )
                _log_tool("evaluate_chunking", t0, True)
                return out
            except Exception:
                _log_tool("evaluate_chunking", t0, False)
                raise
  • Pydantic schema EvaluateBody defining input validation for evaluate_chunking (path, use_case, content_type, strategies, max_docs, top_k, dry_run, embedding_model).
    class EvaluateBody(BaseModel):
        path: str
        use_case: str = "rag_qa"
        content_type: str | None = None
        strategies: list[str] | None = None
        max_docs: int = 20
        top_k: int = 5
        dry_run: bool = False
        embedding_model: str | None = None
  • FastAPI route registration for POST /evaluate_chunking, delegates to evaluate_chunking_impl service.
    @router.post("/evaluate_chunking")
    def evaluate_chunking(body: EvaluateBody) -> dict:
        try:
            return evaluate_chunking_impl(
                body.path,
                body.use_case,
                content_type=body.content_type,
                strategies=body.strategies,
                max_docs=body.max_docs,
                top_k=body.top_k,
                dry_run=body.dry_run,
                embedding_model=body.embedding_model,
            )
        except ValueError as e:
            raise HTTPException(status_code=400, detail=str(e)) from e
  • Path validation helper require_under_base used by evaluate_chunking_impl to ensure path is under CHUNK_TUNER_BASE_DIR.
    def require_under_base(path_str: str) -> Path:
        """Resolve ``path_str`` to an absolute path and ensure it stays under the workspace base."""
        base = _resolved_base_dir()
        candidate = Path(path_str).expanduser()
        if not candidate.is_absolute():
            candidate = (base / candidate).resolve()
        else:
            candidate = candidate.resolve()
        try:
            candidate.relative_to(base)
        except ValueError as e:
            raise ValueError(f"path must be under CHUNK_TUNER_BASE_DIR ({base}): {candidate}") from e
        return candidate
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that a DummyEmbeddingFunction is used if no model is specified, and implies a dry-run vs. full evaluation mode via the dry_run parameter. However, it does not detail what each mode outputs, whether any data is modified, or other behavioral constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence, making it concise but overly terse. It front-loads the main action but sacrifices informativeness. Every word earns its place, but the sentence is too short to be fully helpful.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 8 parameters, no output schema, and no annotations, the description is incomplete. It does not explain the output, how to interpret results, or the meaning of key parameters like strategies and use_case. The sibling tools provide some context, but the description alone is insufficient for effective tool usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. Only the dry_run and embedding_model parameters are implicitly explained; the other six parameters (path, use_case, content_type, strategies, max_docs, top_k) receive no explanation. The description adds minimal meaning beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states 'Dry-run cost estimate or full evaluation' which hints at evaluation of chunking strategies, but it is vague and does not clearly specify the verb and resource. The mention of 'DummyEmbeddingFunction' provides some context, but the purpose remains ambiguous without explicit reference to chunking evaluation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

There is no guidance on when to use this tool versus the siblings (list_strategies, preview_chunks, recommend_config). The description does not explain the conditions for dry-run versus full evaluation, nor does it provide criteria for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/shantanu-deshmukh/chunktuner'

If you have feedback or need assistance with the MCP directory API, please join our Discord server