The Memory of LLMs: How the RAG Pattern Works with Vector Databases
Picture this scene: Your company wants a new chatbot. "Customers ask about our products, get instant answers." Sounds good, you say. You hook up the GPT API, build a nice UI,…
In this article↗
A Familiar Scenario
Picture this scene:
Your company wants a new chatbot.
"Customers ask about our products, get instant answers."
Sounds good, you say. You hook up the GPT API, build a nice UI, deploy it.
First question comes in:
"How much is the X model?"
GPT responds:
"Unfortunately, I don't have access to current pricing information, but generally these types of products range between $50-200..."
Customer's gone.
Second question:
"When will my order arrive?"
GPT:
"Typically, e-commerce shipments are delivered within 2-5 business days..."
That one's gone too.
What's the problem? GPT doesn't know your products, your prices, your shipping policy. And it can't — because this data wasn't in its training set.
Fundamental Limitations of LLMs
Large language models are incredibly capable tools. They write code, generate articles, translate languages. But like any technology, they have limitations. Understanding these limitations is essential to grasp why RAG is so valuable.
Knowledge Cutoff
Every LLM is trained on data up to a certain date. The model is completely unaware of anything that happened after that date.
You: "What's the inflation rate in the US in 2025?"
GPT: "I don't have access to current data. My training data
only goes up to April 2024..."This isn't just about "current news" — it applies to things critical to your business:
- Your company's price list updated yesterday
- A new product added last week
- Shipping policy changed this morning
- API documentation published yesterday
The model knows none of this. It can't — because this data didn't exist during training.
Hallucination
The most dangerous feature of LLMs: they confidently make up things they don't know.
You: "What's your company's return policy?"
GPT: "You can return products within 30 days. Simply bring
your receipt to our nearest store. The refund process
takes 3-5 business days."Sounds perfectly reasonable, right? But it's completely fabricated. Your company's return policy might be 14 days, online only, or maybe you don't accept returns at all. The model doesn't know, so it generates something that "sounds plausible."
This is a disaster for customer service. A chatbot giving wrong information loses customers and can cause legal issues.
No Private Data Access
LLMs are trained on public internet data. Your:
- Internal company documents
- Product database
- Customer information
- Internal procedures
- Meeting notes
- Confluence/Notion pages
None of these are in the model's training data. When asked about them, the model either says "I don't know" (best case) or makes things up (worst case).
Comparison Table
| Limitation | What Happens | Example | Risk Level |
|---|---|---|---|
| Knowledge Cutoff | No current info | "What's the dollar rate?" | Medium |
| Hallucination | States false info as fact | "Your return policy..." | High |
| No Private Data | Doesn't know company data | "Is product X in stock?" | High |
Two Solutions
There are two main approaches to overcome these limitations:
Fine-tuning: You retrain the model with your own data. The model now "knows" your information.
Advantages:
- Model truly learns the information
- No additional cost during inference
- More consistent responses
Disadvantages:
- Expensive (GPU costs in thousands of dollars)
- Slow (days, weeks)
- Requires retraining for every data update
- Requires technical expertise
- Hallucination still possibleRAG (Retrieval Augmented Generation): You don't train the model — you provide relevant information with each query.
Advantages:
- Cheap (only API + vector DB costs)
- Fast (setup in minutes)
- Easy data updates (just update the index)
- Can cite sources
- Reduced hallucination (context provided)
Disadvantages:
- Retrieval cost on each request
- Retrieval quality is critical
- Context window limitationsFor most use cases, RAG is more practical and cost-effective. Consider fine-tuning when:
- You need a very specific language/tone
- Retrieval latency is unacceptable
- Data rarely changes
What is RAG? (Simple Explanation)
RAG can be explained most simply like this:
Fine-tuning = Memorizing everything for an exam RAG = Open-book exam
The model doesn't need to "know" everything. When a question comes, it just needs to find and read the relevant information.
The RAG Cycle
┌────────────────────────────────────────────────────────────┐
│ │
│ 1. RETRIEVE │
│ ┌──────────────┐ ┌──────────────────┐ │
│ │ User Query │ ───► │ Vector Database │ │
│ │ "How much is │ │ ┌──────────────┐ │ │
│ │ product X?" │ │ │ Similarity │ │ │
│ └──────────────┘ │ │ Search │ │ │
│ │ └──────────────┘ │ │
│ └────────┬─────────┘ │
│ │ │
│ ▼ │
│ 2. AUGMENT ┌──────────────┐ │
│ │ Related Docs │ │
│ ┌─────────────────────────┤ "Product X: │ │
│ │ │ $99.99, │ │
│ │ │ in stock" │ │
│ │ └──────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────┐ │
│ │ Enriched Prompt: │ │
│ │ "Answer based on this info: │ │
│ │ [Product X: $99.99, in stock, ...] │ │
│ │ Question: How much is product X?" │ │
│ └─────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ 3. GENERATE │
│ ┌──────────────┐ ┌──────────────────┐ │
│ │ LLM │ ───► │ "Product X costs │ │
│ │ (GPT-4) │ │ $99.99 and is │ │
│ │ │ │ currently in │ │
│ └──────────────┘ │ stock." │ │
│ └──────────────────┘ │
│ │
└────────────────────────────────────────────────────────────┘Step-by-Step Explanation
Step 1 - Retrieve: The user asks a question. This question is searched in the vector database. But not a classic "keyword" search — semantic search. This means "how much" can match "price: $99.99" even without the word "price."
Step 2 - Augment: Found relevant documents/chunks are combined with the user's question. The prompt to be sent to the LLM is enriched.
Step 3 - Generate: The LLM now has context. It has real information. Based on this information, it produces an accurate and consistent answer.
Concrete Example
You're building a product assistant for an e-commerce site:
# User question
user_query = "Can you recommend a winter jacket? My budget is around $200"
# Step 1: Find relevant products via vector search
relevant_products = vector_db.search(user_query, top_k=5)
# Found products:
# - "Men's Winter Parka - $189 - Waterproof, -20°C rated"
# - "Unisex Puffer Jacket - $169 - Lightweight, warm"
# - "Women's Long Coat - $219 - Wool blend"
# Step 2: Enrich the prompt
augmented_prompt = f"""
Help the customer based on these product details:
{relevant_products}
Customer question: {user_query}
Rules:
- Only recommend from the given products
- Mention products that exceed the budget
- Be friendly and helpful
"""
# Step 3: Get response from LLM
response = llm.generate(augmented_prompt)
# Output:
# "Great news - you have some excellent options within your $200
# budget! Here are my recommendations:
#
# 1. Men's Winter Parka ($189) - Waterproof and rated for -20°C.
# Perfect for harsh winters and within your budget.
#
# 2. Unisex Puffer Jacket ($169) - If you prefer something lighter,
# this is ideal. Warm yet allows freedom of movement.
#
# The Women's Long Coat is beautiful but at $219, it's slightly
# over your budget. Let me know if you'd like to consider it anyway."The model knows the product info, prices, and features because you told it. No making things up, no hallucination.
✨Conclusion
LLMs are powerful on their own, but they are not enough for real-world production systems. They lack access to up-to-date information, private company data, and business-specific rules — leading to either incorrect answers or hallucinations.
Retrieval Augmented Generation (RAG) addresses this problem at its core.
Instead of retraining the model, it provides the right context at the right time, enabling:
- Access to current and private data
- More accurate and reliable responses
- Scalable, production-ready AI systems
If you want to move beyond demos and build AI features that actually work for real users, RAG is not optional — it’s a foundational architecture pattern.
