Large language models can explain Kubernetes, write Python code, summarize legal documents, and occasionally suggest restarting the server as though nobody had considered it.
However, ask a general-purpose AI model a question such as:
"What is our production deployment process for the order-processing service?"
and it has a problem.
The model has probably never seen your deployment guide, architecture documents, internal wiki, incident reports, or the message your lead posted six months ago saying, "Please do not deploy this service on Fridays."
This is where Retrieval-Augmented Generation, commonly called RAG, becomes useful.
RAG allows an AI application to search your information before generating an answer. Instead of relying entirely on what the model learned during training, it retrieves relevant content from an external knowledge source and uses that content to answer the question.
In simple terms, RAG turns an AI model from a confident guesser into something closer to an employee who checks the documentation first.
What problem does RAG solve?
A large language model has several limitations.
First, it does not automatically know your private data. Internal policies, project documentation, customer manuals, application logs, and company-specific processes were not part of its training data.
Second, its knowledge may be outdated. A model may understand Kubernetes deployments in general, but it will not know that your team moved from Jenkins to GitHub Actions last month.
Third, a model may generate an answer even when it does not have enough information. This behaviour is often described as hallucination. The answer may sound reasonable, use perfect grammar, and still be completely wrong—which is an impressive but unhelpful combination.
RAG addresses these problems by providing relevant information at the time the question is asked.
Consider an internal engineering assistant.
A developer asks:
"How do I deploy the payment service to production?"
Without RAG, the model may produce a generic deployment checklist.
With RAG, the application can search the company's approved deployment guide, retrieve the section related to the payment service, and provide an answer based on the actual process.
The model is not expected to remember the deployment procedure. It is expected to read it.
What is RAG?
RAG stands for Retrieval-Augmented Generation.
The name describes the two main steps.
Retrieval
The application searches an external knowledge source and finds information related to the user's question.
The source might contain:
- Internal documentation
- Product manuals
- Support articles
- Source-code documentation
- Policies and procedures
- Research reports
- Contracts
- Knowledge-base articles
Generation
The retrieved information is added to the prompt sent to the language model. The model then generates an answer using that context.
The basic flow looks like this:
User question
↓
Search the knowledge base
↓
Retrieve relevant information
↓
Send the question and information to the LLM
↓
Generate an answerRAG does not retrain the language model. It supplies additional information at runtime.
A useful analogy is an open-book exam. The model still needs to understand the question and construct the answer, but it is allowed to consult the correct material first.
Of course, giving someone an open book does not guarantee a correct answer. They must still find the correct page. That is why retrieval quality matters.
How does a RAG system work?
A typical RAG system has two separate workflows:
- Preparing and indexing the documents
- Answering user questions
1. Preparing the knowledge base
Before users can search the documents, the application must process them.
Documents
↓
Extract text
↓
Clean the content
↓
Split it into smaller chunks
↓
Create embeddings
↓
Store them in a searchable indexDocument loading
Documents may come from PDFs, Word files, websites, databases, Git repositories, support systems, or internal wikis.
The system extracts the useful text and removes unnecessary content such as repeated headers, page numbers, navigation menus, and formatting noise.
This step is more important than it appears. If the source content is messy, the retrieval results will also be messy. RAG follows the same timeless rule as most software systems: bad data enters, bad data leaves—usually with better formatting.
Chunking
Large documents are divided into smaller sections called chunks.
For example, a 60-page operations manual should not be stored as one large block. It may be divided by headings, paragraphs, or logical sections such as:
- Deployment prerequisites
- Configuration
- Rollback procedure
- Troubleshooting
- Emergency contacts
Chunking helps the system retrieve only the parts related to the user's question.
Chunks should be large enough to preserve meaning but small enough to avoid unrelated information. A chunk containing one incomplete sentence is rarely useful. A chunk containing half the company wiki is not much better.
Embeddings
Each chunk is converted into an embedding.
An embedding is a numerical representation of the meaning of text. It allows the system to compare text based on semantic similarity rather than only exact keywords.
For example, consider these questions:
- "How do I release the application?"
- "What is the production deployment process?"
The wording is different, but the meaning is similar. Their embeddings should therefore be close to each other.
This makes semantic search more flexible than traditional keyword search.
Storage
The embeddings, original text, and metadata are stored in a searchable system.
Metadata may include:
{
"document": "Production Deployment Guide",
"service": "payment-api",
"section": "Rollback",
"version": "4.1",
"updated_at": "2026-06-10"
}Metadata helps the system filter results. For example, it can search only documents related to a particular service, department, country, product, or access group.
The data may be stored in a dedicated vector database, a search engine with vector-search support, or a relational database with a vector extension.
The product matters, but not as much as the design. Installing a vector database does not automatically create a good RAG system, just as installing PostgreSQL does not automatically create a good application.
2. Answering a question
When a user asks a question, the application performs a second workflow.
Question
↓
Create question embedding
↓
Search for similar chunks
↓
Select the top-k most relevant results
↓
Build a prompt
↓
Generate the answerThe number of chunks the system keeps is usually called top-k. A small k risks missing the answer; a large k buries it under unrelated text. Choosing k is one of the first things a real system has to tune.
Suppose the user asks:
"What should I do if the payment worker is OOMKilled?"
The system converts the question into an embedding and searches the stored document chunks.
It may retrieve:
- A Kubernetes troubleshooting guide
- The payment worker's resource configuration
- A previous incident report involving memory usage
Those chunks are added to the prompt:
Answer the question using only the supplied context.
Context:
- The payment worker has a memory limit of 2 GiB.
- OOMKilled events should be investigated using pod events and memory metrics.
- Do not increase the memory limit before checking batch size and unbounded collections.
Question:
What should I do if the payment worker is OOMKilled?The model can then produce a grounded answer:
Check the pod events and memory metrics first. Review the worker's batch size and any unbounded in-memory collections before changing the current 2 GiB memory limit.
The answer comes from the retrieved documentation rather than from the model's general assumptions.
A real-life example: an engineering knowledge assistant
Imagine a company with several microservices written in Python, Ruby, and JavaScript.
Its technical knowledge is spread across:
- Architecture documents
- README files
- Jira tickets
- API specifications
- Kubernetes runbooks
- Incident reports
- Coding standards
Developers repeatedly ask questions such as:
- Which service owns the product catalog?
- How do I run the order service locally?
- What is the rollback procedure for the checkout service?
- Which coding standard should a new Python service follow?
- Why was the orders database index changed last year?
A RAG-based assistant could index the approved technical documentation and retrieve the relevant sections when these questions are asked.
For example:
Developer question
↓
Search architecture docs and runbooks
↓
Retrieve service ownership and deployment sections
↓
Generate an answer with document referencesA good answer might include:
The product catalog is owned by the catalog service. According to the "Product Catalog Architecture" document, it stores approved product records in PostgreSQL and publishes catalog updates that the order service reads when a customer places an order.
It could also display the source document and section used.
This is more useful than an answer that begins with, "In a typical microservice architecture..." That sentence usually means the model is about to explain somebody else's system.
Where RAG is useful
RAG works well when answers must come from a specific body of knowledge.
Internal company assistants
RAG can search:
- HR policies
- Engineering standards
- Operational runbooks
- Security procedures
- Onboarding documentation
Employees can ask natural-language questions without manually searching several systems.
Customer support
A support assistant can retrieve information from:
- Product manuals
- Troubleshooting guides
- Warranty policies
- Resolved support cases
For example, when a customer reports that a device will not connect to Wi-Fi, the assistant can retrieve the exact troubleshooting steps for that model.
Software development
RAG can help developers work with large codebases by retrieving:
- Architecture decisions
- Module documentation
- API contracts
- Coding conventions
- Migration guides
It is particularly useful when the correct answer depends on project-specific rules rather than general programming knowledge.
Regulated and high-stakes domains
The same pattern extends to legal, compliance, and healthcare work — searching contracts, regulations, clinical guidelines, or internal protocols and summarizing the relevant clause or section. A user might ask, "Which section of this contract explains data-retention responsibilities?" and get the exact clause back.
What changes in these domains is the stakes, not the mechanism. They demand strict access controls, traceable sources, and expert review. In high-risk settings RAG should support a professional's decision, not quietly replace it — and an AI-generated interpretation should not become policy simply because it uses bullet points.
E-commerce and product discovery
RAG can search descriptions, specifications, manuals, and compatibility information, so a customer can ask, "Which laptop supports two external 4K monitors and has at least 32 GB of memory?" and get a grounded comparison rather than a generic recommendation.
When should you use RAG?
RAG is a strong option when:
- The information is private or organization-specific
- The knowledge changes regularly
- The content is too large to include directly in every prompt
- Answers must be based on approved documents
- Users need source references
- The same knowledge base will support many questions
- Updating the information should not require retraining a model
A useful decision question is:
Does the answer depend on finding information that is outside the model's built-in knowledge?
When the answer is yes, RAG may be appropriate.
When should you not use RAG?
RAG is not required for every AI feature.
Simple generation tasks
You do not need RAG to:
- Rewrite an email
- Correct grammar
- Generate a generic unit-test template
- Summarize text already included in the prompt
There is no benefit in searching a knowledge base when all the necessary information is already available.
Exact calculations
Suppose a user asks:
"How many orders failed today?"
This is not primarily a document-retrieval problem. The application should query the operational database, analytics platform, or monitoring API.
RAG is designed mainly for retrieving unstructured knowledge. It should not replace an exact SQL query with a semantically similar guess.
Live system state
Questions about current pod status, payment transactions, available inventory, or today's exchange rate should use APIs or tools connected to the live system.
RAG may explain how inventory is calculated, but an inventory API should provide the current quantity.
Small amounts of context
When the application uses one short document that fits comfortably in the model's prompt, a separate retrieval pipeline may add unnecessary complexity.
Sometimes the best vector database is no vector database.
RAG versus fine-tuning
RAG and fine-tuning solve different problems.
RAG provides knowledge. It retrieves information at runtime and places it in the prompt.
Fine-tuning changes behaviour. It teaches a model to follow particular patterns, styles, formats, or specialised tasks.
For example:
- Use RAG to answer questions from updated company policies.
- Use fine-tuning to make a model consistently produce a specialised output format.
Fine-tuning is usually not the best method for frequently changing facts. If a policy changes every month, retraining the model each month is inefficient. Updating the RAG knowledge base is simpler.
In some applications, both approaches can be combined.
RAG versus tool calling
RAG retrieves information from documents and other unstructured sources.
Tools connect the model to structured systems and actions.
For example, an operations assistant may:
- Use RAG to retrieve the documented incident procedure
- Use a Kubernetes tool to check pod status
- Use a logging tool to retrieve recent errors
- Generate a response combining the documentation and current system state
RAG tells the assistant what should normally be done. Tools tell it what is happening now.
Does RAG eliminate hallucinations?
No.
RAG can reduce unsupported answers, but several things can still go wrong:
- The correct document was not indexed
- The document was split badly
- The search retrieved irrelevant content
- An outdated document ranked higher
- The prompt contained too much context
- The model misunderstood the retrieved text
- Conflicting documents were retrieved
A reliable RAG system should instruct the model to say when the available context is insufficient.
For example:
"The available documentation does not contain enough information to answer this question."
That response may not look impressive in a product demonstration, but it is far better than inventing a production rollback procedure.
Common RAG misconceptions
"RAG is just a vector database"
A vector database may be one component, but RAG also includes document processing, chunking, retrieval, metadata, prompt construction, access control, evaluation, and monitoring.
"More context produces better answers"
Too much context can reduce answer quality. The relevant information may become buried under unrelated text.
The objective is not to retrieve the maximum number of chunks. It is to retrieve the right chunks.
"Semantic search is always enough"
Semantic search is useful for meaning-based questions, but exact keyword search is often better for error codes, product identifiers, API paths, class names, and configuration keys.
Production systems commonly combine semantic and keyword search.
"RAG guarantees correct answers"
RAG gives the model evidence. It does not guarantee that the evidence is correct, current, complete, or interpreted properly.
The system must still be tested.
Final takeaway
RAG allows an AI application to use external knowledge without placing every document inside every prompt or retraining the model whenever information changes.
The core idea is straightforward:
Find the right information first.
Generate the answer second.A successful RAG system is not defined by how many AI frameworks it uses. It is defined by whether it consistently retrieves trustworthy information and produces answers supported by that information.
The language model may be the most visible part of the application, but retrieval does much of the serious work.
As usual in software engineering, the component receiving the most attention is not necessarily the one preventing production incidents.