# Website to RAG Dataset with Source Spans (`danielmichalek/website-to-rag-dataset`) Actor

Prepare website content with heading paths, original anchors and exact text spans. The report exports pages and compatible chunks for retrieval. Send public URLs or saved HTML through the input to create one bounded corpus report.

- **URL**: https://apify.com/danielmichalek/website-to-rag-dataset.md
- **Developed by:** [Daniel Michałek](https://apify.com/danielmichalek) (community)
- **Categories:** Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$30.00 / 1,000 source-linked rag corpus reports

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/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

## Website to RAG Dataset with Source Spans

### What it does

Prepare static website content for a retrieval workflow with evidence that can be traced back to a document snapshot. Choose a bounded public HTML crawl or supply exported HTML. The result contains heading paths, paragraphs, list items, code and table blocks, original anchors and exact positions in normalized text. It also includes pages and chunks compatible with the existing RAG Delta Sync character-based contract.

This is a preprocessing tool. It makes no model or embedding calls and does not connect to a vector database. Input text remains untrusted source data. An extracted citation identifies a location; it does not prove that an answer is true or that the live website is unchanged.

### Input

Set mode to suppliedHtml and provide documents with id, sourceUrl and html. A sourceUrl in this mode is a label supplied by you. Set mode to crawl and provide startUrls for public static HTML pages. Use one mode at a time. The defaults demonstrate supplied HTML; examples/network-input.json demonstrates a real public URL.

The optional selector identifies the main content. A missing or invalid selector rejects that source. Without a selector, one main element is preferred, followed by one article; a body fallback is explicitly flagged. Scripts and forms are excluded. Navigation and other boilerplate are removed by default. Static HTML extraction does not execute JavaScript.

Limits are 20 documents or page attempts, 500000 bytes per HTML source, 2000000 serialized supplied-input bytes, 25000 DOM nodes and 256 levels per document, 20000 UTF-16 text units per exported page, 2000 blocks and 2000 chunks per report, and 6000000 serialized report bytes. Limits interact. Pages exceeding a text limit are rejected with an explicit error. Long title and heading labels may be shortened with explicit metadata. Source text spans remain intact.

### Output

One dataset record contains pages, documents, blocks, chunks, duplicate groups and explicit source errors. PAGES_JSONL and CHUNKS_JSONL contain one JSON record per line. CHUNKS_CSV is a spreadsheet export and REPORT is a Markdown overview. All exact duplicate content is retained with its source references. No automatic cross-source deduplication discards context.

Blocks and chunks use start-inclusive/end-exclusive offsets in NFC_NORMALIZED_TEXT_V1, measured in UTF16_CODE_UNITS. These are positions in the exported text, not byte positions in raw HTML. DOM paths refer to the original parsed static DOM before boilerplate removal. Citation URLs use an existing unique ancestor or heading anchor, or the document URL. A block ID is never presented as a fabricated URL fragment.

The htmlSha256 hashes the UTF-8 encoding of the decoded HTML string. Fetched evidence separately records the hash of decompressed HTTP body bytes and the content type. Supplied evidence labels the input string and does not assert a network fetch. Metadata, source URLs and content can contain sensitive information; use authorized material and review exports before sharing.

### Downstream integration

Pass report.pages as currentPages to RAG Delta Sync. This Actor dataset contains one aggregate record, so its dataset ID is not a page-per-row input dataset. Alternatively import PAGES_JSONL into a separate page dataset. Keep chunkChars unchanged: chunk IDs use the exact rag-delta-v1 URL/content-hash/occurrence contract. Offsets use UTF-16, while the chunk budget counts Unicode code points.

siteCoverage is always NOT_ASSERTED and downstreamSnapshotComplete is false. A successful bounded crawl or supplied batch does not authorize deletion of missing website pages. Review partial sources and configure deletion gates independently. CSV formula prefixes are made literal for spreadsheet safety; JSONL preserves the exact original chunk text.

### Pricing and cost control

Pricing uses one aggregate corpus report. The active price, when published, is shown on the Pricing tab. Cost measurements apply to the tested input and pricing tier; they do not establish a universal maximum cost, paid demand or realized margin. A local build does not activate a Store price. Local SDK execution uses local storage without billed events.

The runtime allows one aggregate report, at most 80 HTTP requests and 120 seconds overall, with a shorter transport deadline and time reserved for exports. Redirect and robots requests count. The bounded body reader caps individual responses and separately tracks observed HTTP body payload and decoded data. Total billed network traffic requires provider measurements. The final read chunk can cross an observed-body threshold before the connection is closed. No proxy or retry service is used.

Only a delivered report is eligible for its event. When no source can be exported, the run fails with FETCH_DIAGNOSTICS and no report delivery. A PREPARED delivery requires reconciliation. A verified COMPLETE replay reuses stored exports and makes no new crawl or charge.

### Limitations and fair use

Use websites and HTML you are authorized to process. The crawler uses its transparent GnyPciorRAGDataset product identity, honors the exact robots decision for each destination, and checks policies again after allowed redirects. Missing404/410 robots files permit a page request; authentication failures, rate limits, server failures and malformed policies do not become an empty allowed policy. A conservative maximum Crawl-delay is respected; delays beyond the bounded run policy are refused.

Crawls stay within declared seed origins, with same-host HTTP-to-HTTPS upgrades. Cross-origin redirects and base elements cannot silently extend the crawl. CAPTCHA/challenge pages, protected content and explicit noai/noarchive or ai-input=no restrictions are not exported. The Actor does not solve CAPTCHA, authenticate, render browser-only pages, infer legal rights or guarantee complete crawling. Public IP checks, pinned DNS lookup and normal TLS certificate checks protect the request route.

### Example

examples/input.json provides two demonstration HTML documents with headings and existing anchors. Source URLs there are supplied labels. examples/output.json is generated from the actual SDK entry point. examples/network-input.json requests example.com with a one-page bound. Source storage remains in the requesting account dataset and key-value store under its retention settings.

### Build and tests

The package uses exact SDK/parser versions and retains the existing basic-ftp override. npm ci runs with lifecycle scripts disabled. npm test runs pure extraction, crawl-policy and delivery tests. npm start runs the normal Apify SDK entry point with an explicit heap budget. Local/runtime and future cloud receipts state their own evidence scope; local success alone is not publication or a measured commercial margin.

# Actor input Schema

## `mode` (type: `string`):

Choose supplied HTML or a bounded static public website crawl.

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

In suppliedHtml mode provide unique id/sourceUrl/html objects. sourceUrl is a provenance label, not proof of a fetch. Optional selector overrides the global selector.

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

In crawl mode provide up to20 public HTTP/HTTPS URL strings. Other-origin redirects are refused; HTTP-to-HTTPS upgrades on the same host are permitted. No credentials or sensitive query parameters.

## `selector` (type: `string`):

Optional basic CSS selector. A missing match is an explicit source error, never a silent whole-page fallback. Expensive :has/:contains/:matches selectors are refused.

## `chunkChars` (type: `integer`):

200–4000 Unicode code points per chunk. Keep this setting unchanged in downstream Delta Sync. Document offsets use UTF-16 code units.

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

1–20 seed or discovered page attempts. Supplied documents must fit this bound. A bounded crawl never asserts full site coverage.

## `maxDepth` (type: `integer`):

0–2 same-origin link levels after each seed. Zero processes only the requested seed pages and their allowed redirects.

## `removeBoilerplate` (type: `boolean`):

Remove navigation, headers, footers, asides and dialogs. Scripts and form controls are excluded in either setting.

## `maxItems` (type: `integer`):

One aggregate corpus report is emitted. Chunk rows are in CHUNKS_JSONL and CHUNKS_CSV.

## Actor input object example

```json
{
  "mode": "suppliedHtml",
  "documents": [
    {
      "id": "guide",
      "sourceUrl": "https://example.com/guide",
      "html": "<!doctype html><html lang=\"en\"><head><title>Knowledge guide</title></head><body><nav>Navigation</nav><main id=\"guide\"><h1>Knowledge guide</h1><h2 id=\"delivery\">Delivery</h2><p>Standard delivery takes three working days. Contact support when a delivery needs review.</p><h2 id=\"returns\">Returns</h2><p>Keep the order reference when requesting a return. Review the original source before publishing an answer.</p><pre>status = \"ready\"\n  preserve_indentation()</pre></main></body></html>"
    },
    {
      "id": "support",
      "sourceUrl": "https://example.com/support",
      "html": "<html lang=\"en\"><head><title>Support</title></head><body><main id=\"support\"><h1>Support</h1><p>Include the order reference and a description of the issue. This is supplied demonstration content, not a fetched support page.</p></main></body></html>"
    }
  ],
  "startUrls": [],
  "selector": "",
  "chunkChars": 200,
  "maxPages": 10,
  "maxDepth": 1,
  "removeBoilerplate": true,
  "maxItems": 1
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `corpus` (type: `string`):

No description

## `pages` (type: `string`):

No description

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

No description

## `csv` (type: `string`):

No description

## `report` (type: `string`):

No description

# 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 = {
    "documents": [
        {
            "id": "guide",
            "sourceUrl": "https://example.com/guide",
            "html": "<!doctype html><html lang=\"en\"><head><title>Knowledge guide</title></head><body><nav>Navigation</nav><main id=\"guide\"><h1>Knowledge guide</h1><h2 id=\"delivery\">Delivery</h2><p>Standard delivery takes three working days. Contact support when a delivery needs review.</p><h2 id=\"returns\">Returns</h2><p>Keep the order reference when requesting a return. Review the original source before publishing an answer.</p><pre>status = \"ready\"\n  preserve_indentation()</pre></main></body></html>"
        },
        {
            "id": "support",
            "sourceUrl": "https://example.com/support",
            "html": "<html lang=\"en\"><head><title>Support</title></head><body><main id=\"support\"><h1>Support</h1><p>Include the order reference and a description of the issue. This is supplied demonstration content, not a fetched support page.</p></main></body></html>"
        }
    ],
    "chunkChars": 200
};

// Run the Actor and wait for it to finish
const run = await client.actor("danielmichalek/website-to-rag-dataset").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 = {
    "documents": [
        {
            "id": "guide",
            "sourceUrl": "https://example.com/guide",
            "html": """<!doctype html><html lang=\"en\"><head><title>Knowledge guide</title></head><body><nav>Navigation</nav><main id=\"guide\"><h1>Knowledge guide</h1><h2 id=\"delivery\">Delivery</h2><p>Standard delivery takes three working days. Contact support when a delivery needs review.</p><h2 id=\"returns\">Returns</h2><p>Keep the order reference when requesting a return. Review the original source before publishing an answer.</p><pre>status = \"ready\"
  preserve_indentation()</pre></main></body></html>""",
        },
        {
            "id": "support",
            "sourceUrl": "https://example.com/support",
            "html": "<html lang=\"en\"><head><title>Support</title></head><body><main id=\"support\"><h1>Support</h1><p>Include the order reference and a description of the issue. This is supplied demonstration content, not a fetched support page.</p></main></body></html>",
        },
    ],
    "chunkChars": 200,
}

# Run the Actor and wait for it to finish
run = client.actor("danielmichalek/website-to-rag-dataset").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 '{
  "documents": [
    {
      "id": "guide",
      "sourceUrl": "https://example.com/guide",
      "html": "<!doctype html><html lang=\\"en\\"><head><title>Knowledge guide</title></head><body><nav>Navigation</nav><main id=\\"guide\\"><h1>Knowledge guide</h1><h2 id=\\"delivery\\">Delivery</h2><p>Standard delivery takes three working days. Contact support when a delivery needs review.</p><h2 id=\\"returns\\">Returns</h2><p>Keep the order reference when requesting a return. Review the original source before publishing an answer.</p><pre>status = \\"ready\\"\\n  preserve_indentation()</pre></main></body></html>"
    },
    {
      "id": "support",
      "sourceUrl": "https://example.com/support",
      "html": "<html lang=\\"en\\"><head><title>Support</title></head><body><main id=\\"support\\"><h1>Support</h1><p>Include the order reference and a description of the issue. This is supplied demonstration content, not a fetched support page.</p></main></body></html>"
    }
  ],
  "chunkChars": 200
}' |
apify call danielmichalek/website-to-rag-dataset --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,danielmichalek/website-to-rag-dataset"
        }
    }
}
```

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/oZydjcaBzFUcTZadW/builds/HbaoS3A7mNfT5OhQf/openapi.json
