Tutorial · RAG and Knowledge Systems
How to Crawl Documentation for RAG
Turn product documentation into a useful, maintainable knowledge source.
Written by Aaron Grainger
Independent Content Strategist & Product-Marketing Writer · Published May 6, 2025
- Primary audience
- AI application developers
- Also useful for
- Developer advocates and technical writers
- Tone
- Educational
- Reading time
- 4 min
- Published
- May 6, 2025
Direct answer
Crawl documentation for RAG by starting from the sitemap, scoping strictly by path, respecting canonical URLs, and normalizing pages while explicitly protecting code blocks and tables. Chunk on heading structure rather than character count, and carry title, section path, version, and canonical URL into every chunk. Then treat the result as a maintained asset: recrawl on a cadence, delete removed pages, and run a fixed retrieval test set after every refresh.
Discovery
Start at /sitemap.xml. It is the cheapest discovery mechanism available and it usually reflects the structure the publisher intends. Treat it as a starting set rather than truth: sitemaps go stale, omit sections, and sometimes list URLs that redirect. Fall back to link-following inside the documented path scope for anything missing.
Crawl scope and URL rules
Write scope as explicit rules before running anything:
- Include only paths under the documentation root
- Exclude version archives unless you intend to index multiple versions
- Exclude non-primary locales, or index them with a locale field
- Exclude search result pages, tag indexes, and pagination shells
- Cap depth and total page count so a misconfiguration fails loudly
- Set a request rate that respects the site and any stated limits
Duplicate handling
Documentation sites generate duplicates prolifically: trailing-slash variants, locale mirrors, versioned copies of unchanged pages, and printer views. Respect the canonical tag, normalize URLs before comparison, and hash the normalized content to catch the rest. Without this, a 400-page set becomes several thousand near-identical chunks and retrieval precision collapses.
Page cleaning
Strip site chrome, sidebars, and version pickers. Protect code blocks, tables, and callouts explicitly — in technical documentation these are frequently the answer. Where the page uses tabs for language variants, either split them into separate documents or label each variant clearly; concatenating them creates documents that contradict themselves.
Chunking
Split on headings, not on a character count. A section is a coherent unit of meaning; 800 characters is not. Carry the page title and the full section path into each chunk so a retrieved fragment still knows where it came from, and avoid splitting in the middle of a procedure — a step without its prerequisites is worse than no step at all.
Document schema
{ "id": "docs/auth/api-keys#rotation", "title": "Rotating API keys", "section_path": ["Authentication", "API keys", "Rotation"], "canonical_url": "https://example.com/docs/auth/api-keys", "version": "v2", "locale": "en", "content_markdown": "## Rotation\nKeys can be rotated without downtime…", "content_chars": 1840, "code_blocks": 2, "retrieved_at": "2026-09-14T09:41:00Z", "content_hash": "sha256:…"}Embeddings, conceptually
Embeddings turn each chunk into a vector so that semantically similar passages can be found. They locate related language; they do not verify correctness. Keep filterable metadata — version, product, section — alongside the vector, because narrowing the candidate set with a filter usually improves results more than tuning similarity.
Retrieval testing
Write down ten to twenty questions that the documentation should answer, ideally taken from real support tickets. Run them after every ingest and read what comes back. This test set will tell you about scope and cleaning problems faster than any aggregate metric.
RAG-readiness audit
- A sitemap or explicit URL list exists and resolves
- Scope is defined by path rules, not by crawl depth alone
- Canonical tags are respected and duplicates collapsed
- Versions and locales are metadata fields, not mixed content
- Code blocks and tables survive normalization intact
- Chunks split on headings and carry the section path
- Every document stores canonical URL and retrieval time
- Removed pages are deleted from the index on recrawl
- A fixed retrieval question set is run after each refresh
- Someone owns the recrawl cadence by name
Technical implementation checklist
- Politeness: concurrency cap, delay, and honoured robots directives
- Retries with backoff, and failures recorded rather than swallowed
- Content assertions: minimum length and expected structural elements
- Content hash stored so unchanged pages skip re-embedding
- Per-run counts: pages crawled, indexed, skipped, failed
- Alert when document count or median content length shifts materially
- Delete-on-removal semantics in the index writer
- Run report archived so two runs can be compared
Troubleshooting
| Symptom | Likely cause | Action |
|---|---|---|
| Retrieval returns navigation text | Cleaning too conservative | Tighten region stripping; exclude index pages |
| Answers cite the wrong product version | Versions mixed in one index | Add a version field and filter at query time |
| Code missing from answers | Readability extraction dropped pre/code | Protect code elements explicitly |
| Index far larger than the page count | Duplicates not collapsed | Respect canonicals; hash normalized content |
| Good pages never retrieved | Chunks too large or topically mixed | Chunk on headings; reduce section size |
| Stale answers after a docs rewrite | No delete-on-removal | Reconcile index against the current URL set |
Questions that keep coming up
Practical takeaway
- Scope rules matter more than crawl depth.
- Canonical-aware deduplication is the highest-value single rule.
- Chunk on structure; carry the section path into the chunk.
- Version and locale belong in metadata, not mixed into one index.
- A knowledge base without a recrawl owner becomes wrong on a schedule.
Related content
Foundational guide · 4 min
How to Turn a Website Into LLM-Ready Markdown
Why clean, structured text often matters more than raw HTML in AI workflows.
Tutorial · 3 min
How to Build a Website-to-Knowledge-Base Pipeline
One ingest path, many sources: standardising how external content enters internal systems.
Technical guide · 4 min
How to Extract Structured Data From a Website
Use schemas to transform inconsistent pages into dependable records.
Workflow playbook · 6 min
Turn a documentation site into a RAG knowledge base
Crawl a documentation set, clean it, chunk it on structure, and keep it current without rebuilding from scratch.
Version history
Current: 1.0 · Published
- 1.0May 6, 2025First published.
Was this useful?
Sourceframe is an independent product concept created for research, product-design, and technical-content exploration. It is not an operating company, and nothing here describes a live commercial service. All examples, schemas, and code are illustrative unless a page says otherwise. No client data, customer outcomes, performance results, or partnerships are described anywhere on this site.