Web Crawling for RAG: Turning Millions of Web Pages Into a Fresh, Searchable Enterprise Knowledge Base
Your AI assistant answered a customer's question perfectly. It quoted the returns policy, cited the page and sounded sure of itself. The policy had changed twelve days earlier. The model was never the weak point; the copy of the web it was reading from was. Web crawling for RAG is the work of keeping that copy complete, clean and current. This guide follows a web page from the crawler to a cited answer, and shows where each stage goes wrong.

Last updated 4 January 2027. Figures in the examples are illustrative.
What is web crawling for RAG?
Web crawling for RAG means collecting web pages and preparing them so that a language model can look things up in them. RAG stands for retrieval-augmented generation. The term comes from a 2020 paper by Lewis and colleagues, which described models that combine pre-trained parametric and non-parametric memory: what the model learned in training, plus an external store it can search at the moment a question arrives.
That external store is where a crawl comes in. A search-engine crawl aims to index everything. A crawl for RAG has a narrower job and a stricter one: fetch the right sources, turn each page into clean text a model can read, cut it into passages that can be retrieved one at a time, and keep all of it in step with the live site. If any of those four is done badly, the model retrieves the wrong passage and answers from it with full confidence.
This is different from collecting data to train a model, which we cover in web scraping for AI model training. Training data is used once. A RAG knowledge base is read every time someone asks a question, so it has to stay right.
The RAG data ingestion pipeline, stage by stage
A RAG data ingestion pipeline has seven stages. The first four are crawling and cleaning. The last three belong to your AI stack. The quality of the answers is decided mostly in the first four.
From a URL to something a model can search
Seven stations. A page passes through all of them once, and through the last one for as long as it exists.
Find every page worth having, from sitemaps and links.
Download it, running the page's scripts where needed.
Strip menus, banners and adverts. Keep the content and its structure.
Cut into passages, each labelled with where it came from.
Turn each passage into numbers that capture its meaning.
Store passages so the closest matches can be found fast.
Notice when the page changes or disappears, and update.
Teams building their first system usually put their effort into stations five and six, because that is where the AI tooling is. The failures that reach users tend to start earlier: a page that was never discovered, a navigation menu embedded as if it were content, a passage cut in half mid-table. Fetching itself has its own difficulties on script-heavy sites, covered in our guide to headless browsers at scale.
How to crawl a website for an LLM: clean text beats raw HTML
To crawl a website for an LLM, the most valuable step is the least glamorous: removing everything on the page that isn't the content. A typical web page is mostly wrapping. Menus, cookie notices, adverts, "related articles" and footers surround a few hundred words that matter.
Feed a model the raw page and three things happen. You pay to embed and store the wrapping. The same menu text appears in thousands of passages, so searches match it instead of the content. And the model, handed a passage that is half navigation, has less room for the part it needs.
The same page, before and after cleaning
Hatched regions are removed. Token counts are illustrative.
# Returns policy ## Return window Most items can be returned within 30 days. Opened electronics: 15 days. ## Refunds | Method | Time | | Card | 5 days | | Store credit| Same day |
Good cleaning keeps structure as well as words. Headings, lists, tables and code blocks carry meaning, and a format such as Markdown preserves them in a form models read well. It also keeps what a reader would need to trust the text: the page title, its address, and the date it was fetched. Documents that aren't web pages, such as PDFs, need the same treatment through a different extractor.
Chunking and metadata: what every passage should carry
A RAG knowledge base from a website is searched passage by passage, so how the text is cut matters as much as how it is cleaned. A chunk should be a piece that makes sense on its own. Cutting on headings and paragraphs does that. Cutting every fixed number of characters does not, because it slices sentences and separates a table from its header.
There is no universally right chunk size. Short chunks retrieve precisely but lose context; long ones keep context but dilute the match. Most teams settle the question by testing a few sizes against real questions, and add a small overlap so that a sentence on the boundary appears in both neighbours.
Anatomy of a chunk
The document on the left, one stored passage on the right.
Returns policy
- text
- Most items can be returned within 30 days. Opened electronics: 15 days.
- source_url
- help.example.com/returns
- title
- Returns policy
- heading_path
- Returns policy › Return window
- fetched_at
- 2027-01-04T06:10Z
- content_hash
- 7c02…a91f
- access
- public
Each field has a job. The source address and heading path let the model cite where an answer came from. The fetch time tells you, and the user, how old the information is. The content hash is what makes refreshing cheap, as the next section shows. The access label stops a passage from an internal or licensed source being shown to someone who shouldn't see it.
Keeping a RAG knowledge base from a website fresh
A RAG knowledge base from a website starts going out of date the day after it is built. Pages are edited, prices and policies change, products are withdrawn. Retrieval has no sense of time on its own. It returns the passage that best matches the question, whether that passage was fetched this morning or last quarter.
Rebuilding everything on a schedule is the simple fix and the expensive one, because every page is fetched, cleaned and embedded again whether or not it changed. The better approach is the one described in our guide to incremental web crawling: detect which pages changed and process only those. For RAG it has three specific consequences.
- Re-embed only what changed. Compare each chunk's content hash with the stored one. If a page changed in one section, only that section's chunks need new embeddings.
- Delete what's gone. When a page is removed or redirected, its chunks must leave the index. An assistant that cites a page returning "not found" loses trust quickly.
- Carry the date through. Store when each passage was last verified, and let the application show it or prefer newer passages when two disagree.
Web data for AI agents: fetch live, or search an index?
Web data for AI agents can arrive in two ways. An agent can open a page at the moment it needs it, or it can search a knowledge base that was crawled in advance. Each suits a different kind of question.
| Fetch live | Search a crawled index | |
|---|---|---|
| Freshness | Current to the second | As fresh as the last refresh |
| Speed | Seconds per page, and several pages per question | Milliseconds |
| Coverage | Only the pages it thinks to open | Everything you chose to include |
| Reliability | Fails when a page is slow, blocked or redesigned | Failures are handled at crawl time, not in front of the user |
| Cost | Paid on every question | Paid once per change |
| Best for | Rare, one-off lookups on pages you can't predict | Repeated questions over a known set of sources |
Most production systems use both: an index for the sources they rely on, and live fetching as a fallback for the rest. Getting crawled data into the systems an agent can reach is its own piece of work, described in enterprise web crawling with custom integrations.
What you are allowed to crawl and index
Building an AI knowledge base from other people's websites raises questions that ordinary analytics does not, so settle them before the crawl starts.
- Respect the site's stated wishes. The Robots Exclusion Protocol, standardised as RFC 9309, lets a site tell crawlers which paths to stay out of. The standard itself notes that these rules are not a form of access authorization; they are a request, and honouring them is part of crawling responsibly. Some sites now publish separate rules for AI use.
- Read the terms and the licence. Displaying passages from a source to your users is a different use from analysing it internally. Check what each source permits.
- Keep personal data out. A knowledge base that can be queried in plain language makes personal information very easy to surface.
- Cite your sources. Showing where an answer came from is good for users and fair to publishers.
Have counsel review the source list. Our overview of web scraping laws and ethics is a starting point, not legal advice.
What goes wrong, and where it starts
| What users see | Where it started | The fix |
|---|---|---|
| "I couldn't find anything about that" | Discover: the page was never crawled | Compare crawled pages with the sitemap; watch for new sections |
| Answers that quote menu text | Clean: wrapping was left in | Tune extraction per site; re-check after every redesign |
| Half an answer, or a table without its header | Chunk: cut in the wrong place | Cut on structure; keep tables whole |
| Confident, out-of-date answers | Refresh: the page changed and the index didn't | Incremental crawling; show the verified date |
| Citations that lead to "page not found" | Refresh: deletions weren't applied | Remove chunks when their page goes |
| The same passage returned five times | Discover: duplicate pages under different addresses | Deduplicate by content hash |
| A block page offered as an answer | Fetch: the site served a challenge | Validate that the page is the real page before it is indexed |
The last row is easy to miss, because a block page is valid text and embeds without complaint. The checks that catch it are in six validation layers every scraped dataset needs.
How to tell whether the knowledge base is healthy
A RAG knowledge base needs monitoring from two sides: is the content current, and can the right passage be found? The first is a crawl question. The second is answered by keeping a fixed set of test questions with known source pages, and checking after every change that those pages are still retrieved.
Freshness by source line marks the 95% target
Retrieval hit rate, 12 weeks 400 test questions
Frequently asked questions
What is the difference between crawling for RAG and crawling for search?
Both collect pages, but a crawl for RAG must also produce clean text a model can read, cut it into passages with their source and date attached, and keep those passages in step with the live pages. A stale search result is an inconvenience. A stale RAG passage becomes a confident wrong answer.
What format should crawled pages be in for an LLM?
Clean text that keeps the page's structure, most often Markdown, with navigation, adverts and footers removed. Headings, lists and tables should survive, and each page should carry its address, title and fetch date.
How often should a RAG knowledge base be updated?
As often as its sources change in ways that matter. Policy and pricing pages may need daily checks, while reference documents can wait a week or a month. Incremental crawling checks pages cheaply and reprocesses only those that changed, so frequent checks stay affordable.
How big should chunks be?
There is no single right size. Cut along headings and paragraphs so each chunk makes sense on its own, keep tables whole, add a small overlap, and test a few sizes against real questions to see which retrieves best for your content.
Can an AI agent just browse the web instead of using a crawled index?
For occasional lookups, yes. For repeated questions over known sources, a crawled index is faster, cheaper per question and more reliable, because slow or blocked pages are dealt with at crawl time. Many systems combine the two.
The short version
Web crawling for RAG decides what your model can know and how current that knowledge is. Find all the pages. Clean them down to their content and keep the structure. Cut them into passages that stand alone, each carrying its source, date and hash. Then keep the index in step with the live sites by reprocessing only what changes and removing what disappears. Measure both freshness and whether the right passages can still be found.
If your assistant already exists, start with two checks: how old is the oldest passage it can cite, and how many of its citations still open? The answers show where the work is.
How DataDwip supplies web data for RAG
Crawls for AI knowledge bases at DataDwip are delivered as model-ready text and kept current, so your team can spend its time on retrieval and answers.
- Clean, structured output. Pages are delivered as clean text or Markdown with headings and tables intact, not raw HTML.
- Provenance on every page. Each record carries its source address, title, fetch time and a content hash, so answers can be cited and changes detected.
- Changes, not rebuilds. We deliver new, changed and removed pages, so you re-embed only what moved and drop what's gone.
- A team that keeps it accurate. A dedicated data acquisition team is three engineers, a QA lead and a delivery manager, so a redesign that breaks extraction is caught by people, not by your users.
- Coverage and speed in writing. The SLA commits to at least 97% coverage per source on every run, detection of a breakage within 4 hours and a fix within 24 business hours.
- Checked, and yours. Every delivery is validated and comes with a quality report. The code and the data are yours.
Crawls of this size run through enterprise web crawling, and smaller source lists through our web scraping services.