How to build AI search and chat over a large website

Embedding 300,000 pages costs about $13. Answering 50,000 questions a month costs about $400. How to build AI search and chat on a big site.

12 min read
How to build AI search and chat over a large website

AI search and chat over a large website works in two steps: search finds the few paragraphs that answer the question, then a language model writes the answer from those, with links back to the pages. Embedding a 300,000-page site costs about $13 on OpenAI's smallest model. Answering 50,000 questions a month costs about $400, and that's where the budget goes, along with the work of cleaning content and keeping the index current.

The build itself goes like this. You export the content and strip the parts repeated on every page. You split each page into chunks of a few hundred words and turn each chunk into an embedding (a list of numbers that captures its meaning). Those go into an index that handles both keyword and vector search. When someone asks a question, you pull a shortlist of chunks, rerank them, and pass the top few to the model.

Why a small-site chat doesn't scale

A 300,000-page site holds about 3,000 times more text than a model can read at once, so it needs a search step before the model sees anything. A small site doesn't.

My own portfolio, mohitgoyal.in, has a chat that answers as me, built on the Anthropic Claude API with Firestore. I wrote up how that chat portfolio was built. The facts it answers from are a few thousand words, about the size of the site's llms.txt file. So the model reads all of it on every question. No search step, no vector database.

A publisher, docs site, marketplace or deals site is a different job. Take 300,000 pages at about 2,000 tokens each (a token is roughly three quarters of a word). That's 600 million tokens. Claude's context window, the amount of text the model can read at once, is 200,000 tokens. Something has to pick the right ten paragraphs out of a million first.

That step is called retrieval, and the whole setup is called RAG (retrieval-augmented generation). On a big site, answer quality comes down to retrieval. If the right chunk isn't in what you hand the model, no model can fix it.

How AI search and chat over a large website works

Two pipelines run side by side. One turns pages into indexed chunks in the background. The other answers each question from that index in a couple of seconds.

Rendering diagram…

The arrow from "Page changed or deleted" back to cleaning is the one that keeps the answers true, and it's the one most builds skip.

Getting the content out

Export from the source if you can. A WordPress site gives you the REST API or a database dump. A headless CMS has its content API. A marketplace or deals site already has every listing as rows in a database. An export gives you clean text plus the fields you'll filter on later: category, author, publish date, price, stock status, expiry date.

Crawl only when you don't control the source, or when the content sits across several systems. Crawling 300,000 pages works, but you get raw HTML and have to rebuild structure the CMS already had. You'll also need to rate-limit the crawler so it doesn't slow the live site.

On a deals site or marketplace, the fields matter as much as the text. Ask for laptop deals under $500 and a vector search on its own will return a deal that has already expired. Store expiry date and price as metadata on every chunk and filter on them before ranking.

How should you clean and chunk the pages?

Strip everything except the main content, then split each page on its headings into chunks of about 300 to 800 tokens.

This is where most large-site projects go wrong. Every page on a big site carries the same header menu, footer, cookie banner, related-posts block and newsletter box. Embed pages as they are and that text gets embedded 300,000 times. Then "how do I contact support" matches the footer on every page and returns 30 identical, useless chunks.

So strip the template. On most sites the main content sits inside one <main> or <article> element, and that's all you keep. Then remove near-duplicates, because large sites are full of them: tag and category archives, paginated lists, print versions, and faceted URLs like ?color=red&sort=price on a marketplace. Index the canonical page once.

For chunking, split on headings first, then by length. For articles and docs, 300 to 800 tokens with a small overlap works well. Each chunk should carry its page title, its heading path ("Billing > Refunds > Partial refunds") and its URL with a #heading anchor. Add that heading path to the text before embedding. A chunk that only says "click Save to confirm" means nothing without it.

Listings are different. A product or deal is usually short enough to be one chunk: title, key specs, description and price in one block, with the structured fields as metadata.

Keep the cleaned chunks in your own storage, separate from the index. You will re-embed at some point, when a better model comes out or you change chunk sizes, and you don't want to re-crawl to do it.

What does it cost to embed 300,000 pages?

About $13 to embed once, then roughly $400 a month to answer 50,000 questions.

The numbers rest on these assumptions: 300,000 pages, about 2,000 tokens of main content each after cleaning, chunks of about 500 tokens with a 50-token overlap. That's roughly 4 chunks and 2,200 embedded tokens per page, so 1.2 million chunks and 660 million tokens in total.

OpenAI's pricing page lists text-embedding-3-small at $0.02 per million tokens and text-embedding-3-large at $0.13 per million, with the Batch API at half those rates.

660M

Tokens to embed (300,000 pages)

$13.20

text-embedding-3-small, standard

$6.60

text-embedding-3-small, Batch API

$85.80

text-embedding-3-large, standard

Storage is small too. text-embedding-3-small returns 1,536 numbers per chunk. At 4 bytes each, 1.2 million vectors come to about 7.4 GB before metadata and index overhead. Cloudflare Vectorize's pricing charges $0.05 per 100 million stored dimensions after the 10 million included in the $5 Workers Paid plan. 1.2 million vectors at 1,536 dimensions is about 1.84 billion dimensions, so under $1 a month.

Answering is the part people leave out of their estimate. Say each answer sends the model 6 chunks (3,300 tokens) plus about 700 tokens of instructions and the question, and gets back about 400 tokens. Anthropic prices Claude Haiku 4.5 at $1 per million input tokens and $5 per million output tokens. That's about $0.006 per answer, or about $300 a month at 50,000 questions. Add a reranker such as Cohere Rerank, which Cohere prices at $2 per 1,000 searches, and that's another $100 a month.

So plan the budget around traffic, not page count. Two things cut the monthly bill: caching answers to common questions, and showing plain search results first with the AI answer as an option. For chatbot pricing more widely, from widget services to custom builds, see what an AI chatbot for a website costs.

Where to store the index

For most large sites, put the vectors in the search engine the site already runs. That means pgvector if the content lives in Postgres, or Algolia or Elasticsearch if the search box already uses one. Prices below are from each vendor's pricing page in 2026, and they change often.

OptionWhat you getKeyword and vector together?Price to start
Cloudflare AI SearchManaged pipeline: ingests from R2 storage or a website crawl, chunks, embeds, stores in Vectorize, answersManaged for you, with less control over chunking and rankingCloudflare's docs bill it through the services it uses: Workers AI, Vectorize, R2 and AI Gateway
Cloudflare VectorizeVector database onlyNo full-text index, so keyword search needs a second store$5/month Workers Paid plan, then $0.01 per million queried dimensions and $0.05 per 100 million stored dimensions past the included amounts
AlgoliaHosted keyword search engine; NeuralSearch, which adds vectors, is on the Elevate plan, not GrowYes, on the Elevate plan with NeuralSearchGrow plan: pay as you go, $0.50 per 1,000 search requests and $0.40 per 1,000 records past the free allowance, so 1.2 million records is about $480 a month before searches
Elastic CloudElasticsearch with BM25 keyword ranking and dense vectors in one engineYesCloud Hosted is billed by the size of the deployment
PineconeManaged vector database with sparse-dense supportYes, with sparse vectors for keywordsStandard plan has a $50 monthly minimum, then usage for storage, reads and writes
pgvector on PostgresFree extension that adds vector columns to PostgresYes, with Postgres full-text searchFree on your own server. Supabase Pro is $25 a month, and 7 GB or more of vectors will need a larger compute add-on

If the content is already in Postgres, pgvector has the fewest moving parts: one database, one backup, filters in plain SQL. If the site already pays for Algolia or Elasticsearch, add vectors there rather than syncing a second system. If you want a working prototype on a slice of the site this week, Cloudflare AI Search is the quickest route, and you can move to your own pipeline once you've seen what users ask.

I'd avoid a vector-only store for a large site unless it's paired with a keyword index.

Hybrid search and reranking

Vector search finds meaning. Ask "how do I get my money back" and it finds the refunds page even though the page never says "money back". But it's weak on exact strings: model numbers, SKUs, error codes, people's names, rare product terms. Someone searching "XPS 9530" wants that exact laptop, and an embedding may rank a similar Dell model just as high.

Keyword search (BM25 is the standard method) is the opposite. It gets exact terms right and misses synonyms. Hybrid search runs both and merges the two ranked lists, usually with reciprocal rank fusion, which rewards chunks that rank well on both. On a site full of names and codes, hybrid beats either one alone.

Then rerank. Take the top 30 to 50 merged results and pass them through a reranker, a model that reads the question and each chunk together and scores the match. It's slower than the first search, which is why it only sees a shortlist. Send the top 5 to 8 to the language model.

Apply metadata filters before any of this: in stock, not expired, the right product category, the right docs version. The model should never see content it mustn't quote.

How do you stop the AI making up answers?

Make the model answer only from chunks you supply, cite each one, and check those citations in code.

Give each chunk an ID and pass it with its title and URL. Tell the model to answer only from those chunks, put the chunk ID after each claim, and say plainly when the chunks don't contain the answer. Then check the output: every cited ID must be one you actually sent. Drop or flag any answer that cites something else, and turn the valid IDs into links to the page and heading.

The "I don't know" path matters more on a large site than a small one. With a million chunks, retrieval always returns something. Feed a weak match to a model and you get a confident wrong answer. Set a minimum relevance score from the reranker, and below it, show normal search results instead.

Put the sources as visible links right next to the answer. People click them, so your pages keep getting traffic. And when an answer is wrong, the link tells you which page or chunk caused it.

How do you keep the index fresh?

Build the update path on day one, because a large site changes every day. Three sources of change cover most sites:

  • A webhook or queue message from the CMS when a page is published, edited or deleted.
  • The sitemap's lastmod dates, checked nightly, to catch anything the webhook missed.
  • Expiry dates on deals, events and listings, removed on a schedule whether or not anyone edited them.

On WordPress, the publish and delete hooks can send that message, and the REST API or WPGraphQL serves the changed page to the pipeline, the same setup I use on headless WordPress builds.

Store a hash (a short fingerprint of the text) for every chunk. When a page changes, re-chunk it, compare hashes and re-embed only the chunks that changed. Most edits touch one paragraph, so most updates cost next to nothing.

Deletions are the step people forget. A page starts returning a 404 or a product is pulled, but its chunks stay in the index, and the chat keeps quoting a price or policy that no longer exists. Delete by URL. Then run a weekly job that compares the index with the live sitemap and removes anything orphaned.

If you already push changed URLs to search engines, for example with IndexNow, hang the re-index job off the same event. One "page changed" signal feeds both.

Testing answer quality

Before launch, collect 100 to 200 real questions from your site search logs and support inbox, and pair each with the URL that holds the right answer. Then measure retrieval and answers separately.

For retrieval, the test is simple: is the correct URL in the top 5 chunks? If it isn't, no prompt change will help. The fix is in cleaning, chunking, filters or hybrid weighting.

For answers, check three things: is it correct, is it backed by the cited chunk, and does it decline when it should? Read a sample yourself after each change, even if a second model does the grading.

Run the full set after every change to chunk size, embedding model, reranker or prompt, since a fix for one question can break three others. After launch, log each question, the retrieved chunks and the answer, with a thumbs-down button. Those thumbs-down questions become your next test cases.

If you want to check which stack fits your site before you start, the Tech Stack Advisor gives a layer-by-layer recommendation with the trade-offs.

Was this helpful?

Share

Frequently asked

Can a ready-made chatbot plugin handle a website with hundreds of thousands of pages?+

Most chatbot plugins and widget services cap the number of pages or characters they will train on, and they give little control over chunking, filters or freshness. Chatbot plugins work for a few hundred pages. At 300,000 pages a site needs its own retrieval pipeline or a managed one like Cloudflare AI Search.

Do I have to re-embed my whole site if I change embedding models?+

Yes. Vectors from two different embedding models can't be compared, so switching models means re-embedding every chunk. Storing the cleaned chunks separately means only the embedding step has to be redone, with no re-crawl.

Do I need a separate vector database if my site already uses Elasticsearch or Postgres?+

Usually no. Elasticsearch stores dense vectors next to its keyword index, and Postgres gets vector search from the free pgvector extension. Adding vectors to the search engine a site already runs is simpler than syncing a second database.

Will adding an AI chat to my website stop Google or ChatGPT from citing my pages?+

No. An on-site AI chat sits on top of the pages and doesn't replace them, so as long as the pages stay crawlable and server-rendered, search engines and AI crawlers see them as before. The clean, well-structured content prepared for the chat also makes the pages easier for outside AI tools to quote.

Mohit Goyal

Written by

Senior Web Developer in Gurugram, India. 100+ fast, SEO-friendly sites shipped in 4.5+ years with Next.js, React and WordPress, including the procol.ai rebuild. Send me your next project.

I work as a freelance web developer in Gurugram, India.

About me →LinkedIn →More on SEO and analytics →

Keep reading

How to link brand entities using JSON-LD

Join Organization, WebSite, Person and Service nodes in JSON-LD with stable @id values and a clean sameAs list. Includes a full working example.

10 min read

Service schema markup: how to add it for a service business

Service schema markup in JSON-LD: link Service to your Organization, add areaServed and offers, with a copy-paste example and what it does for AI search.

11 min read