Zero Labs
Industry News / AI

RAG From Zero: The Skill That’s Getting Freshers Hired in AI Right Now

Source · Towards AI By Addepallenikhilvarma

From the publisher’s feed, collected in the ZeroLabs newsroom.

Imagine hiring the smartest person you’ve ever met. They’ve read millions of books, can write code, explain complex topics, and answer almost anything. But here’s the catch — they haven’t learned anything new since 2023, and they know absolutely nothing about you, your company, or your work.That’s ChatGPT. That’s every LLM you’ve ever used. And that’s exactly the problem RAG was built to solve.I’m not going to throw equations at you. This is a ground-up explanation of one of the most important techniques in AI right now — with a real example, five minutes of reading, and working code you can run today.The Problem — Why LLMs Lie to YouLet me paint a picture.You build a chatbot for your company using ChatGPT or Claude. Customers start asking questions. “What’s your refund policy?” “How do I reset my password?” “What’s included in the Pro plan?”The AI answers confidently. But half the answers are wrong — or generic — because the model has never seen your company’s actual documentation. It’s just guessing based on patterns from its training data.This is the core problem: LLMs are frozen in time.They were trained on data up to a certain date. They know nothing about your internal docs, your product updates, or anything that happened after their training cutoff. And when they don’t know something? They don’t say “I don’t know.” They make something up. That’s hallucination — and it’s a real problem in production systems.So what do we do? We could fine-tune the model on our data. But that’s expensive, slow, and you’d have to redo it every time your docs change. There had to be a better way. There is. It’s called RAG.What is RAG, Actually?RAG stands for Retrieval-Augmented Generation.I know, the name sounds intimidating. But break it down word by word and it’s almost obvious:Retrieval — go find relevant information from somewhereAugmented — add that information into the promptGeneration — now let the LLM answer using what it just foundThat’s it. You’re not changing the model. You’re not retraining anything. You’re just giving the model the right context before it answers.The best analogy I’ve come across: imagine an open-book exam vs a closed-book one. A standard LLM is doing a closed-book exam — it can only use what it memorized during training. RAG turns it into an open-book exam — before answering, it gets to flip to the relevant page first.Same brain. Better answers.How RAG Solves the ProblemHere’s a concrete example. Say a user types:“What’s the return policy?”Without RAG, the LLM searches its memory, finds nothing specific to your company, and either makes something up or gives a generic answer.With RAG, here’s what actually happens behind the scenes:The user’s question gets converted into a vector (a numerical representation of its meaning)That vector is used to search your document database for the most relevant chunksThe top matching chunks — say, your actual return policy page — get pulled outThe LLM receives the original question plus those retrieved chunks as contextIt now answers based on your real documentationThe answer is accurate. Traceable. And it updates automatically whenever you update your docs — no retraining needed.It’s a genuinely elegant solution once you see it in action.Types of RAG — From Simple to AdvancedNot all RAG systems are built the same. As I dug deeper, I realized there’s actually a whole spectrum here. Here’s a quick breakdown:1. Naive RAGThis is the standard, baseline version of RAG. It splits your documents into small pieces, turns them into numbers (vectors), and stores them in a database. When you ask a question, it finds the most similar pieces of text and sends them to the AI to help it answer. It is the easiest to set up but can struggle with very complex questions.2. Recursive RAG (Parent-Document Retrieval)Instead of just looking at tiny snippets, this version looks at small “child” chunks to find the right topic but then pulls in a larger “parent” document for context. This ensures the AI doesn’t lose the “big picture” or surrounding details while answering. It solves the problem of small chunks being too narrow to understand. It is widely used in production for better accuracy.3. Query Transformation RAGThis type improves the process by rewriting the user’s question before searching. If a question is vague or poorly worded, the system generates better versions (Multi-Query) or breaks a hard question into smaller ones. This ensures the search finds the best possible information even if the user didn’t ask “perfectly.” It is the go-to method for handling messy or complex user inputs.4. Agentic RAGThis is the most advanced version, where the AI acts like a researcher with a “reasoning” loop. It can decide whether it needs to search more, which specific database to use, or even if the results it found are good enough to answer. It doesn’t just search once; it can go back and try again if it’s confused. This is becoming the industry standard for high-level AI assistants.If you’re just starting out, don’t worry about the last three. Get Naive RAG working first. Everything else is optimization.Build Your First RAG — Simple Python CodeOkay, enough theory. Let’s build something in practicalInstall dependencies:pip install -U langchain-huggingface langchain-chroma langchain-google-genai langchain-text-splittersThe full code:import osfrom langchain_huggingface import HuggingFaceEmbeddingsfrom langchain_chroma import Chromafrom langchain_core.documents import Documentfrom langchain_text_splitters import RecursiveCharacterTextSplitterfrom langchain_google_genai import ChatGoogleGenerativeAI# Step 1: Securely set your Gemini API Key# In a real app, use environment variables for securityos.environ["GOOGLE_API_KEY"] = "YOUR_GEMINI_API_KEY"# Step 2: Your Local Knowledge Base# This simulates your private data (could be PDFs or SQL data later)raw_data = [ "Refund Policy: Items can be returned within 30 days with a receipt.", "Technical Support: Available 24/7 via the 'Help' button in the dashboard.", "Pricing: Basic is $10/mo, Pro is $30/mo, and Enterprise is custom.", "Security: To reset your password, visit Settings > Security > Reset."]# Step 3: Chunking & Embedding# We use Recursive splitting to keep sentences togethertext_splitter = RecursiveCharacterTextSplitter(chunk_size=250, chunk_overlap=25)docs = [Document(page_content=text) for text in raw_data]chunks = text_splitter.split_documents(docs)# Use a free, local model to turn text into numbers (vectors)embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")# Store in a local vector database (Chroma)vectorstore = Chroma.from_documents(chunks, embeddings)print("Knowledge base is indexed and ready!")# Step 4: Setup the Gemini LLM# We use 'gemini-1.5-flash' for high speed and low latencyllm = ChatGoogleGenerativeAI(model="gemini-1.5-flash", temperature=0)# Step 5: The RAG Workflowdef ask_gemini(question): # A. Retrieval: Find the most relevant pieces of information relevant_docs = vectorstore.similarity_search(question, k=2) context_text = "\n".join([doc.page_content for doc in relevant_docs]) # B. Augmentation: Create a prompt that combines context + question prompt = f"""You are a helpful support assistant. Use the Context below to answer the user's Question. If the answer isn't in the context, say 'I am sorry, I don't have that information.' Context: {context_text} Question: {question} Answer:""" # C. Generation: Let Gemini generate the final answer response = llm.invoke(prompt) print(f"\n--- Result ---") print(f"Question: {question}") print(f"AI Response: {response.content}")# Test the systemask_gemini("What is your return policy?")ask_gemini("How do I get technical support?")What you’ll see:Knowledge base is indexed and ready!--- Result ---Question: What is your return policy?AI Response: Items can be returned within 30 days with a receipt.--- Result ---Question: How do I get technical support?AI Response: Technical support is available 24/7 via the 'Help' button in the dashboard.The retrieval is working. The right chunk got pulled out for the right question. From here, you’d just pass that prompt to any LLM and get a grounded answer.Where to Go From HereOnce RAG clicks, you’ll start seeing it everywhere. Almost every serious LLM application in production is using some form of it. Here’s a rough path if you want to go deeper:RAG Basics → Vector DBs (Pinecone, ChromaDB) → LangChain / LlamaIndex → Advanced RAG (re-ranking, hybrid search) → Agentic RAG → ProductionDon’t rush the path. Build one small project at each stage — a personal docs chatbot, a company FAQ bot, a research assistant. That’s how it sticks.→ If this helped you, share it with someone starting their AI journey — it might be the article that finally makes things click for them. And if you want a deep dive into advanced RAG, hit the like button and I’ll know you’re ready for more.RAG From Zero: The Skill That’s Getting Freshers Hired in AI Right Now was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.