# RAG Data Ingestion: Website to AI Knowledge Base (`0xysn/rag-data-ingestion-website-to-ai-knowledge-base`) Actor

Master complex documentation with a premium scraper that flattens Shadow DOM and handles modern web components. Delivers clean, token-accurate Markdown pre-chunked for immediate RAG ingestion into Pinecone, Weaviate, or LangChain. Optimized for high-fidelity LLM training data.

- **URL**: https://apify.com/0xysn/rag-data-ingestion-website-to-ai-knowledge-base.md
- **Developed by:** [tekk](https://apify.com/0xysn) (community)
- **Categories:** AI, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 premium scraped pages

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Universal AI Knowledge Scraper — Premium RAG Ingestion Engine

> **The high-fidelity bridge between the complex web and your LLM.** Convert any website or documentation portal into cleaned, chunked, and token-accurate Markdown optimized for RAG pipelines.

Build production-grade RAG (Retrieval-Augmented Generation) datasets with a single Actor run. Feed the output directly into **Pinecone, Weaviate, Qdrant, ChromaDB**, or any vector store.

---

### 🛡️ Why Use This Actor?

Most scrapers return empty strings on modern documentation sites. This Actor was built to solve the "Invisible Web" problem.

| Feature | Standard Scrapers | This Actor |
| :--- | :---: | :---: |
| **Vanilla HTML** | ✅ | ✅ |
| **Shadow DOM / Web Components** | ❌ (Empty Output) | ✅ (Full Flattening) |
| **Token Tracking** | ❌ (Manual Regex) | ✅ (Native Tiktoken) |
| **Modern Code Blocks** | ❌ (Garbled) | ✅ (Clean GFM) |

- **Built-in Token Counting for Budget Management** — Every record includes a `usage` object with exact token counts, encoding type, and chunk parameters. Enterprise teams can calculate embedding costs *before* hitting the OpenAI API.
- **Shadow DOM Extraction** — Successfully captures content from Shadow DOM-heavy sites (like Shoelace Web Components) where standard crawlers see nothing.
- **Zero-Config Extraction** — No CSS selectors to maintain. The density-based Readability algorithm adapts to any site layout automatically.
- **Antifragile Stealth** — Bézier-curve mouse simulation and fingerprint rotation make this Actor invisible to Cloudflare, Akamai, and behavioral detection systems.
- **CU-Optimized** — Resource interception blocks images, fonts, and media. You get lower memory usage and higher concurrency at the same price.

---

### 🚀 Key Features

- **Hybrid Discovery** — Priority parsing of `sitemap.xml` with fallback to recursive `<a>` tag extraction.
- **Universal Extraction** — Powered by Mozilla's Readability algorithm with recursive Shadow DOM flattening.
- **Clean Markdown Output** — Converts HTML to Markdown via Turndown with GFM support (tables, code blocks).
- **Token-Aware Chunking** — Splits content using `tiktoken` (GPT-4o / o1 encodings) into configurable chunk sizes with overlap.
- **Bloom Filter Dedup** — O(1) URL deduplication prevents infinite loops and duplicate scraping.

---

### 📦 Output Format

Each record is a standardized JSON object ready for vector database ingestion:
```json
{
  "metadata": {
    "source_url": "[https://docs.example.com/api/auth](https://docs.example.com/api/auth)",
    "title": "Authentication — API Docs",
    "crawled_at": "2026-04-30T13:00:00Z",
    "site_name": "Example Docs",
    "lang": "en"
  },
  "usage": {
    "total_tokens": 1010,
    "total_chunks": 2,
    "encoding": "o200k_base",
    "chunk_size": 512,
    "chunk_overlap": 50
  },
  "content": [
    {
      "chunk_id": 1,
      "token_count": 512,
      "text": "#### Authentication\n\nAll API requests require a Bearer token..."
    }
  ],
  "raw_markdown": "#### Authentication\n\nAll API requests require a Bearer token..."
}

# Actor input Schema

## `startUrls` (type: `array`):

One or more URLs to begin crawling from.
## `maxCrawlDepth` (type: `integer`):

Maximum link-following depth. Set to 0 to only scrape start URLs.
## `maxRequestsPerCrawl` (type: `integer`):

Hard limit on total pages scraped in a single run.
## `maxConcurrency` (type: `integer`):

Maximum parallel pages. 5-10 is recommended for 2GB memory.
## `chunkSize` (type: `integer`):

Target number of tokens per content chunk.
## `chunkOverlap` (type: `integer`):

Overlapping tokens between chunks for context.
## `tiktokenEncoding` (type: `string`):

The tokenizer encoding to use.
## `useSitemap` (type: `boolean`):

Disable this for faster quality tests. Discovers sitemap.xml before crawling.
## `includeGlobs` (type: `array`):

Only crawl URLs matching these glob patterns.
## `excludeGlobs` (type: `array`):

Skip URLs matching these glob patterns.
## `minTextLength` (type: `integer`):

Discard pages with text shorter than this threshold.
## `maxRedirects` (type: `integer`):

Maximum number of redirects to follow per request.
## `proxyConfiguration` (type: `object`):

Proxy settings for anti-bot bypass.
## `fingerprintRotationInterval` (type: `integer`):

Rotate browser fingerprints every N requests.
## `waitForSelector` (type: `string`):

Optional CSS selector to wait for before extracting content.
## `customCodeBlockSelectors` (type: `array`):

CSS selectors for non-standard code containers.
## `outputFormat` (type: `string`):

Choose the output structure format.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://example.com"
    }
  ],
  "maxCrawlDepth": 1,
  "maxRequestsPerCrawl": 10,
  "maxConcurrency": 5,
  "chunkSize": 512,
  "chunkOverlap": 50,
  "tiktokenEncoding": "o200k_base",
  "useSitemap": false,
  "includeGlobs": [],
  "excludeGlobs": [],
  "minTextLength": 150,
  "maxRedirects": 5,
  "proxyConfiguration": {
    "useApifyProxy": true
  },
  "fingerprintRotationInterval": 15,
  "waitForSelector": "",
  "customCodeBlockSelectors": [],
  "outputFormat": "chunked"
}
````

# 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 = {
    "startUrls": [
        {
            "url": "https://example.com"
        }
    ],
    "proxyConfiguration": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("0xysn/rag-data-ingestion-website-to-ai-knowledge-base").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 = {
    "startUrls": [{ "url": "https://example.com" }],
    "proxyConfiguration": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("0xysn/rag-data-ingestion-website-to-ai-knowledge-base").call(run_input=run_input)

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

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

```

## CLI example

```bash
echo '{
  "startUrls": [
    {
      "url": "https://example.com"
    }
  ],
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}' |
apify call 0xysn/rag-data-ingestion-website-to-ai-knowledge-base --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=0xysn/rag-data-ingestion-website-to-ai-knowledge-base",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "RAG Data Ingestion: Website to AI Knowledge Base",
        "description": "Master complex documentation with a premium scraper that flattens Shadow DOM and handles modern web components. Delivers clean, token-accurate Markdown pre-chunked for immediate RAG ingestion into Pinecone, Weaviate, or LangChain. Optimized for high-fidelity LLM training data.",
        "version": "1.0",
        "x-build-id": "i8Rvh64h6LwGGGB2g"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/0xysn~rag-data-ingestion-website-to-ai-knowledge-base/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-0xysn-rag-data-ingestion-website-to-ai-knowledge-base",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/0xysn~rag-data-ingestion-website-to-ai-knowledge-base/runs": {
            "post": {
                "operationId": "runs-sync-0xysn-rag-data-ingestion-website-to-ai-knowledge-base",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/0xysn~rag-data-ingestion-website-to-ai-knowledge-base/run-sync": {
            "post": {
                "operationId": "run-sync-0xysn-rag-data-ingestion-website-to-ai-knowledge-base",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "startUrls"
                ],
                "properties": {
                    "startUrls": {
                        "title": "Start URLs",
                        "type": "array",
                        "description": "One or more URLs to begin crawling from.",
                        "items": {
                            "type": "object",
                            "required": [
                                "url"
                            ],
                            "properties": {
                                "url": {
                                    "type": "string",
                                    "title": "URL of a web page",
                                    "format": "uri"
                                }
                            }
                        }
                    },
                    "maxCrawlDepth": {
                        "title": "Max Crawl Depth",
                        "minimum": 0,
                        "maximum": 50,
                        "type": "integer",
                        "description": "Maximum link-following depth. Set to 0 to only scrape start URLs.",
                        "default": 1
                    },
                    "maxRequestsPerCrawl": {
                        "title": "Max Pages Per Run",
                        "minimum": 1,
                        "maximum": 100000,
                        "type": "integer",
                        "description": "Hard limit on total pages scraped in a single run.",
                        "default": 10
                    },
                    "maxConcurrency": {
                        "title": "Max Concurrency",
                        "minimum": 1,
                        "maximum": 50,
                        "type": "integer",
                        "description": "Maximum parallel pages. 5-10 is recommended for 2GB memory.",
                        "default": 5
                    },
                    "chunkSize": {
                        "title": "Chunk Size (tokens)",
                        "minimum": 64,
                        "maximum": 8192,
                        "type": "integer",
                        "description": "Target number of tokens per content chunk.",
                        "default": 512
                    },
                    "chunkOverlap": {
                        "title": "Chunk Overlap (tokens)",
                        "minimum": 0,
                        "maximum": 512,
                        "type": "integer",
                        "description": "Overlapping tokens between chunks for context.",
                        "default": 50
                    },
                    "tiktokenEncoding": {
                        "title": "Tiktoken Encoding",
                        "enum": [
                            "o200k_base",
                            "cl100k_base"
                        ],
                        "type": "string",
                        "description": "The tokenizer encoding to use.",
                        "default": "o200k_base"
                    },
                    "useSitemap": {
                        "title": "Use Sitemap Discovery",
                        "type": "boolean",
                        "description": "Disable this for faster quality tests. Discovers sitemap.xml before crawling.",
                        "default": false
                    },
                    "includeGlobs": {
                        "title": "Include URL Patterns",
                        "type": "array",
                        "description": "Only crawl URLs matching these glob patterns.",
                        "default": [],
                        "items": {
                            "type": "object",
                            "required": [
                                "glob"
                            ],
                            "properties": {
                                "glob": {
                                    "type": "string",
                                    "title": "Glob of a web page"
                                }
                            }
                        }
                    },
                    "excludeGlobs": {
                        "title": "Exclude URL Patterns",
                        "type": "array",
                        "description": "Skip URLs matching these glob patterns.",
                        "default": [],
                        "items": {
                            "type": "object",
                            "required": [
                                "glob"
                            ],
                            "properties": {
                                "glob": {
                                    "type": "string",
                                    "title": "Glob of a web page"
                                }
                            }
                        }
                    },
                    "minTextLength": {
                        "title": "Min Text Length (chars)",
                        "minimum": 0,
                        "maximum": 5000,
                        "type": "integer",
                        "description": "Discard pages with text shorter than this threshold.",
                        "default": 150
                    },
                    "maxRedirects": {
                        "title": "Max Redirects",
                        "minimum": 0,
                        "maximum": 20,
                        "type": "integer",
                        "description": "Maximum number of redirects to follow per request.",
                        "default": 5
                    },
                    "proxyConfiguration": {
                        "title": "Proxy Configuration",
                        "type": "object",
                        "description": "Proxy settings for anti-bot bypass."
                    },
                    "fingerprintRotationInterval": {
                        "title": "Fingerprint Rotation Interval",
                        "minimum": 1,
                        "maximum": 100,
                        "type": "integer",
                        "description": "Rotate browser fingerprints every N requests.",
                        "default": 15
                    },
                    "waitForSelector": {
                        "title": "Wait For Selector",
                        "type": "string",
                        "description": "Optional CSS selector to wait for before extracting content.",
                        "default": ""
                    },
                    "customCodeBlockSelectors": {
                        "title": "Custom Code Block Selectors",
                        "type": "array",
                        "description": "CSS selectors for non-standard code containers.",
                        "default": [],
                        "items": {
                            "type": "string"
                        }
                    },
                    "outputFormat": {
                        "title": "Output Format",
                        "enum": [
                            "chunked",
                            "full"
                        ],
                        "type": "string",
                        "description": "Choose the output structure format.",
                        "default": "chunked"
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
