# RAG Text Chunker - Source Offsets and Verbatim Chunks (`variable_mitts/citation-span-text-chunker`) Actor

Split supplied text into overlapping verbatim chunks with source offsets, hashes and stable chunk IDs. Export JSONL for RAG pipelines.

- **URL**: https://apify.com/variable_mitts/citation-span-text-chunker.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 input record processeds

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 Text Chunker - Source Offsets and Verbatim Chunks

Split supplied documents into overlapping, verbatim character windows for a retrieval pipeline. Preserve exact source-field offsets, content hashes and deterministic chunk IDs, and download a flat JSONL export.

### Start with this workflow

Create traceable text chunks without rewriting the source.

**After the run:** Open the flat JSONL export and verify start/end spans against the original field. Character windows are not token counts or an embedding service.

**What is billed:** Processed input documents, not output chunks; per-record diagnostics count and invalid top-level input is free. Check the Pricing tab for the applicable subscription-tier rate. Result rows and billable input units can differ. A successful execution does not guarantee full coverage.

The example uses a small supplied fixture or the publisher-owned demonstration target. Replace it with input you are authorized to process; inspect coverage, diagnostics and limits before downstream use.

### Quick start

1. Open the Input tab or the public Example task and restore the example input.
2. Run the small example below. Use non-sensitive supplied records first. Source URLs are metadata; this Actor does not fetch websites.
3. Open the dataset for individual results, then read `REPORT` for coverage and diagnostics. A successful execution alone does not establish that all requested work was completed.
4. Download the relevant files from the Output tab, or retrieve the dataset through Apify's API for your next workflow step.

```json
{
  "records": [
    {
      "url": "https://example.com/docs",
      "text": "Price100\nrun --safe\nDocumentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. "
    }
  ],
  "chunkCharacters": 200,
  "overlapCharacters": 40
}
```

### Output example

The following is a real first result from the developer's example run; some large nested fields are omitted for readability. These are supplied sample records; source labels are not independently verified website evidence.

```json
{
  "record_index": 0,
  "valid": true,
  "error": "",
  "chunk_count": 6,
  "character_count": 860,
  "boundary_mode": "characters"
}
```

The default dataset contains result rows. Files declared for this Actor are listed below; availability depends on the input mode and validation result. Input errors and diagnostics are reported in REPORT.

- `REPORT`
- `CHUNKS.jsonl`

### Input reference

| Field | Type | Required | Description |
|---|---|---|---|
| `maxRecords` | integer | No | Total record processing cap. Capped output is explicitly truncated. |
| `records` | array | Yes | JSON array of input records. Up to10000 supplied; at most1000 processed per run. |
| `textField` | string | No | Dot-separated object field path. |
| `chunkCharacters` | integer | No | Unicode code points per window, not tokens. |
| `overlapCharacters` | integer | No | Overlap0 to half the chunk size. |
| `boundaryMode` | string | No | Paragraph mode prefers a blank LF line in the final40% of a window. Otherwise uses the character limit. Text and exact offsets are preserved. |

### Advanced workflow

#### Optional paragraph boundaries and flat JSONL export

boundaryMode defaults to characters, preserving existing window positions and chunk IDs. Set paragraphs to prefer an LF blank-line boundary in the final40% of the character window, provided overlap still permits forward progress; otherwise it falls back to the character limit. Text is never stripped or normalized. Each chunk includes boundary_reason and overlap_with_previous. CHUNKS.jsonl flattens chunks with record_index for pipeline use. Exact half-open Unicode code-point spans and content hashes remain authoritative. This is not semantic, sentence-aware or token-aware chunking. Billing remains per inspected input document, not per chunk.

### Pricing

$0.6 per 1,000 processed input documents ($0.0006 each) at the entry tier. Per-record diagnostics count as processed records; invalid top-level input has no record event fee. Billing is per input document, not per emitted chunk. 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

Default 200, maximum 1,000 input documents per run; at most 10,000 supplied records and 2 million serialized JSON characters. Each document is limited to 100,000 characters and the run to 5,000 exported chunks. Offsets are zero-based, half-open Unicode code-point positions, not bytes, tokens or grapheme clusters. No embeddings, semantic splitting, sentence analysis or citation-fact verification. Source URLs are supplied labels and are never fetched.

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`, 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. Check the input field names, per-record diagnostics and coverage. This tool does not fetch websites.
- **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

- [rag dataset cleaner evidence](https://apify.com/variable_mitts/rag-dataset-cleaner-evidence)
- [dataset contract field checker](https://apify.com/variable_mitts/dataset-contract-field-checker)

### Who is this for?

RAG and retrieval developers who need traceable text chunks. Supply documents and inspect the source offsets before passing chunks to an embedding service.

### Frequently asked questions

#### Is this a token-based chunker or embedding API?

No. It creates bounded character windows that preserve source text and offsets. It does not count model tokens, rewrite text or generate embeddings.

#### 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 Dataset Cleaner - Text Deduplication and Source URLs](https://apify.com/variable_mitts/rag-dataset-cleaner-evidence)
- [JSONL Validator - Invalid Lines and Clean JSONL Export](https://apify.com/variable_mitts/jsonl-validator-reject-export)

# Actor input Schema

## `maxRecords` (type: `integer`):

Total record processing cap. Capped output is explicitly truncated.

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

JSON array of input records. Up to10000 supplied; at most1000 processed per run.

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

Dot-separated object field path.

## `chunkCharacters` (type: `integer`):

Unicode code points per window, not tokens.

## `overlapCharacters` (type: `integer`):

Overlap0 to half the chunk size.

## `boundaryMode` (type: `string`):

Paragraph mode prefers a blank LF line in the final40% of a window. Otherwise uses the character limit. Text and exact offsets are preserved.

## Actor input object example

```json
{
  "maxRecords": 200,
  "records": [
    {
      "url": "https://example.com/docs",
      "text": "Price100\nrun --safe\nDocumentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. "
    }
  ],
  "textField": "text",
  "chunkCharacters": 200,
  "overlapCharacters": 40,
  "boundaryMode": "characters"
}
```

# Actor output Schema

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

No description

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

No description

## `rows` (type: `string`):

No description

## `jsonl` (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/docs",
            "text": "Price100\nrun --safe\nDocumentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. "
        }
    ],
    "chunkCharacters": 200,
    "overlapCharacters": 40
};

// Run the Actor and wait for it to finish
const run = await client.actor("variable_mitts/citation-span-text-chunker").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/docs",
            "text": """Price100
run --safe
Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. """,
        }],
    "chunkCharacters": 200,
    "overlapCharacters": 40,
}

# Run the Actor and wait for it to finish
run = client.actor("variable_mitts/citation-span-text-chunker").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/docs",
      "text": "Price100\\nrun --safe\\nDocumentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. Documentation explains installation and recovery steps. "
    }
  ],
  "chunkCharacters": 200,
  "overlapCharacters": 40
}' |
apify call variable_mitts/citation-span-text-chunker --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,variable_mitts/citation-span-text-chunker"
        }
    }
}
```

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/gRwsmD6hYTcYVg4bV/builds/wCckEadcm54mcL2FG/openapi.json
