# RAG Table-Aware Markdown & HTML Chunker (MCP) (`snowy_divide_r1t/rag-table-aware-chunker`) Actor

Zero-scraping deterministic Markdown & HTML chunker for RAG pipelines. Protects tables intact, auto-repeats headers on oversized splits, adds heading breadcrumbs & CJK token counts.

- **URL**: https://apify.com/snowy_divide_r1t/rag-table-aware-chunker.md
- **Developed by:** [對帳 秒](https://apify.com/snowy_divide_r1t) (community)
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$2.00 / 1,000 document chunkeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## RAG Table-Aware Markdown & HTML Chunker (MCP)

**Stop naive text splitters from slicing financial tables in half and destroying your RAG retrieval quality.**

Standard character splitters (`RecursiveCharacterTextSplitter`) tear Markdown and HTML tables apart mid-row, stripping column headers from downstream rows so vector search retrieves meaningless numbers.

**RAG Table-Aware Chunker** is a **100% zero-scraping, zero-dependency, pure-compute Actor & MCP Tool** that transforms raw Markdown or HTML strings into retrieval-ready JSON chunks:

- **Atomic Table Protection**: Keeps tables intact whenever they fit within `maxTokens`.
- **Header-Repeating Row Splitting**: Automatically splits oversized tables along row boundaries and prepends the original table header row to every continuation chunk (`tableSplitPart: "1/3"`, `"2/3"`, `"3/3"`).
- **Native HTML Table Support**: Converts HTML `<table>`, `<h1>`-`<h6>`, and `<pre><code>` blocks into clean Markdown chunks without browser overhead.
- **Hierarchical Heading Breadcrumbs**: Tracks `H1 > H2 > H3` context on every chunk so embeddings always know where a row came from.
- **CJK-Aware Deterministic Token Estimator**: Accurately accounts for English words, CJK characters (Chinese/Japanese/Korean), numbers, and table pipe punctuation across `openai-o200k`, `openai-cl100k`, `claude`, and `gemini` profiles.

***

### Pricing (Pay-Per-Event)

- **`document-chunked`**: **`$0.002` USD** per non-empty document (`$2.00` per 1,000 documents).
- Empty inputs are never charged. Zero proxies, zero external API calls, minimal 128–256MB memory footprint.

***

### Example Input

```json
{
  "docId": "q4-pricing-guide",
  "document": "# Enterprise Plans\n\n## Tier Comparison\n\n| Tier | Seats | Monthly Price |\n|---|---|---|\n| Starter | 5 | $49 |\n| Growth | 25 | $199 |\n| Enterprise | Unlimited | $799 |\n",
  "options": {
    "format": "auto",
    "maxTokens": 256,
    "repeatTableHeaders": true,
    "injectBreadcrumbs": true,
    "tokenizerProfile": "openai-o200k"
  }
}
```

### Example Output

```json
{
  "docId": "q4-pricing-guide",
  "chunkIndex": 0,
  "totalChunks": 1,
  "chunkType": "table",
  "breadcrumbs": ["Enterprise Plans", "Tier Comparison"],
  "tokenCount": 62,
  "charCount": 195,
  "tableSplitPart": null,
  "content": "[Section: Enterprise Plans > Tier Comparison]\n\n| Tier | Seats | Monthly Price |\n|---|---|---|\n| Starter | 5 | $49 |\n| Growth | 25 | $199 |\n| Enterprise | Unlimited | $799 |"
}
```

***

### Security & Compliance

This Actor operates **100% in memory** on text strings supplied directly in the JSON payload. It does not accept external URLs, does not scrape websites, and performs zero outbound HTTP requests.

# Actor input Schema

## `document` (type: `string`):

Raw Markdown or HTML string to split into table-aware RAG chunks. Mutually complementary with 'documents'.

## `docId` (type: `string`):

Optional identifier for the single document.

## `documents` (type: `array`):

Array of objects { id, content, metadata } for batch RAG chunking (up to 500 documents per run).

## `options` (type: `object`):

Deterministic settings for format detection, token budget, table header repetition, and heading breadcrumbs.

## Actor input object example

```json
{
  "document": "# Q4 Financial Report\n\n## Regional Margin Summary\n\n| Region | Revenue | Margin |\n|---|---|---|\n| North America | $1,250,000 | 76% |\n| Europe | $840,000 | 72% |\n| APAC | $620,000 | 78% |\n",
  "docId": "doc-1",
  "options": {
    "format": "auto",
    "maxTokens": 512,
    "overlapTokens": 40,
    "repeatTableHeaders": true,
    "preserveCodeBlocks": true,
    "injectBreadcrumbs": true,
    "tokenizerProfile": "openai-o200k"
  }
}
```

# Actor output Schema

## `overview` (type: `string`):

Structured dataset view showing chunk index, chunk type, table split part, and token count.

## `chunks` (type: `string`):

Complete chunk payloads ready for vector database ingestion or MCP agent consumption.

## `summary` (type: `string`):

Aggregated chunking statistics stored in the default Key-Value Store under the OUTPUT key.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "document": `# Q4 Financial Report

## Regional Margin Summary

| Region | Revenue | Margin |
|---|---|---|
| North America | $1,250,000 | 76% |
| Europe | $840,000 | 72% |
| APAC | $620,000 | 78% |`
};

// Run the Actor and wait for it to finish
const run = await client.actor("snowy_divide_r1t/rag-table-aware-chunker").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "document": """# Q4 Financial Report

## Regional Margin Summary

| Region | Revenue | Margin |
|---|---|---|
| North America | $1,250,000 | 76% |
| Europe | $840,000 | 72% |
| APAC | $620,000 | 78% |
""" }

# Run the Actor and wait for it to finish
run = client.actor("snowy_divide_r1t/rag-table-aware-chunker").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "document": "# Q4 Financial Report\\n\\n## Regional Margin Summary\\n\\n| Region | Revenue | Margin |\\n|---|---|---|\\n| North America | $1,250,000 | 76% |\\n| Europe | $840,000 | 72% |\\n| APAC | $620,000 | 78% |\\n"
}' |
apify call snowy_divide_r1t/rag-table-aware-chunker --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,snowy_divide_r1t/rag-table-aware-chunker"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Pbbi0E9XK8Wq1dy74/builds/Ub3BAKpEpNYNFKULd/openapi.json
