How to Build a RAG Pipeline from Website Content
Retrieval-Augmented Generation (RAG) has become one of the most practical ways to build AI applications that can answer questions using external knowledge. Instead of relying entirely on information learned during model training, a RAG system retrieves relevant information from a knowledge base and provides it to a language model as context when generating an answer.

For many businesses, some of the most valuable information for that knowledge base already exists online. Product documentation, help centres, technical guides, pricing pages, company websites, and other public resources contain information that AI applications can use to answer questions more accurately. The challenge is getting that information into a format that an AI system can actually use.
A website is designed for people to browse, not for AI systems to retrieve precise information from. Content is spread across different pages, navigation elements, HTML structures, and sometimes dynamically rendered components. Pages change over time, and information that was accurate when first collected can quickly become outdated.
Building a reliable RAG pipeline from website content therefore involves more than scraping a few pages and sending their text to a vector database. You need a process for discovering relevant sources, collecting their content, extracting useful information, preparing it for retrieval, and keeping everything up to date.
This guide walks through the main steps involved in building that pipeline.
1. Understand the RAG pipeline
Before collecting website content, it helps to understand how the different parts of a RAG system fit together. A typical RAG application has two main workflows: An ingestion pipeline and a retrieval pipeline.
The ingestion pipeline collects external information and prepares it for search. It discovers relevant pages, extracts their content, transforms the content into manageable sections, generates embeddings, and stores the resulting data in an index.
The retrieval pipeline runs when someone asks a question. It converts the query into a searchable representation, retrieves relevant content from the index, and passes that content to a language model. The model uses the retrieved information to generate an answer.
The process looks roughly like this:
- Discover relevant website pages.
- Crawl the website and collect page content.
- Extract and clean the information.
- Split content into chunks.
- Generate embeddings.
- Store chunks and metadata in a searchable index.
- Retrieve relevant chunks when a user asks a question.
- Generate an answer using the retrieved context.
Each step affects the quality of the final result. A powerful language model cannot compensate for missing pages, poorly extracted content, or outdated information. If the ingestion pipeline provides incomplete or irrelevant data, the retrieval pipeline has little chance of producing a reliable answer.
This is why data collection deserves as much attention as the model and retrieval components.
2. Discover the right website pages to collect
The first step is identifying which pages should become part of your knowledge base. A common mistake is to crawl an entire website without considering whether every page is useful. Most websites contain a mixture of valuable information and content that has little relevance to an AI application. Navigation pages, login screens, search results, duplicate URLs, campaign landing pages, and outdated announcements may all end up in the collected dataset if the crawling process is not configured carefully.
Start by defining what the AI application needs to know.
For a customer support assistant, useful sources might include product documentation, help centre articles, troubleshooting guides, and frequently asked questions. For an internal research assistant, the relevant content could be company policies, technical documentation, reports, and product information.
Once you understand the use case, you can identify the websites and sections that contain the information you need.
There are several ways to discover pages on a website. Sitemaps are often a good starting point because they provide a list of URLs that the website owner wants search engines to discover. Internal links are another important source, allowing a crawler to navigate between pages by following links found in the HTML.
You can also start with a known set of URLs and expand from there, or use predefined URL patterns to limit crawling to specific sections of a website.
For example, a documentation website might use URLs such as:
example.com/docs/example.com/guides/example.com/api/
If the goal is to build a knowledge base about a product, these sections are likely to be more useful than the company's careers page or press releases.
URL filtering is important because it helps control what enters the pipeline. You can include relevant paths, exclude unwanted sections, and avoid collecting the same content through multiple URL variations.
It is also worth considering how frequently different pages change. A pricing page may need to be refreshed regularly, while a general company history page might remain unchanged for years. These differences will become important when designing the update process.
3. Crawl websites and extract their content
Once you know which pages to collect, the next step is getting their content.
Web crawling and data extraction are closely related, but they solve different problems.
Crawling is the process of discovering and visiting web pages. A crawler follows links, reads sitemaps, and retrieves URLs according to predefined rules. Its main responsibility is finding the pages that should be collected.
Extraction focuses on turning the content of those pages into useful data. This means identifying the main text, headings, lists, tables, links, and other relevant information while removing elements that do not contribute to the knowledge base.
For a RAG pipeline, both steps matter. Crawling determines which information becomes available, while extraction determines how useful that information will be once it reaches the retrieval system.
Handling different website structures
Websites do not all present information in the same way. Some use relatively simple HTML pages, while others rely heavily on JavaScript to render their content. Documentation platforms may use different layouts, and some websites place important information inside tables, expandable sections, or complex page structures.
A basic HTML scraper may work well for a simple website but fail to collect content from a page that requires JavaScript rendering. Similarly, extracting all visible text from a page can introduce navigation menus, cookie notices, footers, and other unrelated information into the dataset.
The extraction process should therefore focus on the actual content rather than treating every piece of text as equally important.
For example, consider a product documentation page containing a heading, an explanation, a code example, and a navigation sidebar. A useful extraction process should preserve the heading, explanation, and code example while avoiding unnecessary interface elements.
The output format also matters. HTML is useful for representing the original page structure, but it can be unnecessarily complicated for downstream processing. Markdown is often a practical alternative because it preserves headings, lists, links, and code blocks in a format that is easier to process.
The goal is not simply to extract as much text as possible. It is to preserve the information and structure that help an AI system understand what the content means.
4. Prepare website content for RAG
Raw website content is rarely ready to be indexed directly. Before generating embeddings, you should transform the extracted information into a consistent format.
This stage is often called data preparation or document processing.
The first task is cleaning the content. Remove irrelevant navigation elements, repeated page components, cookie banners, and other boilerplate that can interfere with retrieval. At the same time, avoid removing information that gives the content meaning.
For example, a heading such as "Authentication" may look like a small piece of text, but it tells the reader what the following paragraphs describe. Removing headings can make individual text sections much harder to interpret once they are separated from the original page.
Preserving document structure is therefore important. Headings, paragraphs, lists, tables, and code examples should retain their relationships wherever possible.
Add metadata to every document
Content should also be accompanied by metadata that describes where it came from and how it should be used.
Useful metadata fields include:
- Source URL: The original page address.
- Page title: The title of the source page.
- Section: The relevant heading or section.
- Content type: Documentation, product information, FAQ, policy, and so on.
- Last updated: When the source was last modified or collected.
- Collection date: When the content entered the pipeline.
Metadata improves both retrieval and traceability. It allows an application to filter results by source or content type, display links to the original information, and identify when a document was last collected.
It also becomes essential when the knowledge base needs to be updated. If a page changes, the pipeline needs to know which indexed content belongs to that source.
Choose an appropriate chunking strategy
After cleaning and structuring the content, it needs to be divided into smaller sections called chunks.
Language models have limits on how much context they can process at once. Sending an entire website or large document into a prompt is usually impractical. Chunking makes it possible to retrieve only the sections that are relevant to a particular question.
There is no universally correct chunk size. Smaller chunks can make retrieval more precise, but they may lose important context. Larger chunks preserve more surrounding information but can introduce irrelevant text into the retrieved results.
A common starting point is to create chunks of a few hundred tokens, sometimes with a small overlap between neighbouring chunks. The right configuration depends on the content and the questions users are likely to ask.
However, splitting content purely based on character count or token count can create problems. A paragraph might be separated from its heading, a list might be divided in the middle, or a code example might become disconnected from the explanation that introduces it.
A better approach is to use the document's existing structure when possible. Split content along headings, paragraphs, or other natural boundaries, then apply size limits where necessary.
For example, a documentation page about API authentication might contain separate sections for API keys, OAuth, and token expiration. Keeping those sections separate makes it easier for the retrieval system to return the right information when someone asks a specific question.
The objective is to create chunks that are small enough to retrieve efficiently but complete enough to make sense on their own.
5. Generate embeddings and index the content
Once the content has been prepared and divided into chunks, the next step is creating embeddings.
An embedding is a numerical representation of text that captures aspects of its meaning. Text with similar semantic meaning tends to have embeddings that are closer together in vector space.
This allows a retrieval system to find relevant content even when the wording of a question differs from the wording used in the original document.
For example, a user might ask, "How do I reset my password?" while the documentation uses the heading "Changing your account credentials." A semantic search system may still identify the relevant section because the underlying concepts are related.
An embedding model converts each chunk into a vector. These vectors are then stored in a vector database or another system that supports similarity search.
Common vector database options include Pinecone, Qdrant, Weaviate, and PostgreSQL with the pgvector extension. The best choice depends on your existing infrastructure, scale, filtering requirements, and operational preferences.
When storing the content, keep the original text and its metadata alongside the embedding. The vector helps find relevant information, but the original content is what the language model ultimately needs.
You should also preserve a stable relationship between the indexed chunk and its source document. This makes it possible to retrieve the original URL, display citations, and update or remove chunks when the underlying page changes.
Consider hybrid search
Vector search is useful for finding conceptually related information, but it is not always enough on its own.
Some questions depend on exact terms, product names, identifiers, error codes, or technical phrases. A user searching for a specific API endpoint may need an exact keyword match rather than a semantically similar paragraph.
Hybrid search combines vector similarity with traditional keyword search. Depending on the implementation, the results can be combined or reranked to improve relevance.
For documentation and technical knowledge bases, this can be particularly useful because exact terminology often matters as much as semantic meaning.
6. Retrieve relevant information and generate answers
With the content indexed, the application can start answering questions.
When a user submits a query, the retrieval system searches the knowledge base for relevant chunks. These chunks are then included in the prompt sent to the language model.
A simplified retrieval workflow looks like this:
- Receive the user's question.
- Convert the question into an embedding.
- Search the index for similar content.
- Retrieve the most relevant chunks.
- Optionally rerank the results.
- Build a prompt containing the question and retrieved context.
- Generate an answer using the language model.
The quality of this process depends on more than finding text with a high similarity score.
The system needs to retrieve enough information to answer the question without overwhelming the model with unrelated content. If the retrieved chunks are incomplete, the model may lack important context. If too many irrelevant chunks are included, they can make the answer less focused.
Reranking can help by evaluating an initial set of search results and ordering them according to their relevance to the query. Some systems also use metadata filters to narrow results by source, product, document type, or other attributes.
Another important consideration is source attribution. When an answer is based on website content, users should be able to see where the information came from. Including source URLs and relevant page titles in the retrieved context makes it easier to provide references alongside generated answers.
A RAG application should also be able to handle situations where the knowledge base does not contain enough information. Rather than generating an answer based on assumptions, it should be able to communicate that the available sources do not provide a reliable answer.
7. Keep the knowledge base up to date
One of the biggest challenges when building a RAG pipeline from website content is maintaining the data after the initial collection.
Websites are constantly changing. Documentation gets revised, pricing changes, product features are introduced, policies are updated, and pages are removed. If the ingestion pipeline only runs once, the knowledge base gradually becomes less accurate.
This creates a problem that is easy to overlook during development: an AI application can retrieve information correctly from its index and still produce an incorrect answer because the indexed information is outdated.
Keeping the knowledge base current requires an ongoing update process.
Schedule regular refreshes
The simplest approach is to periodically crawl the source websites again. Depending on the type of content, this might happen hourly, daily, weekly, or monthly.
The refresh frequency should reflect how quickly the information is likely to change and how important freshness is to the application.
For example, pricing information or product availability may need frequent updates. General documentation or company background information might require less frequent checks.
Running a full crawl every time is not always necessary. A more efficient pipeline identifies which pages have changed and processes only those pages.
Detect changes at the page level
Change detection helps avoid unnecessary processing.
A pipeline can compare newly collected page content with the previously stored version. This can be done using content hashes, timestamps, HTTP headers such as ETag and Last-Modified where available, or direct comparisons of extracted content.
When a meaningful change is detected, the pipeline can reprocess the page, generate new embeddings, and update the corresponding records in the index.
It is important to distinguish between meaningful content changes and minor technical changes. A website might update a navigation element, tracking script, or footer without changing the information that the AI application relies on.
Monitoring should therefore focus on the content that matters to the use case.
Remove outdated content
Updating a page is only one part of maintaining the index. Pages can also disappear, move to a different URL, or be replaced by new versions.
If old chunks remain in the vector database after the source has changed, the retrieval system may return conflicting information.
A reliable update process should therefore account for deletions and replacements as well as additions. When a source page is removed or its content is replaced, the corresponding indexed records should be updated or removed.
It is also useful to retain source history where appropriate. Keeping a record of previous versions can help with debugging, auditing, and understanding why an AI application produced a particular answer.
Monitor important sources
Scheduled refreshes help maintain freshness, but they do not always provide enough visibility into important changes.
For some sources, it is useful to monitor pages for specific types of updates and receive notifications when something relevant happens.
For example, a company might want to know when a competitor changes its pricing page, when API documentation introduces a new limit, or when a policy page is updated.
This is where website monitoring becomes a valuable part of the broader data pipeline. Instead of treating collection as a one-time operation, you can continuously track the sources your AI application depends on.
Tools such as Bulkgrid can help with this process by allowing teams to monitor websites, collections, and individual pages, detect changes, and receive notifications through email, Slack, or webhooks.
The important principle is that freshness should be built into the architecture from the beginning. It should not be treated as an optional maintenance task after the RAG application has been launched.
8. Common mistakes when building a website-based RAG pipeline
A RAG pipeline can be technically functional while still producing poor results. In many cases, the problem is not the language model but the way the underlying data has been collected and prepared.
One common mistake is collecting too much content without filtering it. More data does not automatically mean better answers. Irrelevant pages can reduce retrieval quality and make it harder to find the information that actually matters.
Another mistake is extracting text without preserving its structure. Headings, lists, tables, and code examples provide context. Removing them can turn useful documentation into disconnected paragraphs that are difficult to retrieve accurately.
Chunking is another area where small decisions can have a significant impact. Chunks that are too small may lose context, while chunks that are too large may contain several unrelated topics. Testing different chunking strategies against realistic questions is usually more effective than relying on a fixed configuration.
Some teams also focus heavily on embeddings and vector databases while overlooking metadata. Without source URLs, document identifiers, and timestamps, it becomes harder to provide citations, filter search results, and maintain the index over time.
Finally, many pipelines fail to account for changing source content. A system that works well during its initial demonstration may become less reliable as websites evolve and the knowledge base falls behind.
These issues illustrate why RAG should be treated as a complete data pipeline rather than simply a combination of a vector database and a language model.
9. Build for reliability from the beginning
A successful RAG application depends on the quality of the information it can retrieve. That quality is determined long before a language model generates its first answer.
The most reliable systems treat website content as a continuously maintained data source. They have a clear process for discovering relevant pages, extracting structured content, preserving source information, indexing documents, and detecting changes.
It is also important to test the pipeline using real questions. Create a set of representative queries and evaluate whether the system retrieves the correct pages, includes enough context, and provides answers that can be traced back to their sources. Repeat these tests when changing extraction rules, chunking strategies, embedding models, or retrieval settings.
Over time, this makes it easier to identify where problems originate. An incorrect answer might be caused by missing source content, poor extraction, an unsuitable chunking strategy, or retrieval that selects the wrong information. Measuring the different stages separately makes those problems easier to diagnose.
Building a RAG pipeline is not just about connecting a website to an AI model. It is about creating a dependable process that turns external information into knowledge an AI application can use.
When the underlying data is accurate, structured, and up to date, the entire application has a stronger foundation.
Better AI starts with better data infrastructure.