# RAG Docs Extractor - Documentation to Chunks (`ambitious_door/ragdocs-extractor`) Actor

Turn any documentation site into clean, RAG-ready chunks in a single call. Semantic boundaries, preserved structure, per-chunk metadata.

- **URL**: https://apify.com/ambitious_door/ragdocs-extractor.md
- **Developed by:** [C. K.](https://apify.com/ambitious_door) (community)
- **Categories:** AI, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 3 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $10.00 / 1,000 document processeds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/running/actors-in-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 Docs Extractor

Turn any documentation site into clean, RAG-ready chunks in a single call. Semantic boundaries, preserved structure, per-chunk metadata (source URL, heading path, token count). No post-processing. Pay per document processed.

### What it does

Most doc scrapers give you raw HTML or a single wall of text. You then spend hours cleaning, splitting, and fixing broken context before anything is usable in a vector store. This Actor eliminates that step entirely.

Give it a documentation URL. It crawls the site, strips navigation/chrome, converts to clean markdown, and splits each page into semantically meaningful chunks that respect heading boundaries. Every chunk includes the metadata you need for retrieval: source URL, heading path (so you know *where* in the doc tree it came from), and token count (so you can plan your embedding budget).

The output drops straight into any vector store or RAG pipeline without cleanup.

### Output format

Each chunk in the dataset contains:

| Field | Type | Description |
|-------|------|-------------|
| `content` | string | The chunk text in markdown or plain text |
| `heading_path` | string | Hierarchical path, e.g. `"Guide > Installation > Requirements"` |
| `chunk_index` | integer | Position of this chunk within its source document |
| `token_count` | integer | Token count (cl100k_base encoding) |
| `source_url` | string | The URL this chunk was extracted from |
| `document_title` | string | Page title |

### Input parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `startUrl` | string | *required* | Documentation URL to start crawling from |
| `maxPages` | integer | 50 | Maximum pages to crawl |
| `maxChunkTokens` | integer | 512 | Target max tokens per chunk |
| `crawlSameDomain` | boolean | true | Stay within the start URL's domain |
| `pathPrefix` | string | `""` | Only crawl paths starting with this prefix |
| `outputFormat` | string | `"markdown"` | `"markdown"` or `"plain_text"` |

### Example usage

#### Single page extraction

```json
{
    "startUrl": "https://docs.python.org/3/library/asyncio.html",
    "maxPages": 1
}
```

#### Full docs site

```json
{
    "startUrl": "https://fastapi.tiangolo.com/",
    "maxPages": 100,
    "pathPrefix": "/tutorial/",
    "maxChunkTokens": 256
}
```

### Pricing

This Actor uses the **pay-per-event** model. You are charged per document (page) successfully processed and chunked. No charge for pages that are skipped (empty, non-content).

### How the chunking works

1. **HTML cleaning** — strips navigation, sidebars, footers, cookie banners, and other non-content elements using a curated set of selectors. Falls back to `<article>`, `<main>`, or `<body>`.
2. **Markdown conversion** — converts the cleaned HTML to structured markdown, preserving headings, code blocks, tables, lists, and links.
3. **Semantic splitting** — splits on heading boundaries first, then paragraph boundaries, then sentence boundaries. Each chunk inherits the heading hierarchy from its position in the document.
4. **Token counting** — uses `cl100k_base` (the encoding used by GPT-4 and most modern embeddings) for accurate token counts.

### Responsible use

- This Actor **respects `robots.txt`** by default (enforced by Crawlee).
- It identifies itself with a descriptive `User-Agent` header so site owners can identify and block it.
- Crawlee's built-in autoscaling keeps request rates reasonable and avoids overloading target servers.
- **You are responsible** for ensuring your use complies with the target site's Terms of Service. Only crawl content you have the right to access and process.

### Built with

- [Crawlee](https://crawlee.dev/python/) for reliable crawling (robots.txt compliant)
- [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/) for HTML parsing
- [tiktoken](https://github.com/openai/tiktoken) for token counting

# Actor input Schema

## `startUrl` (type: `string`):

The starting URL of the documentation site to extract.

## `maxPages` (type: `integer`):

Maximum number of pages to crawl. Set to 1 to extract a single page.

## `maxChunkTokens` (type: `integer`):

Target maximum token count per chunk. Chunks may be slightly larger to preserve semantic boundaries.

## `crawlSameDomain` (type: `boolean`):

Only follow links within the same domain as the start URL.

## `pathPrefix` (type: `string`):

Only crawl pages whose path starts with this prefix (e.g., '/docs/'). Leave empty to crawl the whole domain.

## `outputFormat` (type: `string`):

Format for chunk content.

## Actor input object example

```json
{
  "startUrl": "https://docs.python.org/3/library/functions.html",
  "maxPages": 50,
  "maxChunkTokens": 512,
  "crawlSameDomain": true,
  "pathPrefix": "",
  "outputFormat": "markdown"
}
```

# 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 = {
    "startUrl": "https://docs.python.org/3/library/functions.html"
};

// Run the Actor and wait for it to finish
const run = await client.actor("ambitious_door/ragdocs-extractor").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 = { "startUrl": "https://docs.python.org/3/library/functions.html" }

# Run the Actor and wait for it to finish
run = client.actor("ambitious_door/ragdocs-extractor").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 '{
  "startUrl": "https://docs.python.org/3/library/functions.html"
}' |
apify call ambitious_door/ragdocs-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,ambitious_door/ragdocs-extractor"
        }
    }
}
```

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/XrYj1devlCVLcqP76/builds/yuJJO59cVtsGQYeJb/openapi.json
