Case study

Building the RAG chatbot on my own website

This RAG chatbot case study covers the AI assistant on my own website. Visitors can ask it about my work, skills and writing. It answers from my own content, not from guesses. I built it with Next.js, the AI SDK and MongoDB Atlas. I run it through a CMS I also built. Below I explain how it works, the choices I made and why. I will not quote usage or accuracy numbers here. This page is about how it is built.

Discuss your chatbot

Context: why I built it

A personal site has a problem. People arrive with specific questions. Has he built a chatbot? Does he work remotely? What has he written about Claude Code? The answers are spread across pages and blog posts. Most visitors will not dig through all of them.

I wanted an assistant that could answer those questions in a few seconds. It also had to be honest. A chatbot that makes things up about me is worse than no chatbot. So retrieval augmented generation was the obvious choice. If you want the concept first, my page on retrieval augmented generation explains it step by step.

How the pipeline works

Every answer follows the same path.

  1. Collect the content. Knowledge entries that I manage in my CMS, plus every published blog post, are the source of truth.
  2. Split it into passages. Long text is cut into smaller passages, so each one covers a single idea.
  3. Embed each passage. Each passage becomes a vector with gemini-embedding-001, at 768 dimensions.
  4. Store and search. The vectors live in MongoDB Atlas. When a visitor asks a question, Atlas Vector Search finds the closest passages by cosine similarity.
  5. Answer with context. The 5 closest passages go to the model with the question. The model answers from them.

I chose MongoDB Atlas because the site's content already lives there. Keeping the vectors next to the content means one database, one backup and no extra service to run.

Choosing and protecting the model

The model is called through Vercel AI Gateway. The default is Claude Haiku 4.5. It is fast and cheap enough for short chat answers.

Any model provider can fail. Credits run out, or a service has a bad hour. So I added an automatic fallback to Gemini 2.5 Flash. If the first model fails before it writes its first word, the fallback answers instead. The visitor does not notice anything.

If every model fails, the visitor gets a friendly offline message. It points them to the contact page, so the question still reaches me.

I can also switch the model from the CMS without touching code. That makes it easy to try a new model or move away from one.

Keeping answers grounded and private

Retrieval alone is not enough. The model also needs clear rules.

A strict system prompt tells it to answer only from the retrieved passages. If the passages do not hold the answer, it must say it does not know. It should never fill the gap with a guess.

Privacy rules keep some topics out of answers. These include family details, weekend availability, job search status and anything my employer treats as confidential. For each one, the assistant has a polite, ready-made reply.

A tone guide shapes how it speaks. It answers in the visitor's language, English or Roman Urdu, and stays professional. The guide includes example conversations, so the model can see the style I want.

Managing knowledge from the CMS

I did not want to redeploy the site to teach the chatbot something new. So knowledge management lives in my CMS.

  • Add, edit or switch off entries. An entry that is switched off stops being used in answers.
  • Sync now. One button embeds new or changed passages. A content hash tells the system what has changed, so unchanged passages are not embedded again. That saves time and cost.
  • Try it. A test box lets me ask questions with the new settings before I save them. I see the effect of a change before visitors do.

Running it in production

A chatbot is a live service, so it needs the same care as any other.

Streaming. Answers stream to the browser word by word. The visitor sees the reply start at once, not after a long wait.

Rate limiting. Each visitor can send 20 messages per 5 minutes. This protects the service and the budget from abuse.

Recording. Every conversation is saved with the model used, the token usage and the estimated cost. I can see what each answer cost and which model gave it.

Follow-up. Questions the assistant could not answer are flagged. They show me what is missing from the knowledge base, so I know what to add next.

If you are curious what happens inside the model itself, my post Inside the Black Box walks through tokens, embeddings and inference.

The stack

  • Framework: Next.js 16 with the App Router.
  • AI layer: the AI SDK, with Vercel AI Gateway for model access.
  • Models: Claude Haiku 4.5 by default, with Gemini 2.5 Flash as the fallback.
  • Embeddings: gemini-embedding-001 at 768 dimensions.
  • Data and search: MongoDB Atlas with Atlas Vector Search.

What I would bring to your project

This RAG chatbot case study shows the parts I care about most. Answers stay grounded in real content. A fallback keeps the service up. Clear rules protect private topics. And the team that owns the content can manage knowledge without a developer.

The same approach fits a support bot, an internal help desk or a product assistant. I build these through my RAG chatbot development service. If you have content and want an assistant that answers from it, get in touch.

Frequently asked questions

What is a RAG chatbot?

A RAG chatbot answers questions by first searching a set of trusted content, then giving the most relevant passages to a language model. The model writes its answer from those passages. This keeps answers tied to real sources instead of the model's memory.

Why did you use MongoDB Atlas Vector Search?

The site's content already lived in MongoDB Atlas. Storing the vectors in the same place meant one database, one backup and no extra service. Atlas Vector Search finds the closest passages by cosine similarity.

What happens if the AI model is down?

The chatbot falls back to Gemini 2.5 Flash automatically if Claude Haiku 4.5 fails before its first word. If every model fails, the visitor sees a friendly offline message that points to the contact page.

How do you keep the chatbot from making things up?

A strict system prompt tells it to answer only from the retrieved passages and to say when it does not know. Unanswered questions are flagged, so I can add the missing knowledge later.

Can you build a similar chatbot for my business?

Yes. I can build an assistant that answers from your documents, help pages or product content, with grounding rules, a model fallback and a way for your team to manage knowledge. Start with a short conversation through the contact page.

Let's talk about your project

Software Architect, AI Native. Google Certified Generative AI Leader with 14+ years of experience.

Discuss your chatbot