# Wikipedia to RAG — Article Scraper for AI Pipelines (`yuchiaoniu/wikipedia-rag-scraper`) Actor

Search Wikipedia and download articles as clean Markdown chunks ready for RAG pipelines, Pinecone, Weaviate, Chroma, or any vector database. No API key required.

- **URL**: https://apify.com/yuchiaoniu/wikipedia-rag-scraper.md
- **Developed by:** [Niu Yuchiao](https://apify.com/yuchiaoniu) (community)
- **Categories:** AI, Developer tools
- **Stats:** 2 total users, 1 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-usage

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

## Wikipedia to RAG — Bulk Article Scraper for AI & Vector Databases

Turn any Wikipedia topic into clean, chunked Markdown ready for RAG pipelines, vector databases, and LLM fine-tuning — **no API key required**.

### Why use this Actor?

Wikipedia is the world's largest free knowledge base with 60+ million articles. This Actor automates:

- 🔍 **Multi-query search** — find relevant articles by keyword
- 📄 **Clean text extraction** — removes infoboxes, references, navbars
- ✂️ **Smart chunking** — overlapping chunks optimized for RAG retrieval
- 📦 **Vector DB ready** — outputs JSONL with `text` + `metadata` fields

### Use Cases

- Building domain-specific RAG knowledge bases
- Creating AI training datasets
- Populating Pinecone / Weaviate / Chroma / Qdrant
- Research automation and summarization pipelines

### Input

```json
{
  "searchQueries": ["machine learning", "neural networks", "transformer model"],
  "articleUrls": ["https://en.wikipedia.org/wiki/BERT_(language_model)"],
  "language": "en",
  "maxArticles": 20,
  "chunkSize": 400,
  "chunkOverlap": 40,
  "includeIntroOnly": false,
  "outputMarkdown": true
}
```

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `searchQueries` | string\[] | `[]` | Keywords to search Wikipedia |
| `articleUrls` | string\[] | `[]` | Direct Wikipedia article URLs |
| `language` | string | `"en"` | Wikipedia language code (en, zh, de, fr, ja, ...) |
| `maxArticles` | number | `20` | Maximum number of articles to process |
| `chunkSize` | number | `400` | Words per chunk |
| `chunkOverlap` | number | `40` | Overlapping words between chunks |
| `includeIntroOnly` | boolean | `false` | Only extract the article introduction |
| `outputMarkdown` | boolean | `true` | Save full markdown to Key-Value store |

### Output

#### Dataset (JSONL chunks)

Each row contains a text chunk ready for embedding:

```json
{
  "text": "A transformer is a deep learning architecture...",
  "metadata": {
    "title": "Transformer (deep learning architecture)",
    "url": "https://en.wikipedia.org/wiki/Transformer_(deep_learning_architecture)",
    "chunkIndex": 0,
    "totalChunks": 12,
    "language": "en",
    "source": "wikipedia",
    "scrapedAt": "2025-01-01T00:00:00.000Z"
  }
}
```

#### Key-Value Store

- `wiki-{title}.md` — full article as clean Markdown
- `output.jsonl` — all chunks as downloadable JSONL file

### Integration Examples

#### Pinecone

```python
import json
from pinecone import Pinecone
import openai

pc = Pinecone(api_key="YOUR_KEY")
index = pc.Index("wikipedia-knowledge")

## Download output.jsonl from Actor run
with open("output.jsonl") as f:
    for line in f:
        item = json.loads(line)
        embedding = openai.embeddings.create(
            input=item["text"], model="text-embedding-3-small"
        ).data[0].embedding
        index.upsert([(item["metadata"]["url"] + str(item["metadata"]["chunkIndex"]),
                       embedding, item["metadata"])])
```

#### LangChain

```python
from langchain.vectorstores import Chroma
from langchain.embeddings import OpenAIEmbeddings
from langchain.schema import Document
import json

docs = []
with open("output.jsonl") as f:
    for line in f:
        item = json.loads(line)
        docs.append(Document(page_content=item["text"], metadata=item["metadata"]))

vectorstore = Chroma.from_documents(docs, OpenAIEmbeddings())
```

### Multilingual Support

Set the `language` parameter to scrape any Wikipedia language edition:

| Code | Language |
|------|----------|
| `en` | English |
| `zh` | Chinese |
| `de` | German |
| `fr` | French |
| `ja` | Japanese |
| `es` | Spanish |
| `ko` | Korean |

### FAQ

**Is this legal?**
Yes. Wikipedia content is published under the Creative Commons Attribution-ShareAlike license and explicitly allows programmatic access. The Actor respects rate limits with polite delays.

**Does it require an API key?**
No. The Wikipedia REST API is completely free and requires no authentication.

**How many articles can I scrape?**
The FREE Apify plan supports up to hundreds of articles per run. For bulk scraping of thousands of articles, consider upgrading.

## Actor input object example

```json
{}
```

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("yuchiaoniu/wikipedia-rag-scraper").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("yuchiaoniu/wikipedia-rag-scraper").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 '{}' |
apify call yuchiaoniu/wikipedia-rag-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/acts/HpGJuki5bbyPCF843/builds/W0YeLzntTNeRFwOcz/openapi.json
