# smart-rag-optimizer⁠ (`devluka/smart-rag-optimizer`) Actor

Lightweight RAG web scraper that extracts web content, removes noise/ads, converts HTML to clean Markdown, and splits text into structured RAG chunks for LLMs and MCP servers.

- **URL**: https://apify.com/devluka/smart-rag-optimizer.md
- **Developed by:** [LUKA LU](https://apify.com/devluka) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 scraped and chunked 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/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

## 🚀 Smart RAG Optimizer

*Smart RAG Optimizer*
is an enterprise-grade, high-performance web crawler and
text preprocessor designed specifically to convert
any web page into clean, chunked,
RAG-ready JSON data for large language
Models (LLMs) and Vector Databases.

***

### ✨ Key features

- **🧹 Automated Noise Removal:** Automatically
  strips out non-content elements such as scripts,
  styles, navigation bars, footer, headers, ads,
  and popups.
- **🌐 Automatic Sitemap Detection:** Automatically
  detects and extracts links from `sitemap.xml` as a primary
  entry point for full-domain coverage.
- **⚡️ Hybrid Engine (Cheerio + Playwright):** Uses
  `CheerioCrawler` for ultra-fast parsing, with seamless
  optional fallback to `PlaywrightCrawler` (`useBrowser`)
  to bypass firewalls and JavaScript-rendered pages.
- **📊 Markdown Table Conversion:** Automatically transforms
  complex HTML tables into clean Markdown format to preserve
  structured context for LLMs.
- **✂️ Smart Semantic Chunking:** Dynamic paragraph-aware
  splitting with customizable overlap (`chunkOverlap`) to
  eliminate context boundary truncation.
- **🎯 Rich RAG Metadata:** Emits Structured JSON complete
  with `chunkId`, estimated `tokensCount`, `headingPath`
  breadcrumbs, and raw cleaned text.
- **🛡️ Built-in Proxy Integration:** Direct integration with
  Apify proxy for dynamic IP rotation and anti-bot mitigation.

***

### 💡 Common Use Cases

- Preparing web data for *RAG pipelines*
  (LangChain, LlamaIndex, OpenAI Assistant
  API, AutoGen).
- Feeding structured context to *Vector Databases*
  (Pinecone, Weaviate, Qdrant, Chroma, Milvus).
- Building high-accuracy custom Knowledge Bases for
  *Enterprise AI Chatbots*.

***

### 🛠️ Input Parameters

| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `url` | string | *(Required)* | The target webpage URL to extract and process. |
| `chunkSize` | number | `1000` | Target character count threshold per chunk. |
| `chunkOverlap` | number | `200` | Character overlap between consecutive chunks to retain semantic context. |
| `maxPages` | number | `1` | Maximum number of pages to crawl starting from the URL or Sitemap. |
| `chunkByHeaders` | boolean | `true` | Enable smart semantic chunking based on natural paragraphs and sections. |
| `useBrowser` | boolean | `false` | Enable Playwright headful browser rendering to handle heavy JS and bypass firewalls. |

***

### 📄 Output Sample

````json
[
{
    "url": "https://docs.python.org/3.11/",
    "title": "Python 3.11.18 documentation",
    "totalChunks": 3,
    "chunks": [
    {
    "chunkIndex": 1,
    "chunkId": "chunk_1_aHR0cHM6Ly",
    "tokensCount": 475,
    "headingPath": "Python 3.11.18 documentation > Part 1",
    "content": "Welcome! this is the official documentation for python 3.11.18..."
    }
    ],
    "rawText": "Welcome! this is the official documentation for python 3.11.18..."
}
]



# Actor input Schema

## `url` (type: `string`):

The webpage URL to fetch and convert for RAG
## `chunkSize` (type: `integer`):

Maximum characters per chunk for RAG.
## `maxPages` (type: `integer`):

Maximum number of pages to crawl starting from the URL (Set 1 for single page).
## `chunkByHeaders` (type: `boolean`):

Enable smart chunking based on Markdown headers and semantic sections.
## `useBrowser` (type: `boolean`):

Enable real browser rendering for dynamic JavaScript websites.

## Actor input object example

```json
{
  "url": "https://example.com",
  "chunkSize": 1000,
  "maxPages": 1,
  "chunkByHeaders": true,
  "useBrowser": false
}
````

# Actor output Schema

## `results` (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 = {
    "url": "https://example.com"
};

// Run the Actor and wait for it to finish
const run = await client.actor("devluka/smart-rag-optimizer").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 = { "url": "https://example.com" }

# Run the Actor and wait for it to finish
run = client.actor("devluka/smart-rag-optimizer").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 '{
  "url": "https://example.com"
}' |
apify call devluka/smart-rag-optimizer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,devluka/smart-rag-optimizer"
        }
    }
}
```

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/RJ7BhzlwbBwswdKB5/builds/P18XAStHjlWicymRb/openapi.json
