# RAG Dataset Cleaner - Text Deduplication and Source URLs (`variable_mitts/rag-dataset-cleaner-evidence`) Actor

Deduplicate crawler text for RAG datasets. Export exact-unique JSONL with grouped source URLs, empty-record diagnostics and near-duplicate review flags.

- **URL**: https://apify.com/variable_mitts/rag-dataset-cleaner-evidence.md
- **Developed by:** [Dhan sites](https://apify.com/variable_mitts) (community)
- **Categories:** AI, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.48 / 1,000 document record inspecteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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 Dataset Cleaner - Text Deduplication and Source URLs

Deduplicate crawler text for RAG datasets. Export exact-unique JSONL with grouped source URLs, empty-record diagnostics and near-duplicate review flags.

### See the result before you run

The prefilled example contains five fictional help-centre crawler records. URLs are labels; this Actor does not visit them.

| Input | Result |
|---|---|
| 3 identical delivery-policy texts with different source URLs | 1 verbatim document preserving all 3 source references |
| 1 different returns-policy text | 1 separate verbatim document |
| 1 whitespace-only record | Empty-text diagnostic; no candidate document |

**5 processed records â†’ 2 exact-unique candidate documents, 2 duplicates grouped, 1 empty record flagged.** Four nonempty-record source references are preserved in the candidate export. The empty record remains visible in the decision dataset and report. Source records are not deleted. These are measured fixture results, not a promise about your dataset or retrieval accuracy.

### Quick start

1. Open the Input tab or the public Example task and restore the example input.
2. Run the five prefilled fictional records with Maximum documents set to 5. They have $0.003 in Actor event fees at the entry-tier rate, including duplicate and empty-text diagnostics. Review the Pricing tab for tier discounts and any separately displayed platform costs. The smaller copy-and-run example below uses three records ($0.0018 at the entry tier).
3. Open `START_HERE.md` first, then inspect the dataset and `REPORT` for coverage and diagnostics. A successful execution alone does not establish that all requested work was completed.
4. Download `CLEAN_DOCUMENTS.jsonl` for candidate documents and `MANIFEST` for their grouped sources. To use a crawler dataset, **clear Inline document records first**, select Source crawler dataset and grant READ permission. These two input modes cannot be combined. Set `textField` if your crawler stores text outside `markdown` or `text`.

#### The same five-record demo, via API

```json
{
  "records": [
    {
      "url": "https://example.com/help/delivery",
      "markdown": "# Delivery policy\nStandard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.\n"
    },
    {
      "url": "https://example.com/help/delivery?utm_source=newsletter",
      "markdown": "# Delivery policy\nStandard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.\n"
    },
    {
      "url": "https://example.com/help/returns",
      "markdown": "# Returns policy\nUnused products can be returned within fourteen days of delivery. Keep the original packaging and contact support for return instructions before sending the parcel. Refunds are processed after the returned item has been inspected. This sample policy is fictional demonstration content.\n"
    },
    {
      "url": "https://example.com/archive/delivery",
      "markdown": "# Delivery policy\nStandard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.\n"
    },
    {
      "url": "https://example.com/help/empty",
      "markdown": "   "
    }
  ],
  "maxDocuments": 5
}
```

### What to open after the run

1. **START_HERE.md** — the actual result counts, coverage warnings and what to do next. It also explains invalid input without promising nonexistent exports.
2. **CLEAN_DOCUMENTS.jsonl** — candidate verbatim text with content hashes and grouped source references.
3. **MANIFEST** — source references and export coverage. Empty or invalid records are accounted for in the decision dataset instead.
4. **REPORT** and the default dataset — full decisions, review flags and coverage.

For the five-record fixture, expect 2 unique documents, 2 grouped duplicates, 1 empty record and 4 nonempty source references. New runs compute their own results; these counts are not a promise for other inputs.

### Input reference

| Field | Type | Required | Description |
|---|---|---|---|
| `records` | array | No | Small JSON array of objects containing markdown or text and optional url. Use instead of a source dataset. |
| `sourceDatasetId` | string | No | Select one dataset containing source text. Cannot be combined with inline records. |
| `maxDocuments` | integer | No | Read/process at most this many source rows,1-1000. Larger inputs are explicitly incomplete. |
| `textField` | string | No | Dot-separated object path. Leave empty to prefer markdown then text automatically. |
| `urlField` | string | No | Dot-separated object path, default url. URLs are metadata only and never fetched. |

### Advanced workflow

#### Pipeline-ready candidate JSONL and provenance manifest

CLEAN_DOCUMENTS.jsonl exports one retained exact-unique text per line with its content hash and every grouped source reference. MANIFEST describes exported documents, duplicate_groups, preserved source counts, review requirement and original coverage. REPORT adds duplicate_groups, flag_counts, duplicate_fraction_of_processed and per-record text_metrics. Whitespace word count is not token count. Exports preserve supplied text verbatim; sources remain user-provided labels. Near-duplicates and boilerplate remain review flags, never automatic removals. No source dataset or vector index is modified.

### Pricing

$0.6 per 1,000 processed source rows ($0.0006 each) at the entry tier. Per-record diagnostics count as processed records; invalid top-level input has no record event fee. No run-start event or automatic output-row event. The Pricing tab shows the applicable subscription-tier price. The spending limit can reduce the number of processed items.

For example, 100 billable items cost $0.06 in Actor event fees at the entry tier. Zero findings is different from zero processed items. Inspect the report's processed/checked counts and the run's charge events to reconcile a run.

### Limits and interpretation

Process at most maxDocuments, up to 1,000 rows. Inline records and a source dataset are alternative input modes. Dataset access is read-only and subject to the caller's permissions. Near-duplicates and repeated boilerplate are review flags, never automatic removals. Source URLs are supplied labels and are not fetched. No paid AI model, embedding generation or vector-database write is performed.

Results cover only the inspected input. Truncation and unchecked records require review; do not treat them as a complete-source guarantee. Input is not overwritten. The Actor uses limited permissions.

### Troubleshooting and support

- **Run succeeded but output is diagnostic:** inspect `REPORT` and `INPUT_ERRORS`, correct the named fields, and rerun. Handled invalid input can finish with `SUCCEEDED` and no billable items.
- **Fewer results than requested:** check coverage, truncation, spending limits and the limits above. In dataset mode, check dataset availability, READ permission and the selected text field. No websites are fetched.
- **Repeat a workflow:** save a task with your input and use Apify scheduling or its API. Review each run's coverage before passing results downstream.
- **Report a problem:** open this Actor's Issues tab with the run ID, expected behavior and a minimal non-sensitive input. Never post tokens, credentials or private source data.

### Related tools

- [dataset contract field checker](https://apify.com/variable_mitts/dataset-contract-field-checker)
- [csv formula neutralizer](https://apify.com/variable_mitts/csv-formula-neutralizer)

### Questions before your first run

**Does it crawl the URLs?** No. Supply crawler text inline or select an existing Apify dataset. URLs are source labels only.

**Why am I charged for a duplicate or empty record?** The Actor inspects source records to decide what can be exported. Billing is per inspected input record, not per retained document. Invalid top-level input has no document event fee.

**Will slightly different prices or wording disappear?** Exact grouping requires identical full text. Near-duplicate flags are for review only. Different texts remain separate candidates.

**Which example should I use?** [Try the five-record source-preserving cleanup task](https://apify.com/variable_mitts/rag-dataset-cleaner-evidence/examples/rag-dataset-cleaner-evidence-quick-demo). It uses fictional non-sensitive data and has $0.003 in entry-tier Actor event fees.

**Can I use my own dataset?** Clear the prefilled inline records, select your dataset, and grant READ permission. Check the text-field path and report coverage before using the output.

### Who is this for?

RAG developers preparing crawler text for retrieval pipelines. Supply supported source records and keep provenance when removing exact duplicate text.

### Frequently asked questions

#### Does this automatically remove near-duplicate documents?

Exact duplicates are grouped for the clean export. Near-duplicate findings are review flags rather than automatic removals, helping preserve meaningful differences. Inspect coverage and diagnostics.

#### How do I try it before using my full input?

Open the Input tab, review the prefilled example, and run a small batch with a spending limit. Inspect the dataset and report before increasing the batch. Examples can incur the documented inspection or analysis fee; an execution marked successful can still contain rejected records or incomplete coverage.

#### Can I use the Actor through an API or on a schedule?

Yes. Use Apify's [Actor API](https://docs.apify.com/api/v2/acts-run-sync-get-dataset-items-post) or [schedules](https://docs.apify.com/platform/schedules). Keep credentials private and use the documented input fields. The pricing and limits below apply to API runs too.

### Related tools for the next step

- [RAG Text Chunker - Source Offsets and Verbatim Chunks](https://apify.com/variable_mitts/citation-span-text-chunker)
- [JSON Dataset Validator - Required Fields and Data Types](https://apify.com/variable_mitts/dataset-contract-field-checker)

# Actor input Schema

## `records` (type: `array`):

Small JSON array of objects containing markdown or text and optional url. Use instead of a source dataset.

## `sourceDatasetId` (type: `string`):

Select one dataset containing crawler text. First clear Inline document records; inline records and a dataset cannot be used together. Requires READ permission.

## `maxDocuments` (type: `integer`):

Read/process at most this many source rows,1-1000. Larger inputs are explicitly incomplete.

## `textField` (type: `string`):

Dot-separated object path. Leave empty to prefer markdown then text automatically.

## `urlField` (type: `string`):

Dot-separated object path, default url. URLs are metadata only and never fetched.

## Actor input object example

```json
{
  "records": [
    {
      "url": "https://example.com/help/delivery",
      "markdown": "# Delivery policy\nStandard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.\n"
    },
    {
      "url": "https://example.com/help/delivery?utm_source=newsletter",
      "markdown": "# Delivery policy\nStandard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.\n"
    },
    {
      "url": "https://example.com/help/returns",
      "markdown": "# Returns policy\nUnused products can be returned within fourteen days of delivery. Keep the original packaging and contact support for return instructions before sending the parcel. Refunds are processed after the returned item has been inspected. This sample policy is fictional demonstration content.\n"
    },
    {
      "url": "https://example.com/archive/delivery",
      "markdown": "# Delivery policy\nStandard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.\n"
    },
    {
      "url": "https://example.com/help/empty",
      "markdown": "   "
    }
  ],
  "maxDocuments": 5
}
```

# Actor output Schema

## `startHere` (type: `string`):

Read this first. Summarizes the run and warns about incomplete coverage or invalid input.

## `review` (type: `string`):

No description

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

No description

## `cleanDocuments` (type: `string`):

No description

## `decisions` (type: `string`):

No description

## `jsonl` (type: `string`):

No description

## `manifest` (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 = {
    "records": [
        {
            "url": "https://example.com/help/delivery",
            "markdown": "# Delivery policy\nStandard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.\n"
        },
        {
            "url": "https://example.com/help/delivery?utm_source=newsletter",
            "markdown": "# Delivery policy\nStandard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.\n"
        },
        {
            "url": "https://example.com/help/returns",
            "markdown": "# Returns policy\nUnused products can be returned within fourteen days of delivery. Keep the original packaging and contact support for return instructions before sending the parcel. Refunds are processed after the returned item has been inspected. This sample policy is fictional demonstration content.\n"
        },
        {
            "url": "https://example.com/archive/delivery",
            "markdown": "# Delivery policy\nStandard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.\n"
        },
        {
            "url": "https://example.com/help/empty",
            "markdown": "   "
        }
    ],
    "maxDocuments": 5
};

// Run the Actor and wait for it to finish
const run = await client.actor("variable_mitts/rag-dataset-cleaner-evidence").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 = {
    "records": [
        {
            "url": "https://example.com/help/delivery",
            "markdown": """# Delivery policy
Standard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.
""",
        },
        {
            "url": "https://example.com/help/delivery?utm_source=newsletter",
            "markdown": """# Delivery policy
Standard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.
""",
        },
        {
            "url": "https://example.com/help/returns",
            "markdown": """# Returns policy
Unused products can be returned within fourteen days of delivery. Keep the original packaging and contact support for return instructions before sending the parcel. Refunds are processed after the returned item has been inspected. This sample policy is fictional demonstration content.
""",
        },
        {
            "url": "https://example.com/archive/delivery",
            "markdown": """# Delivery policy
Standard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.
""",
        },
        {
            "url": "https://example.com/help/empty",
            "markdown": "   ",
        },
    ],
    "maxDocuments": 5,
}

# Run the Actor and wait for it to finish
run = client.actor("variable_mitts/rag-dataset-cleaner-evidence").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 '{
  "records": [
    {
      "url": "https://example.com/help/delivery",
      "markdown": "# Delivery policy\\nStandard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.\\n"
    },
    {
      "url": "https://example.com/help/delivery?utm_source=newsletter",
      "markdown": "# Delivery policy\\nStandard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.\\n"
    },
    {
      "url": "https://example.com/help/returns",
      "markdown": "# Returns policy\\nUnused products can be returned within fourteen days of delivery. Keep the original packaging and contact support for return instructions before sending the parcel. Refunds are processed after the returned item has been inspected. This sample policy is fictional demonstration content.\\n"
    },
    {
      "url": "https://example.com/archive/delivery",
      "markdown": "# Delivery policy\\nStandard delivery takes three to five working days after dispatch. Tracking information is sent by email when the parcel leaves the warehouse. Delivery estimates exclude public holidays. Customers can contact support with their order number if tracking has not updated for two working days.\\n"
    },
    {
      "url": "https://example.com/help/empty",
      "markdown": "   "
    }
  ],
  "maxDocuments": 5
}' |
apify call variable_mitts/rag-dataset-cleaner-evidence --silent --output-dataset

```

## MCP server setup

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

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/3uMQewxp8XcojQ8Sc/builds/kfeQTHrZS3slVw9Jo/openapi.json
