# RAG Corpus Provenance Packager (`flintglade/rag-corpus-provenance-packager`) Actor

Package rights-declared HTML, Markdown, text, and born-digital PDFs into deterministic RAG pages, traceable chunks, and verified manifests.

- **URL**: https://apify.com/flintglade/rag-corpus-provenance-packager.md
- **Developed by:** [Flintglade](https://apify.com/flintglade) (community)
- **Categories:** AI, Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $20.00 / 1,000 packaged pages

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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

## RAG Corpus Provenance Packager

Turn explicit, rights-declared HTML, Markdown, text, and born-digital PDF sources into deterministic, deduplicated corpus pages, traceable chunks, and a portable evidence package.

### What this does not do

- No open-web crawling or link following.
- No paywall or authentication bypass.
- No OCR in version 1.
- No vector embedding generation.
- No legal conclusion about reuse rights.
- No LLM summaries or synthetic citations.
- No billing by both page and chunk.

### Sources and authorization

Every source must be one explicit HTTPS URL or one record from an Apify key-value store you can read. Every source also requires a `rightsBasis` declaration with evidence text or an evidence URL. The declaration and any detected indicators are preserved as provenance; they are not legal advice and do not establish permission. A `metadata_only` declaration is refused because this Actor's output contains source text.

HTML uses direct HTTP responses only. Markdown and plain text must be UTF-8 or UTF-16. PDFs must contain extractable text; image-only pages return an uncharged `ocr_required` result. HTML selectors are explicit and bounded. The Actor never follows links discovered in a source.

### Input example

```json
{
  "sources": [
    {
      "url": "https://flintglade-tools.github.io/apify-fixtures/rag/sample.html",
      "rightsBasis": {
        "type": "user_owned",
        "evidence": "Flintglade-controlled public fixture"
      },
      "formatHint": "html",
      "excludeSelectors": ["footer"]
    }
  ],
  "chunking": {"strategy": "character", "size": 1000, "overlap": 150},
  "dedupe": {"mode": "exact"},
  "retainRaw": false,
  "concurrency": 1
}
```

### Outputs

The default dataset contains one result per page plus one uncharged run summary. Admitted pages include stable document/page IDs, canonical and raw hashes, rights evidence, extraction indicators, chunk IDs, and invalidation links. Exact duplicates and refusals remain visible but uncharged.

Child chunks are written to a run-specific named dataset and are included in the page price. Every chunk carries its page and document IDs, source and page locators, character range, text hash, rights declaration, and chunker version.

The default key-value store receives:

- `CORPUS_MANIFEST.json`
- `EXTRACTED_DOCUMENT.jsonl`
- `CORPUS_PACKAGE.zip`
- `VERIFICATION.json`
- `ARTIFACT_MANIFEST.json`
- generated `RAW_SOURCE_*` records only when `retainRaw` is explicitly enabled

Example admitted page fields:

```json
{
  "status": "ok",
  "charge": {"event": "packaged-page", "chargeable": true},
  "data": {
    "pageId": "page_...",
    "canonicalHash": "sha256:...",
    "chunkCount": 2,
    "duplicateOfPageId": null,
    "rightsBasis": {"type": "user_owned", "evidence": "Flintglade-controlled public fixture"}
  }
}
```

### Pricing

`packaged-page` costs **$0.02 per admitted source page**. Generated chunks are included and are never charged separately. For example, three admitted pages cost $0.06 in Actor events, plus Apify platform usage. Blocked URLs, source outages, unsupported media, oversized sources, parse failures, rights refusals, OCR-required pages, exact duplicates after the first page, and charge-limit rows are uncharged.

### Baseline behavior

Without `baselineStoreId`, each run is stateless. With an existing authorized KVS, admitted pages compare their canonical hash to the prior page record and report `baseline_created`, `unchanged`, or `changed`. Changed pages list the superseded hash and prior chunk IDs. Baseline state is committed only after Apify confirms the paid page event, and a concurrent baseline change is preserved rather than overwritten.

### Limits

At most 100 sources, 50 MB per source, 2,000 PDF pages per run, and 250,000 chunks per run. Configured source concurrency is bounded to four; the runtime may reduce it to one so the next source is not scheduled after the paid-event budget is exhausted. The run timeout is 900 seconds, with 2 GB default memory.

### Support

See [SUPPORT.md](SUPPORT.md) for reproducible issue-report details. Never include private source content, signed URLs, storage tokens, or credentials in a support request.

# Actor input Schema

## `inputSchemaVersion` (type: `integer`):

Versioned runtime input contract.

## `sources` (type: `array`):

Each source selects one HTTPS URL or one user-authorized Apify KVS record and includes an explicit rights declaration. This declaration is recorded, not legally validated.

## `chunking` (type: `object`):

Character chunking with a stable version, size, and overlap.

## `dedupe` (type: `object`):

Version 1 performs exact canonical-content deduplication only.

## `baselineStoreId` (type: `string`):

Optional existing KVS for page invalidation history. State commits only after a paid event is accepted.

## `retainRaw` (type: `boolean`):

Store user-authorized raw bytes in KVS and the ZIP. Off by default.

## `maxBytesPerSource` (type: `integer`):

Reject a source before parsing when its response exceeds this byte limit.

## `concurrency` (type: `integer`):

Maximum simultaneous source reads, reduced automatically by the remaining event budget.

## Actor input object example

```json
{
  "inputSchemaVersion": 1,
  "sources": [
    {
      "url": "https://flintglade-tools.github.io/apify-fixtures/rag/sample.html",
      "rightsBasis": {
        "type": "user_owned",
        "evidence": "Flintglade-controlled public fixture"
      },
      "formatHint": "html"
    }
  ],
  "chunking": {
    "strategy": "character",
    "size": 1000,
    "overlap": 150
  },
  "dedupe": {
    "mode": "exact"
  },
  "retainRaw": false,
  "maxBytesPerSource": 20000000,
  "concurrency": 2
}
```

# Actor output Schema

## `defaultDataset` (type: `string`):

No description

## `corpusManifest` (type: `string`):

No description

## `corpusPackage` (type: `string`):

No description

## `extractedDocument` (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 = {
    "sources": [
        {
            "url": "https://flintglade-tools.github.io/apify-fixtures/rag/sample.html",
            "rightsBasis": {
                "type": "user_owned",
                "evidence": "Flintglade-controlled public fixture"
            },
            "formatHint": "html"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("flintglade/rag-corpus-provenance-packager").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 = { "sources": [{
            "url": "https://flintglade-tools.github.io/apify-fixtures/rag/sample.html",
            "rightsBasis": {
                "type": "user_owned",
                "evidence": "Flintglade-controlled public fixture",
            },
            "formatHint": "html",
        }] }

# Run the Actor and wait for it to finish
run = client.actor("flintglade/rag-corpus-provenance-packager").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 '{
  "sources": [
    {
      "url": "https://flintglade-tools.github.io/apify-fixtures/rag/sample.html",
      "rightsBasis": {
        "type": "user_owned",
        "evidence": "Flintglade-controlled public fixture"
      },
      "formatHint": "html"
    }
  ]
}' |
apify call flintglade/rag-corpus-provenance-packager --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=flintglade/rag-corpus-provenance-packager",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

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