ragchunk
v1.8.0
Published
High-performance, production-grade text preprocessing and semantic chunking engine optimized for LLM inputs and Vector Databases
Readme
⚡ RAG Semantic Document Chunker & HTML Cleaner
The only RAG preprocessing tool that thinks like a developer and charges like a cloud function.
Transform any public documentation URL into clean, token-precise, context-rich Markdown chunks, ready to be dropped directly into OpenAI, Pinecone, Weaviate, Chroma, LangChain, or any LLM pipeline. No headless browsers. No bloated DOM trees. No wasted tokens.
🤔 What Problem Does This Solve?
If you have ever tried to build a RAG (Retrieval-Augmented Generation) pipeline on real-world documentation, you already know the pain:
- You scrape a documentation page and your markdown output is 60% navigation links, sidebar menus, cookie banners, and footer noise, none of which helps your LLM.
- You try to chunk the raw text but end up slicing code blocks in half, breaking tables mid-row, or losing which section a chunk belongs to.
- You burn $15 to $40 in OpenAI embedding tokens per document ingestion run because you are vectorizing sidebar garbage instead of actual content.
This Actor solves all three problems in a single API call.
🚀 The Differentiator: Up to 40% Token Savings
Standard scrapers ingest entire DOM trees, wasting thousands of dollars on navigation menus, footers, and tracking scripts. This engine runs an advanced Cheerio-based selector priority extraction cascade and link-density evaluation engine to strip layout noise before any chunking occurs.
Live Validation Benchmark (Node.js API Reference Page):
| Metric | Value |
|---|---|
| Raw Markdown Volume | 395,669 characters |
| Post-Processed Clean Markdown | 333,964 characters |
| Net Token Savings | 61,705 characters (approximately 15,000 to 20,000 wasted tokens eliminated) |
That is real money saved on every single document you ingest.
✅ Who Is This For?
This tool is built for:
- AI Engineers building RAG pipelines on top of GPT-4, Claude, Gemini, or open-source LLMs.
- Developer Tool Teams ingesting API reference documentation into vector databases.
- Startups & SaaS companies building documentation search, AI assistants, or knowledge base copilots.
- Data engineers automating content ingestion workflows into Pinecone, Weaviate, Chroma, or pgvector.
If you are feeding documentation into a vector database, this is the highest-quality, lowest-cost preprocessing layer available on the market.
✨ Core Engine Features
🧹 Aggressive Boilerplate Sanitization
Removes navigation menus, sidebars, footers, tracking pixels, cookie banners, and advertisement containers using a multi-layer Cheerio-based DOM cascade before any conversion to Markdown occurs. Unlike raw scrapers that hand you the entire DOM, we hand you only the signal.
🛡️ Code Block Integrity Protection
The chunker tracks open and closed Markdown code fences (```) in real-time. If a split would slice a code block in half, it automatically postpones the split until the fence closes. Your LLM will always receive complete, syntactically valid code samples.
📊 Markdown Table Integrity Protection
Tables carry structured data (such as parameter schemas, API response mappings, and comparison grids). Our engine detects table boundaries and applies a configurable table_hard_multiplier budget to keep entire tables within a single chunk, preventing broken header rows from stranding orphaned data rows in the next chunk.
🏷️ Multi-Header Context Tracking
Every emitted chunk includes a header_contexts array listing all active parent headings within the sliding window boundary. When your RAG retriever returns a chunk about reduce(), it will know whether that chunk came from Parameters, Description, or Edge cases. This eliminates the context-drift problem permanently.
🪙 Exact BPE Token Tracking
Uses the cl100k_base Byte Pair Encoding tokenizer, which is the exact same tokenizer used internally by GPT-4 and GPT-4o, to count tokens with 100% accuracy. No approximations. No character-based guesses. Every chunk respects the token ceiling you configure.
⛓️ Cascading Line Segmentation
Handles dense layouts (such as blog indexes, link lists, or documentation menus) that render thousands of characters onto a single line. The parser automatically cascades down through sentence boundaries, list boundaries, semicolon/comma clauses, and word limits to segment long lines below max_tokens * 0.8. This prevents runaway chunk overlaps and ensures strict token bounds.
🔁 Configurable Sliding Overlap Window
Carries a configurable number of trailing tokens from the previous chunk into the next, ensuring that semantic ideas which straddle chunk boundaries are never completely lost during vector retrieval.
📥 Input Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
| url | string | required | The exact public URL to scrape, extract, and chunk. |
| max_tokens | integer | 500 | Max BPE tokens per chunk (50–2000). |
| overlap | integer | 50 | Trailing overlap tokens between consecutive chunks (0–500). |
| contentSelector | string | none | Optional CSS selector to target specific content containers (e.g. main, article, #content). |
| min_token_floor | integer | 30 | Minimum token count to emit a chunk. Discards tiny non-semantic fragments (5–500). |
| prose_hard_multiplier | number | 1.2 | Hard token budget multiplier for prose segments before splitting (1.0–2.0). |
| table_hard_multiplier | number | 3.0 | Hard token budget multiplier inside tables to prevent row fragmentation (1.5–5.0). |
Example Input
{
"url": "https://docs.stripe.com/api/payment_intents",
"max_tokens": 400,
"overlap": 40,
"contentSelector": "main"
}📤 Output Payload
Each Actor run returns a structured JSON dataset where every item is one semantically-clean chunk:
[
{
"chunk_index": 0,
"token_count": 387,
"header_contexts": [
"Payment Intents API",
"Create a PaymentIntent"
],
"content": "## Create a PaymentIntent\n\nCreates a PaymentIntent object.\n\n### Parameters\n\n| Parameter | Type | Description |\n|---|---|---|\n| `amount` | integer | Amount intended to be collected..."
},
{
"chunk_index": 1,
"token_count": 412,
"header_contexts": [
"Create a PaymentIntent",
"Returns"
],
"content": "Returns a PaymentIntent object if the call succeeded. Returns an error if something goes wrong..."
}
]Output Fields Explained:
chunk_index: Sequential position of the chunk within the document.token_count: Exact BPE token count of this chunk's content.header_contexts: All active section headings that were open when this chunk was emitted.content: The clean, pristine GFM Markdown content ready for embedding.
🧪 Validated Against 50+ Real-World Documentation Sites
We stress-tested this engine against a comprehensive 50-URL live matrix covering Wikipedia, MDN, technical docs (React, AWS, Stripe), personal blogs (Paul Graham), forums (Stack Overflow), and company landing pages (Hugging Face, Google DeepMind, Microsoft Research). It achieved:
- 100% execution success across all accessible layouts.
- 0 broken code blocks or table rows (100% formatting preservation).
- Runaway overlap prevention on complex dense lists.
Live Metrics Highlight:
| Target URL / Layout Type | Clean Markdown | Chunks Generated | Min Tokens | Max Tokens | Avg Tokens | Code Block Integrity | |---|---|---|---|---|---|---| | Wikipedia: Retrieval-augmented generation | 25,214 chars | 33 | 101 | 480 | 353 | ✅ PASS | | Wikipedia: Transformer Architecture | 184,897 chars | 281 | 117 | 679 | 402 | ✅ PASS | | MDN: Array.prototype.reduce() | 17,763 chars | 14 | 328 | 510 | 399 | ✅ PASS | | Technical Doc: React useEffect Reference | 44,352 chars | 36 | 217 | 501 | 367 | ✅ PASS | | Personal Blog: How to Do Great Work (Paul Graham) | 69,016 chars | 45 | 65 | 472 | 408 | ✅ PASS | | Stripe API: PaymentIntents Reference | 21,182 chars | 27 | 70 | 689 | 401 | ✅ PASS | | Forum: Stack Overflow Sorted Array Q&A | 140,564 chars | 141 | 55 | 584 | 346 | ✅ PASS | | Company Blog: Astro Blog (Astro 4 Release) | 11,871 chars | 8 | 312 | 437 | 380 | ✅ PASS | | Aggregator: Hugging Face Blog Homepage | 11,698 chars | 16 | 183 | 579 | 428 | ✅ PASS |
⚙️ Performance Benchmarks
| Metric | Value |
|---|---|
| Median Latency (p50) | ~497ms end-to-end |
| Scraping Engine | Lightweight DOM parsing (no headless browser) |
| Token Tracking | cl100k_base BPE (GPT-4/GPT-4o compatible) |
| Memory Footprint | Resource-isolated, no persistent storage |
| Pricing | $2.00 / 1,000 chunks (pay-per-result, not per-run) |
❓ Frequently Asked Questions
Q: What types of pages does this work best on? A: It excels on developer documentation, API reference pages, technical guides, blog articles, and knowledge base content. Any structured, text-rich public web page.
Q: Does it work on sites protected by Cloudflare or other bot protections? A: The engine uses a multi-tier fetch pipeline. If direct access is blocked, it automatically falls back to a secondary content extraction layer to maximize success rates.
Q: How is this priced? A: You pay $2.00 per 1,000 chunks generated. A typical documentation page generates 8–15 chunks, meaning a full page costs less than $0.03. There are no monthly minimums, no seat fees, and no API key commitments.
Q: Can I use this to ingest private/internal documentation? A: This Actor only fetches publicly accessible URLs. It cannot bypass authentication or access pages behind a login wall.
Q: Which vector databases does the output work with? A: The output is plain JSON with string content fields. It is compatible with every major vector database including Pinecone, Weaviate, Chroma, Qdrant, pgvector, Milvus, and any LangChain / LlamaIndex embedding pipeline.
Q: Does it preserve code examples from documentation? A: Yes. This is one of its core differentiators. The engine specifically detects and protects Markdown code fences, refusing to split a chunk mid-code-block regardless of token budget.
Legal & Licensing
Copyright © 2026. All Rights Reserved. Private Proprietary Software. Usage is strictly governed by the Terms of Service and Privacy Policy.
