# RAG refresh API for clean, embeddable markdown | Spider

Refresh RAG stores on demand. Index documentation and knowledge bases incrementally, and Spider returns clean, embeddable markdown so retrieval stays current.

Canonical: https://spider.cloud/use-cases/rag/

## Clean markdown for your retrieval layer.

For teams that keep a vector store in step with docs and knowledge bases. Spider crawls the source and streams each page back as markdown, not HTML, so your callback embeds page one while the crawl is still running.

[Get an API key](https://spider.cloud/register/) [Read the guide](https://spider.cloud/guides/building-a-speedy-resilient-web-scraper-for-rag-ai-part1-preparing/)

Pay as you go from $0.16 per 1,000 pages. Documentation pages averaged $0.27 per 1,000 in the 2026-11-06 cost run. Cost varies by site.

Recorded crawl, 2026-09-09

- POST /crawl, limit 30, markdown

  https\://doc.rust-lang.org/book/

- page one

  /book/, 200

- its markdown

  1,482 bytes

- all 30 pages

  21.5 s

- all markdown

  319 KB

```
# The Rust Programming Language
*by Steve Klabnik, Carol Nichols, and Chris Krycho, with contributions from the
Rust Community*
```

Page one's opening lines, verbatim. It landed 5.0 s after a request that asked for smart mode with country_code set to de. The other 29 pages followed within 16.4 s, each one ready to embed as it arrived.

## The first page lands while the crawl runs.

The same crawl, page by page. The first page arrived at 5,048 ms and pages came in bursts after it. With stream=True your callback takes each burst as it lands.

Arrival, ms after the request

30 pages of doc.rust-lang.org/book, crawled 2026-09-09 with return_format markdown. Each tick on a riser is one page. The pages came in 6 bursts, and 16.4 s passed between the first page and the last.

| Arrived   | Pages | Markdown |
| --------- | ----- | -------- |
| 5,048 ms  | 1     | 1.4 KB   |
| 8,300 ms  | 4     | 14.3 KB  |
| 11,675 ms | 6     | 32.6 KB  |
| 14,925 ms | 3     | 44.2 KB  |
| 18,175 ms | 6     | 101.1 KB |
| 21,295 ms | 10    | 125.4 KB |

## Embed the text, not the page chrome.

In a 60-page crawl of the kubernetes.io docs on 2026-11-06, the raw HTML came to 7,428,798 o200k_base tokens. The same pages as markdown came to 202,123, about 37 times fewer, as the [fine-tuning dataset write-up](https://spider.cloud/blog/build-fine-tuning-dataset-from-the-web/) shows. The median page went from 486,606 bytes of HTML to 11,673 bytes of markdown. Navigation, scripts and footers are what fell away, and none of it belongs in a chunk.

- Raw HTML

  7,428,798 tokens

- Markdown

  202,123 tokens

## Embed each page as it lands.

Pass a callback with stream=True and the crawl hands your code one page at a time. Chunk it, embed it and upsert it with its URL.

- stream=True

  Each page reaches your callback when it finishes. With the LangChain loader, lazy_load() yields documents the same way.

- SpiderLoader

  On LangChain, the loader returns documents with the markdown in page_content and the source URL in metadata, ready for add_documents.

- Webhooks

  Set a webhook URL and Spider POSTs results as pages complete, so the crawl and your ingestion run apart. Events include on_find and on_website_status.

- Cost

  max_credits_allowed caps the credits one run may use, so a refresh job has a ceiling you set.

crawl_and_embed.py

```
from spider import Spider

client = Spider()
def index(page):
    chunks = split(page["content"])
    vectors = embed(chunks)
    db.upsert(vectors, source=page["url"])

# Pages stream in as they finish, so indexing starts right away
client.crawl_url(
    "https://doc.rust-lang.org/book/",
    params={
        "return_format": "markdown",
        "limit": 500,
        "max_credits_allowed": 5000,
    },
    stream=True,
    callback=index,
)
```

## Crawl your own docs before you commit.

2,500 free credits, worth $0.25, if your signup passes our checks. No card required. Point the script above at your docs, keep the limit low, and count what comes back.

spider crawl --return-format markdown

[Get an API key ](https://spider.cloud/register/)[LangChain docs](https://spider.cloud/docs/integrations/langchain/)

- [Building a RAG scraper](https://spider.cloud/guides/building-a-speedy-resilient-web-scraper-for-rag-ai-part1-preparing/)
- [LangChain integration](https://spider.cloud/docs/integrations/langchain/)
- [LlamaIndex integration](https://spider.cloud/docs/integrations/llamaindex/)
