Building a Retrieval-Augmented Generation (RAG) application is not just about connecting an LLM to a vector database.
A RAG application may successfully retrieve documents, generate a fluent response, and still provide incorrect or misleading information.
For enterprise applications, especially in banking, payments, insurance, and healthcare, a confident but unsupported answer can be more dangerous than no answer at all.
This is why RAG evaluation is a critical part of production AI engineering.
In this article, we will explore four important dimensions of RAG evaluation:
- Faithfulness
- Answer Relevance
- Retrieval Quality
- Grounding
We will also understand how to evaluate a RAG application using a practical fintech use case.
1. Why RAG Evaluation Matters
A typical RAG pipeline consists of the following steps:
- Receive a user query.
- Convert the query into an embedding.
- Retrieve relevant documents from a vector database.
- Build a prompt using the retrieved context.
- Send the prompt to an LLM.
- Generate the final answer.
The challenge is that every stage can introduce errors.
For example:
- The retriever may return irrelevant documents.
- The correct document may not be retrieved.
- The LLM may ignore the retrieved context.
- The generated answer may introduce unsupported facts.
- The answer may be technically correct but fail to address the user's question.
Traditional application testing cannot fully validate these behaviors.
We need a dedicated evaluation strategy.
2. Faithfulness: Is the Answer Supported by the Context?
Faithfulness measures whether the generated answer is supported by the retrieved context.
It helps identify hallucinations introduced by the LLM.
Example
User query:
"What is the maximum daily transfer limit for a premium banking customer?"
Retrieved context:
"Premium banking customers can transfer up to ₹5,00,000 per day through the mobile banking application."
Generated answer:
"Premium banking customers can transfer up to ₹5,00,000 per day through mobile banking."
This answer is faithful because it is supported by the retrieved context.
Now consider another answer:
"Premium banking customers can transfer up to ₹10,00,000 per day through mobile banking."
The answer sounds reasonable, but the retrieved context does not support the ₹10,00,000 limit.
This is a faithfulness failure.
How to evaluate faithfulness
A common approach is to:
- Extract factual claims from the generated answer.
- Check whether each claim is supported by the retrieved context.
- Calculate the proportion of supported claims.
A simplified formula:
Faithfulness = Supported Claims / Total Claims
For example, if an answer contains 5 factual claims and 4 are supported:
Faithfulness = 4 / 5 = 0.80
A score of 1.0 indicates that all evaluated claims are supported by the context.
However, faithfulness does not guarantee that the retrieved context itself is correct.
3. Answer Relevance: Does the Answer Address the Question?
Answer relevance measures how directly the generated answer responds to the user's query.
An answer can be factually correct and faithful but still irrelevant.
Example
User query:
"What is the daily transfer limit for premium customers?"
Generated answer:
"Premium banking customers receive personalized banking services, priority customer support, and access to exclusive financial products."
The answer may be factually correct, but it does not answer the transfer-limit question.
This is an answer relevance failure.
A good response should directly address the requested information:
"Premium customers can transfer up to ₹5,00,000 per day through mobile banking."
Important distinction
Faithfulness and relevance measure different things.
- Faithfulness: Is the answer supported by the context?
- Relevance: Does the answer address the user's question?
A response can score high on one and low on the other.
This distinction is particularly important when evaluating enterprise AI assistants.
4. Retrieval Quality: Did We Retrieve the Right Documents?
Retrieval quality evaluates the performance of the retriever before the LLM generates an answer.
Even a powerful LLM cannot reliably answer a question if the required information is missing from the retrieved context.
Consider a banking knowledge base containing:
- Customer onboarding policies
- Payment processing rules
- Transaction limits
- Fraud detection guidelines
- Loan eligibility criteria
A query about transaction limits should retrieve the correct transaction-limit policy, not a general banking document.
Precision@K
Precision@K measures how many of the top K retrieved documents are relevant.
Precision@K = Relevant Retrieved Documents / K
Suppose the retriever returns 5 documents, and 4 are relevant.
Precision@5 = 4 / 5 = 0.80
This tells us that 80% of the retrieved documents are relevant.
Recall@K
Recall@K measures how many of the known relevant documents were retrieved in the top K results.
Recall@K = Relevant Retrieved Documents Retrieved / Total Relevant Documents
Suppose there are 10 relevant documents in the evaluation dataset, and the retriever finds 7.
Recall@K = 7 / 10 = 0.70
This means the retriever found 70% of the relevant documents.
Why both metrics matter
High precision means the retrieved context contains fewer irrelevant documents.
High recall means the retriever is finding more of the information needed to answer the question.
For enterprise RAG systems, we often need to balance both.
Other useful retrieval metrics include:
- Mean Reciprocal Rank (MRR)
- Normalized Discounted Cumulative Gain (NDCG)
- Hit Rate@K
MRR evaluates how highly the first relevant result is ranked.
NDCG considers both relevance and ranking position, making it useful when highly relevant documents should appear near the top.
5. Grounding: Can We Trace the Answer to Reliable Sources?
Grounding evaluates whether the generated response is anchored in trustworthy evidence.
In a RAG application, grounding is more than retrieving a document.
The answer should be traceable to the correct source, such as:
- An approved banking policy
- An official product document
- A customer-specific record
- A regulatory guideline
- An authorized internal knowledge article
Example
User query:
"Can I reverse a completed payment?"
Generated answer:
"Completed payments cannot be directly reversed through the mobile application. Customers must raise a dispute through the approved support process."
A grounded response should reference the approved payment-reversal policy that supports this statement.
For enterprise applications, grounding should ideally include:
- Source document ID
- Document version
- Relevant page or section
- Retrieval timestamp
- Access-control validation
Grounding vs Faithfulness
These concepts are closely related but not identical.
Faithfulness asks:
"Does the answer follow the retrieved context?"
Grounding asks:
"Is the answer supported by reliable, traceable evidence?"
An answer could be faithful to an outdated policy document but still be incorrectly grounded in the current business context.
This is why document freshness, versioning, and source authority are important.
6. Putting the Metrics Together
Let's evaluate a hypothetical banking RAG application.
User query:
"What is the daily transfer limit for premium customers?"
Expected answer:
"Premium customers can transfer up to ₹5,00,000 per day through mobile banking."
Retrieved documents:
- Document 1: Premium customer transaction limits
- Document 2: Mobile banking security policy
- Document 3: General banking services
- Document 4: Premium customer benefits
Generated answer:
"Premium customers can transfer up to ₹5,00,000 per day through mobile banking. Transfers above this limit require additional authorization."
Evaluation:
| Metric | Result |
|---|---|
| Faithfulness | High, if both claims are supported |
| Answer Relevance | High |
| Retrieval Precision@4 | Depends on which documents are relevant |
| Retrieval Recall@4 | Depends on the known relevant document set |
| Grounding | High, if supported by current approved policies |
Notice that the second sentence about additional authorization must also be verified.
A correct first sentence does not automatically make the entire answer faithful.
7. Building a RAG Evaluation Dataset
A reliable evaluation process starts with a curated dataset.
For each test case, maintain:
- User query
- Expected answer
- Relevant document IDs
- Reference answer or key facts
- Retrieved context
- Generated answer
- Evaluation scores
Example test cases:
| Query | Expected behavior |
|---|---|
| What is the daily transfer limit? | Return the approved limit |
| How can I reverse a completed payment? | Explain the approved dispute process |
| What documents are required for KYC? | List required documents |
| What is the loan eligibility criteria? | Retrieve the correct loan policy |
| What is the current policy version? | Identify the latest approved version |
Include difficult cases such as ambiguous queries, missing information, conflicting documents, outdated policies, and questions that should not be answered.
A production-ready RAG system must also know when to say:
"I couldn't find sufficient information in the approved sources to answer this question."
8. Evaluating RAG in a Java Spring AI Application
For Java backend developers, RAG evaluation can be integrated into the application testing and CI/CD process.
A typical architecture:
A practical implementation can include:
- Spring AI for retrieval and model orchestration
- PostgreSQL with pgvector for vector search
- Amazon Bedrock for LLM inference
- JUnit for evaluation test execution
- A curated evaluation dataset stored as JSON or database records
- An evaluation framework such as RAGAS or custom LLM-as-a-judge logic
The evaluation pipeline can run during development and before production deployment.
Example workflow:
- Load the evaluation dataset.
- Execute each query against the RAG application.
- Capture retrieved documents and generated answers.
- Calculate retrieval metrics.
- Evaluate faithfulness and answer relevance.
- Validate source citations and grounding.
- Compare results against the previous model or prompt version.
- Fail the build if critical evaluation thresholds are not met.
For example, a banking application might define an internal release gate requiring high faithfulness and retrieval recall for critical policy queries.
The thresholds should be based on business risk, evaluation dataset quality, and observed production performance—not arbitrary universal values.
9. Production Considerations
RAG evaluation should not stop after development.
In production, monitor:
- Retrieval latency
- LLM response latency
- Token consumption
- Retrieval failure rate
- Unsupported answer rate
- User feedback
- Source document freshness
- Model and prompt version changes
For sensitive domains, also validate:
- User authorization before document retrieval
- PII protection
- Tenant-level data isolation
- Prompt injection resistance
- Audit logging
- Human escalation for high-risk decisions
Evaluation should be performed whenever there is a significant change to the embedding model, chunking strategy, vector database configuration, prompt, LLM, or source documents.
Conclusion
RAG evaluation is essential for building reliable enterprise AI applications.
The four dimensions provide complementary insights:
- Faithfulness checks whether the answer is supported by retrieved context.
- Answer Relevance checks whether the response addresses the user's question.
- Retrieval Quality checks whether the right documents were found.
- Grounding checks whether the answer is traceable to trustworthy evidence.
A production RAG system should not be evaluated only by how fluent or impressive its answers sound.
It should be evaluated by how accurately it retrieves information, how reliably it generates supported answers, and how safely it handles uncertainty.
For enterprise AI, the goal is not simply to generate answers.
The goal is to generate reliable, relevant, evidence-backed answers that can be trusted.
Author: Ram The Architect (RTA)
Follow me for more practical insights on Java 21 | Spring Boot | Microservices | Apache Kafka | AWS | System Design | GenAI
Github: https://github.com/Ramu-fsd/enterprise-banking-microservices
Linkedin: https://www.linkedin.com/in/ramuboya/
#Java #AI #RAG #MachineLearning




