How RAG works
RAG solves a fundamental problem with LLMs: a language model knows the world as of its training
cut-off and has no access to your specific catalogue, your prices or your stock. RAG adds a
retrieval step over a current knowledge base.
The request pipeline:
User request → Request embedding
↓
Vector search over the index (Top-K documents)
↓
LLM: [system prompt] + [retrieved documents] + [request]
↓
Answer to the user
All of it happens inside a single request latency — typically 500–2000 ms for the full cycle.
Components of a RAG system
Indexing (offline):
– Catalogue documents are split into chunks — structured fragments such as a product record, an
FAQ entry or a category description.
– Each chunk is converted into a vector by an embedding model.
– The vectors are stored in a vector database alongside their metadata (price, availability,
category).
Retrieval and generation (online, on every request):
– The user’s request is converted into a vector by the same model.
– The system finds the Top-K nearest vectors — usually 5–10 documents.
– Those documents plus the request are passed to the LLM as context.
– The LLM generates an answer grounded in the supplied data.
Important: the quality of RAG is set by the quality of the retrieval step. If the right
document never makes it into the Top-K, no LLM is powerful enough to give the right answer.
RAG in e-commerce
In retail, RAG addresses three jobs:
| Job | Without RAG | With RAG |
|---|---|---|
| “Do you have the iPhone 15 Pro 256 GB in stock?” | Hallucination, or “I don’t know” | Real availability checked against the catalogue |
| “Recommend a mattress for back pain” | Generic advice with no link to the assortment | Specific models with prices from the catalogue |
| “How does model A differ from model B?” | Specifications get mixed up | A comparison built from the real product records |
Limits and practical caveats
- Context size: only a limited number of documents fits into the prompt. On a large catalogue,
ranking quality at the retrieval step becomes critical. - Freshness: the knowledge base has to track catalogue changes — prices, availability — which
in e-commerce usually means in real time. - Handling an empty result: when retrieval finds nothing relevant, the model should say so
honestly rather than invent something similar.