Skip to content
isam.chajia
AI

Adding AI search to your web app with RAG: a practical guide

How retrieval-augmented generation turns your own content into an assistant that cites its sources — and how to build it without surprises.

Isam Chajia8 min read
Chat interface on a screen showing cited search results

Users do not want a search box that returns ten blue links. They want an answer. Retrieval-augmented generation (RAG) is a practical way to give them one over your own content.

How RAG works

  • Split your content into small passages.
  • Embed each passage and store the vectors.
  • Embed the question and retrieve the closest passages.
  • Ask a model to answer using only those passages.

Start with a boring, reliable pipeline

Begin with keyword or hybrid search before adding embeddings. A simple, well-tuned retrieval step beats a clever one you cannot debug.

Always cite sources

Return the passages that supported the answer and link to them. Citations build trust and make wrong answers visible instead of invisible.

select id, content
from documents
order by embedding <-> query_embedding
limit 5;

Control cost and quality

  • Cache embeddings so you do not pay twice.
  • Keep an evaluation set of real questions.
  • Log prompts and retrieved passages to debug failures.
  • Set a hard limit on tokens per request.
A good AI feature is one a user can verify, not one they have to trust.
  • AI
  • RAG
  • Supabase
Available for new work

Enjoying the writing?

If an article sparked an idea for your product or team, I'd be glad to hear about it.

Replies within 2 working daysMarrakech, Morocco