Module 3 · Building Production AI Apps with RAG

Manish Garg
Manish Garg Associate of (ISC)² · RingSafe
Apr 25, 2026
4 min read
Read as

Last updated: April 29, 2026

APIs, vector databases, chunking strategies, agents — the moment AI goes from toy to production. Includes Slack-bot RAG architecture.

Most AI demos look impressive in a notebook and break instantly in production. This module is about the difference — APIs, retrieval, error handling, monitoring, and the architectural choices that determine whether your AI feature ships or stalls.

The architecture of a production AI app

A production AI app has 6 layers, every single one worth getting right:

  1. Ingest — pulls your private docs into the system. Files, Notion, Confluence, GitHub, customer tickets.
  2. Chunk — splits docs into pieces that fit in the LLM’s context. Strategy here makes or breaks RAG.
  3. Embed — converts each chunk to a vector via an embeddings API.
  4. Store — saves vectors + chunk metadata in a vector database.
  5. Retrieve — at query time, embed the user question, find top-K nearest chunks.
  6. Generate — pass retrieved chunks + question to the LLM, get an answer.

Every layer has failure modes. Most teams obsess over (6) and ignore (2)-(3) — which is why their RAG quality is mediocre.

Vector database — pick once, regret forever

Options as of Q2 2026:

Option Cost Best for
pgvector (PostgreSQL extension) Free (your DB) Most teams. Works at scale up to 10M vectors.
Qdrant Free OSS / paid cloud Higher-scale than pgvector, fast.
Pinecone ~$70+/mo managed If you don’t want to manage anything.
Weaviate Free OSS Hybrid search built-in.
Milvus Free OSS Very high scale (billions of vectors).

For 99% of Indian SaaS teams, pgvector is the right answer. You already have Postgres. Adding vectors is a one-line install.

Chunking — where RAG quality lives or dies

Naive default: split docs every 1000 characters. This is wrong because it splits sentences mid-thought. Better strategies:

  • Sentence-boundary chunking — split on sentence ends, target 200-500 tokens per chunk
  • Semantic chunking — split where embedding distance is highest (topic shifts)
  • Structure-aware — for code/docs, split on function or section boundaries
  • Overlap — include last 50 tokens of previous chunk in next chunk, so context isn’t lost at boundaries

Spend a week on chunking strategy and your RAG accuracy can double. This is the highest-leverage tuning knob in the entire stack.

Hybrid search — don’t ignore BM25

Pure embedding similarity misses exact-term matches. If a user asks “AWS S3 bucket policy SCP-OrganizationAccountAccessRole” — that’s keyword territory, not semantic. Production-grade RAG uses both:

  1. Sparse search (BM25 / Postgres full-text)
  2. Dense search (embedding similarity)
  3. Reciprocal-rank-fusion to merge results
  4. Reranker (Cohere Rerank, BGE) to re-score the top 20

Streaming — make the wait feel shorter

LLMs generate token-by-token. Streaming sends tokens to the user as they’re produced. Same total time, feels 5× faster:

for chunk in client.chat.completions.create(
    model="gpt-4o", messages=msgs, stream=True
):
    if chunk.choices[0].delta.content:
        yield chunk.choices[0].delta.content

Every production chat UI must stream. There’s no excuse not to.

Cost control — the production reality

  • Set hard dollar limits on API keys. OpenAI/Anthropic both support this. One bad prompt loop can spend ₹50K in an hour.
  • Log every call: prompt, tokens, cost, latency. ₹100/month on a logging DB is cheap insurance.
  • Alert on cost anomalies. 10× day-over-day spend = page someone.
  • Use prompt caching for static system prompts.
  • Use batch APIs (OpenAI Batch, Claude Message Batches) for offline tasks — 50% cheaper, 24-hour SLA.

Agents — when one prompt isn’t enough

An agent is an LLM in a loop. It can call tools, observe results, decide next action, repeat. Patterns:

  • ReAct — alternates Reason and Act steps
  • LangGraph — explicit state-machine agents
  • Multi-agent — multiple specialised agents collaborate (planner + executor + critic)

Don’t reach for agents until simpler patterns fail. They’re harder to debug and 5-10× more expensive than single-shot prompts.

Your project for Module 3

Build a RAG-powered Slack bot for RingSafe Academy’s content:

  1. Ingest all 145 module pages (HTML scraping or WP REST API)
  2. Chunk with sentence-boundary splitting + 50-token overlap
  3. Embed with OpenAI text-embedding-3-small
  4. Store in pgvector
  5. Build a Slack bot (Bolt SDK) that, when @mentioned, retrieves top-5 chunks and uses Claude/GPT-4o to answer
  6. Cite sources: every answer ends with a list of module URLs that informed it

Stretch goals: streaming responses, hybrid search (pgvector + Postgres FTS), cost dashboard.

Summary

  • Production AI = 6 layers; chunking and retrieval matter as much as the LLM.
  • pgvector is the default vector DB for most Indian SaaS teams.
  • Hybrid search (BM25 + embeddings) beats either alone.
  • Stream responses always. Set hard cost limits always.
  • Skip agents until simpler patterns fail.
🧠
Check your understanding

Module Quiz · 20 questions

Pass with 80%+ to mark this module complete. Unlimited retries. Each question shows an explanation.

Want this for your team?

Custom team training + practitioner advisory

Beyond the free academy — we run private workshops, vCISO advisory, and red-team exercises tailored to your stack. For Indian SMBs scaling past their first hire.

Book team training call Replies in 4 working hrs · India-only · Senior consultants