# How to crawl a website for RAG: map, filter, chunk, and sync

How to crawl a website into a clean RAG knowledge base: URL discovery with /v1/map, scoped /v1/crawl, heading-aware chunking, and sync.

Published: 2026-11-28
Author: Ajain Vivek

**TL;DR:** To build a clean RAG index from a website, map URLs first to exclude noise (/blog/tag, /login), crawl scoped prefixes to Markdown, split chunks along H2/H3 heading boundaries rather than fixed character counts, and re-index on a schedule or monitor.

Most RAG failures start at ingestion, not retrieval. Dumping an entire domain with an unfiltered crawler fills your vector store with pagination archives, changelog tags, and duplicate nav bars. A four-step loop (**map, filter, crawl to Markdown, and chunk by heading**) keeps your index small, fresh, and accurate.

See the [RAG knowledge base use case](/use-cases/rag-knowledge-base) and the [`/v1/crawl` docs](/docs/crawl) for endpoint details.

## Why should you map before you crawl?

Running a blind crawl from `/` wastes credits and pollutes embeddings with low-value pages. Calling `POST /v1/map` first inspects `sitemap.xml` and links so you can review or filter the URL list before fetching full bodies.

```bash
curl -X POST https://webcrawl.app/v1/map \
  -H "Authorization: Bearer $WEBCRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://docs.example.com","limit":200}'
```

Drop URLs that hurt retrieval:
- Tag, author, and pagination archives (`/page/2`, `/tag/`)
- Auth, cart, and search result routes (`/login`, `/search?q=`)
- Localized duplicates if your assistant only answers in one language

## How do you run a scoped crawl to Markdown?

Once you know the path prefixes that hold real knowledge (such as `/docs/` or `/guides/`), run `POST /v1/crawl` with path filters and a page cap:

```ts
import { createClient } from "@webcrawl/client";

const client = createClient({ apiKey: process.env.WEBCRAWL_API_KEY });

const job = await client.crawl({
  url: "https://docs.example.com/docs",
  includePaths: ["/docs/**"],
  excludePaths: ["/docs/changelog/**"],
  limit: 100,
});
```

Every returned page arrives as clean Markdown plus canonical URL and title metadata, ready to store alongside your embeddings.

## How should you chunk crawled Markdown for RAG?

Fixed-size character windows (like slicing every 1,000 characters blindly) cut code blocks in half and separate an `H2` question from its answer. Instead:

1. **Split on `##` and `###` headings first:** each section keeps its natural topic and heading context.
2. **Prepend the page title + heading breadcrumb** to every chunk (`Docs > Auth > API Keys`) so the embedding knows what entity the paragraph belongs to.
3. **Keep code fences atomic:** never split inside a ```` ``` ```` block.
4. **Target 300 to 600 tokens per chunk** with 10% overlap only when a single section exceeds your max window.
5. **Store `url`, `title`, and `contentHash` in metadata** so your retriever can cite sources and skip unchanged pages on the next run.

## How do you keep the RAG index fresh?

Re-crawling 500 unchanged docs pages every hour wastes credits and re-embedding compute. Two lighter patterns work better:

- **ETag / `lastmod` diffing:** check `sitemap.xml` or `If-Modified-Since` / `contentHash` and re-embed only changed URLs.
- **Change monitors:** watch high-churn pages (pricing, API limits, release notes) and trigger a single-URL `/v1/scrape` re-index when content changes.

## FAQ

### Should I use `/v1/crawl` or `/v1/map` + `/v1/scrape`?

Use `/v1/crawl` when you want all pages under one path prefix in a single job. Use `/v1/map` followed by selective `/v1/scrape` calls when you need strict allowlists or custom scheduling per URL.

### How many pages can I crawl on Webcrawl's free tier?

The free tier includes 1,000 hosted credits a month with no card, or you can self-host the MIT engine from `brainfish-ai/webcrawl-anything` for unlimited internal runs.

### Do I need a vector database if the site already has `llms.txt`?

For small docs sets (under ~30 pages), an agent with MCP access to `llms.txt` and `web_read` often answers accurately without any vector database. Use RAG when you have hundreds of pages, private docs, or strict sub-second retrieval budgets.

HTML: https://webcrawl.app/blog/crawl-website-for-rag
