TOOL โ€” RAG LAB

Agent RAG / Chunking Playground

Learn how chunk size and overlap affect retrieval. Paste text, set parameters, run a query, and inspect the chunks that come back.

๐Ÿ”’ Agent code unlocks Jul 17, 2026 โ€” subscribers get it now

Frequently Asked

What is RAG chunking?

Retrieval-Augmented Generation (RAG) chunking splits documents into smaller pieces before embedding them. The chunk size and overlap control how much context each retrieved result carries.

What chunk size should I use?

Use 256-512 tokens for dense factual lookup, 512-1024 for prose and articles, and 1024-2048 for code or long reasoning chains. Overlap of 10-20% reduces boundary artifacts.

Can agents use this playground?

Yes. The playground exposes the chunking algorithm and retrieval scoring logic in copy-paste snippets. Agent code access is released to Hermes Dispatch subscribers first.

๐Ÿค– Use this tool in your agent

โœ“ Agent-ready code

Copy the snippet below into your agent, newsletter, or script. The tool page at hermesdispatch.dev/tools/rag-playground/ is the canonical contract: inputs, outputs, and formulas.

python
# Hermes Dispatch Tool โ€” Agent RAG / Chunking Playground
# Source: https://hermesdispatch.dev/tools/rag-playground/
# Description: Chunk text and simulate keyword-based retrieval for a RAG playground.
# License: MIT (generated by hermesdispatch.dev)
#
# INSTALL:
#   1. Save this file as ~/.hermes/hermes-agent/tools/rag_playground.py
#   2. Restart Hermes or run /reset in a session
#   3. The tool auto-registers if Hermes uses auto-discovery of tools/*.py
#
# MANUAL REGISTRY (if auto-discovery is off):
#   from tools.rag_playground import register
#   register()

import json

DATA = {}

def _ok(result):
    return json.dumps({"success": True, "data": result}, indent=2)

def _err(message):
    return json.dumps({"success": False, "error": message}, indent=2)


TOOL_NAME = "rag_playground"
TOOLSET = "agents"

SCHEMA = {
  "type": "function",
  "function": {
    "name": "rag_playground",
    "description": "Chunk text and simulate keyword-based retrieval for a RAG playground.",
    "parameters": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string",
          "description": "Document text to chunk."
        },
        "chunk_size": {
          "type": "integer",
          "description": "Words per chunk."
        },
        "overlap": {
          "type": "integer",
          "description": "Word overlap between chunks."
        },
        "query": {
          "type": "string",
          "description": "Query to retrieve chunks for."
        },
        "top_k": {
          "type": "integer",
          "description": "Number of top chunks to return."
        }
      },
      "required": [
        "text"
      ]
    }
  }
}

def _run(args):
    text = args.get("text", "")
    chunk_size = int(args.get("chunk_size", 512))
    overlap = int(args.get("overlap", 64))
    query = args.get("query", "")
    top_k = int(args.get("top_k", 3))
    if not text:
        return _err("Provide 'text' to chunk.")
    words = text.split()
    chunks = []
    start = 0
    while start < len(words):
        end = min(start + chunk_size, len(words))
        chunks.append(" ".join(words[start:end]))
        if end == len(words):
            break
        start = max(0, end - overlap)
        if start <= 0:
            break
    matches = []
    if query:
        query_words = set(query.lower().split())
        scored = []
        for i, ch in enumerate(chunks):
            chunk_words = set(ch.lower().split())
            score = len(query_words & chunk_words)
            scored.append((score, i, ch[:200]))
        scored.sort(reverse=True)
        for score, i, snippet in scored[:top_k]:
            matches.append({"chunk_index": i, "score": score, "snippet": snippet})
    return _ok({
        "chunk_count": len(chunks),
        "chunk_size": chunk_size,
        "overlap": overlap,
        "chunks_preview": [c[:120] + "..." for c in chunks[:5]],
        "query": query,
        "top_k_matches": matches
    })

def HANDLER(args):
    try:
        return _run(args)
    except Exception as e:
        return _err(str(e))


def register():
    """Manual registry hook. Import and call this to register with Hermes."""
    try:
        from tools.registry import registry
        registry.register(
            name=TOOL_NAME,
            toolset=TOOLSET,
            schema=SCHEMA,
            handler=HANDLER,
        )
    except ImportError:
        print("Hermes registry not found; skipping manual registration.")

if __name__ == "__main__":
    # CLI smoke test
    print(HANDLER({}))

Want early access to the next locked tool? Subscribe to The Hermes Dispatch.

๐Ÿš€ Get AI automation insights daily

15:00 MST. One-click unsubscribe.

Subscribe