Bonaventure OgetoBy Bonaventure Ogeto|

What Is RAG and Why Every Kenyan Startup Is Suddenly Asking for It

RAG (Retrieval-Augmented Generation) is a technique where you give an AI model access to your own data by searching a knowledge base, retrieving the most relevant information, and injecting it into the prompt before the model responds. It solves the core problem that LLMs do not know anything about your company, your products, or your internal documents.

The Problem RAG Solves

Imagine you are building a customer support chatbot for a Kenyan e-commerce startup. You connect it to ChatGPT or Claude, and a customer asks: "What is your return policy?" The AI confidently responds with a generic return policy that has nothing to do with your actual business. It might even invent details. This is the fundamental problem.

Large language models like GPT-4 and Claude are trained on vast amounts of internet data. They know a lot about the world in general. But they know absolutely nothing about your specific company, your products, your policies, your internal documentation, or your customer data. They cannot. That information was never in their training set.

You have three options for fixing this:

  • Fine-tuning: Retrain the model on your data. Expensive, slow, requires ML expertise, and you need to retrain every time your data changes.
  • Stuffing the prompt: Paste all your documentation into the system prompt. Works for tiny amounts of data, but context windows have limits and costs increase with every token.
  • RAG: Search your data at query time, retrieve only the relevant parts, and inject them into the prompt. Fast, cheap, easy to update, and scales to large knowledge bases.

RAG is the right answer for almost every "I need the AI to know about my stuff" use case. It is not new (the technique was described in a 2020 research paper from Meta), but it has become the standard approach in 2025-2026 as businesses have moved from playing with AI demos to building real products.

The reason every Kenyan startup is suddenly asking for RAG is simple. They have tried building chatbots with generic AI, discovered the AI does not know anything useful about their business, and realized they need a way to give it that knowledge. RAG is that way.

How RAG Works (Without the Jargon)

RAG sounds technical, but the concept is something you already understand. Think about how you would answer a question about a topic you do not know well.

You would not try to answer from memory. You would open Google, search for the relevant information, read the top results, and then form your answer based on what you found. RAG is exactly this process, automated for an AI model.

Here is what happens when a user asks your RAG-powered chatbot a question:

Step 1: The user asks a question. "What are your delivery times to Mombasa?"

Step 2: The system searches your knowledge base. It looks through your stored documents (FAQs, product pages, policy documents, help articles) and finds the chunks that are most relevant to the question. In this case, it finds a section from your shipping policy that mentions delivery times by city.

Step 3: The relevant chunks are added to the prompt. The system builds a prompt like: "Here is the relevant information from our documentation: [shipping policy excerpt]. Based on this information, answer the customer's question: What are your delivery times to Mombasa?"

Step 4: The AI generates an answer grounded in your data. "Delivery to Mombasa typically takes 3-5 business days. For express delivery, you can expect 1-2 business days at an additional fee." This answer is accurate because it comes from your actual documentation, not from the AI making things up.

That is the entire concept. Search, retrieve, generate. The "retrieval" happens before the "generation," which is why it is called Retrieval-Augmented Generation. You are augmenting what the AI can do by giving it relevant information at the moment it needs it.

The technical magic is in step 2, specifically, how the system knows which documents are "relevant" to a given question. That is where embeddings and vector search come in, which we cover in the next section.

Real RAG Use Cases for Kenyan Businesses

RAG is not just a Silicon Valley toy. It solves real problems for Kenyan businesses right now. Here are the use cases we see most often.

Customer Support Bots That Actually Know Your Products

This is the most common use case by far. You have a product catalog, FAQ pages, help documentation, and shipping policies. Instead of hiring more support agents or building a rigid decision-tree chatbot, you build a RAG system that searches your docs and answers customer questions accurately. It works 24/7, handles questions in both English and Swahili (if your docs are in both languages), and escalates to human agents only when it cannot find an answer. For e-commerce companies, SaaS products, and fintechs, this is the first AI feature that pays for itself.

Internal Knowledge Bases

Every growing company has this problem: tribal knowledge trapped in Slack messages, Google Docs, Notion pages, and people's heads. A RAG-powered internal tool lets team members ask natural-language questions and get answers pulled from across all your internal documentation. "What is our process for onboarding a new vendor?" "What were the key decisions from last quarter's board meeting?" Instead of searching through twenty documents, the team asks the AI, and it finds the answer.

Document Q&A

Law firms, consulting companies, and government agencies deal with large volumes of documents. RAG lets you build a system where users upload a contract, policy document, or report, and then ask questions about it. "What are the termination clauses in this contract?" "What does this regulation say about data protection?" The AI reads the document and answers based on its contents, with the ability to cite the specific section.

Product Recommendation and Discovery

For e-commerce platforms and marketplaces, RAG can power a conversational product discovery experience. Instead of browsing categories and applying filters, customers describe what they need: "I need a laptop under KES 80,000 for programming." The RAG system searches your product catalog and recommends specific products with explanations of why they match.

M-Pesa and Financial Services FAQ

Fintechs and M-Pesa-integrated businesses get the same questions over and over: "How do I reverse a transaction?" "Why was my payment declined?" "What are your transaction limits?" A RAG chatbot trained on your transaction troubleshooting docs handles these questions instantly, freeing up your support team for complex issues that require human judgment.

Building a Basic RAG System: The Practical Steps

Let us get concrete. Here is what you need to build a basic RAG system, and it is less than you might think.

What you need:

  • A set of documents (your knowledge base)
  • An embedding model (OpenAI's text-embedding-3-small is the easiest starting point)
  • A vector database (Supabase with pgvector if you are already using Supabase, or Pinecone for a standalone option)
  • An AI model for generation (GPT-4o-mini, Claude Haiku, or their larger siblings)

Phase 1: Prepare your knowledge base.

Gather your documents. This might be your website content, help articles, product descriptions, policy documents, or internal wikis. Split each document into chunks of about 200-500 words. Each chunk should be self-contained, meaning someone should be able to read it and understand the point without needing the surrounding text. Splitting on paragraph or section boundaries usually works better than splitting at arbitrary character counts.

Phase 2: Embed and store.

Send each chunk to the embedding model and store the resulting vector alongside the original text in your vector database. With Supabase and pgvector, this looks like:

// Embed a chunk and store it
const embedding = await openai.embeddings.create({
  model: 'text-embedding-3-small',
  input: chunkText,
});

await supabase.from('knowledge_base').insert({
  content: chunkText,
  embedding: embedding.data[0].embedding,
  source: 'shipping-policy.md',
  section: 'Delivery Times',
});

Phase 3: Build the query pipeline.

When a user asks a question, embed their question, search for the most relevant chunks, and build the prompt:

async function answerQuestion(question: string): Promise<string> {
  // 1. Embed the question
  const questionEmbedding = await openai.embeddings.create({
    model: 'text-embedding-3-small',
    input: question,
  });

  // 2. Find relevant chunks
  const { data: chunks } = await supabase.rpc('match_knowledge_base', {
    query_embedding: questionEmbedding.data[0].embedding,
    match_threshold: 0.7,
    match_count: 5,
  });

  // 3. Build the prompt with context
  const context = chunks.map((c: any) => c.content).join('\n\n');

  const response = await openai.chat.completions.create({
    model: 'gpt-4o-mini',
    messages: [
      {
        role: 'system',
        content: `You are a helpful customer support assistant. Answer the question
based ONLY on the following context. If the context does not contain enough
information to answer, say so honestly. Do not make up information.

Context:
${context}`,
      },
      { role: 'user', content: question },
    ],
  });

  return response.choices[0]?.message?.content || 'I could not find an answer.';
}

That is a complete, working RAG pipeline. It is not production-ready (you would want error handling, caching, and evaluation), but it demonstrates the core pattern in about 40 lines of code. The system prompt instruction to answer "ONLY based on the context" is crucial. Without it, the AI will happily mix in information from its training data, which defeats the entire purpose of RAG.

RAG vs Fine-Tuning vs Prompt Stuffing: When to Use What

RAG is not the only way to give AI access to custom knowledge. Here is when each approach makes sense, and why RAG is usually the right starting point.

Prompt Stuffing (Putting data directly in the prompt)

Best for: Very small amounts of data. If your entire knowledge base fits in a few thousand words, just paste it into the system prompt. No need for embeddings, vector databases, or any infrastructure. A restaurant chatbot with a menu, hours, and location can handle everything in the system prompt. The limit is practical: once your data exceeds a few pages, prompt stuffing gets expensive (you pay for all those input tokens on every request) and the AI starts struggling to find relevant information in a wall of text.

RAG (Retrieval-Augmented Generation)

Best for: Most real-world use cases. RAG shines when your knowledge base is too large for the prompt but does not require changes to the model's fundamental behavior. Customer support docs, product catalogs, internal wikis, policy documents. RAG is also the best choice when your data changes frequently, because you just update the knowledge base without touching the model. The main limitation is that RAG cannot change how the model writes or reasons. It only changes what information the model has access to.

Fine-Tuning (Retraining the model on your data)

Best for: Changing the model's behavior, tone, or output format. If you want the AI to write in your brand voice, follow a specific response format, or handle domain-specific reasoning patterns, fine-tuning is the tool. The cost is significantly higher (both money and time), you need hundreds to thousands of training examples, and you have to retrain every time the model needs to learn new behavior. For most Kenyan startups, fine-tuning is overkill until you have validated the product and need to optimize.

The practical recommendation: Start with prompt stuffing if your data is small. Move to RAG when it outgrows the prompt. Consider fine-tuning only when RAG is working but the model's output quality or style is not meeting your standards. In practice, RAG alone handles the vast majority of business use cases. You can always add fine-tuning later.

If you want a deeper technical comparison, check our detailed comparison guide.

Getting Started: Your First Weekend with RAG

If you want to build your first RAG system this weekend, here is a concrete plan.

Saturday morning: Set up the infrastructure.

Create a Supabase project (free tier is fine). Enable the pgvector extension. Create a table for your knowledge base with a vector column. Get an OpenAI API key if you do not have one. Total setup time: about 30 minutes.

Saturday afternoon: Index your documents.

Pick a small, focused knowledge base to start. Your company's FAQ page, a product catalog with 20-50 items, or a help documentation section. Split the content into chunks, embed them, and store them in Supabase. Write a simple script to do this. You will probably index 50-200 chunks. Total time: 2-3 hours.

Sunday morning: Build the query pipeline.

Write the search and generation code. Test it with 10-15 real questions that customers would actually ask. Tweak the system prompt based on the answers you get. The first version will not be perfect, and that is fine. Total time: 2-3 hours.

Sunday afternoon: Wire it into your app.

Build a simple chat UI (or use the one from our chatbot tutorial). Connect it to your RAG backend. Test with a few friends or teammates. Gather feedback. Total time: 2-3 hours.

By Sunday evening, you have a working RAG-powered chatbot that answers questions about your business using your actual data. It will not be production-ready (you need error handling, rate limiting, and more testing), but you will have a clear understanding of the technology and a prototype you can iterate on.

The most important takeaway: RAG is not a research project. It is an engineering task. If you can call an API, query a database, and build a basic web interface, you can build a RAG system. The barrier is not technical complexity. It is just sitting down and doing it.

Key Takeaways

  • RAG lets AI answer questions about your own data without retraining the model. You provide the knowledge, the AI provides the reasoning.
  • The core idea is simple: search your documents, grab the relevant parts, paste them into the prompt, and let the AI answer based on that context.
  • RAG is cheaper and faster to implement than fine-tuning, and you can update the knowledge base any time without touching the model.
  • Common use cases in Kenya include customer support bots that know your products, internal knowledge bases, and document Q&A systems.
  • You can build a basic RAG system in a weekend using Supabase (pgvector) for storage and any major AI API for generation.

Frequently Asked Questions

How much does it cost to build a RAG system?
The infrastructure can be free (Supabase free tier for storage, OpenAI or Anthropic pay-per-use for embeddings and generation). Embedding 1,000 pages of text costs roughly $0.02. Each user query costs $0.01-0.05 depending on the model. For a small startup handling a few hundred queries per day, expect $20-50/month in API costs. The main cost is developer time, not infrastructure.
Does RAG work with documents in Swahili?
Yes, with some caveats. Modern embedding models (OpenAI text-embedding-3, Cohere Embed v3) support Swahili and other African languages. Retrieval quality may be slightly lower than English because these languages were underrepresented in training data. Test with your actual documents. For mixed-language use cases (English docs, Swahili queries), results are generally good because the models understand cross-language semantics.
How often do I need to update the knowledge base?
Whenever your source data changes. If your product catalog updates weekly, re-index the changed items weekly. If your policy documents change quarterly, update them quarterly. The beauty of RAG is that updating is simple: embed the new or changed content and insert or replace it in the database. No model retraining required.
Can RAG completely replace human customer support?
No, and it should not. RAG handles routine, information-based questions well: "What are your delivery times?" "How do I reset my password?" For complex issues (billing disputes, damaged items, emotional customers), you still need human agents. The best setup is RAG for the first line, with clear escalation to humans when the AI cannot resolve the issue or the customer requests it.
What is the difference between RAG and just using a bigger context window?
Bigger context windows (200K+ tokens) let you fit more data in the prompt, but they do not solve the problem. First, cost scales with input length, so sending 200K tokens per query is expensive. Second, models struggle to find specific information in very long contexts (the "lost in the middle" effect). RAG retrieves only the relevant chunks, keeping costs low and accuracy high.
Do I need a vector database, or can I use my existing PostgreSQL?
If you use PostgreSQL (including Supabase), install the pgvector extension and you have a vector database. No separate service needed. This is the recommended approach for most startups. Dedicated vector databases like Pinecone become worthwhile only at large scale (millions of documents) or when you need specialized features.

Ready to build real-world apps?

Join the McTaba Labs full-stack marathon (4 months full-time · 6 months part-time). Learn M-Pesa, USSD, and WhatsApp engineering while shipping 8 production apps.

Apply to the McTaba Marathon