How LLM Evals Actually Work — Ragas, Langfuse & DeepEval
Summary
This video explains the critical need for robust evaluation frameworks like traces, evaluations, and test cases for AI agents, especially in enterprise-level applications. It contrasts deterministic software with probabilistic AI systems, highlighting why traditional unit testing fails for LLM-based agents. The explanation covers key concepts like RAG, MCP, state management, and the importance of logging (traces), performance measurement (evaluations), and validation (test cases). It details metrics for generation and retrieval, introduces libraries like Langfuse, Ragas, and DeepEval, and discusses offline vs. online evaluation methods, ultimately aiming to improve AI agent reliability, accuracy, and cost-effectiveness.
Key Insights
Deterministic software has one correct answer, unlike probabilistic AI.
Traditional software has a single, deterministic answer (e.g., a=b, a>b). AI systems, particularly LLM-based ones, are probabilistic and can produce varied outputs for the same input.
Evaluation techniques include deterministic, LLM-as-a-judge, and human-in-the-loop.
Three main evaluation techniques are deterministic (like traditional assertions), LLM-as-a-judge (using an LLM to score outputs), and human-in-the-loop (human review and approval).
Faithfulness measures how well the answer is grounded in the provided context.
Faithfulness assesses if the generated answer contains claims that are factually supported by the retrieved context; a low score indicates hallucination.
Golden datasets are crucial for evaluating AI agent performance.
Creating a golden dataset with input (questions) and expected output (e.g., Terraform code) allows for systematic evaluation and comparison of agent-generated results.
Sections
Introduction to AI Agent Evaluation
Video covers Traces, Evaualtions, and Test Cases for AI agents.
The video aims to explain Traces, Evaualtions, and Test Cases for AI agents, answering what they are, when to use them, and why they are important.
AI agents leverage LLMs, tools, and RAG for complex tasks.
AI agents, often containing LLMs, take inputs and produce outputs utilizing tools and Retrieval Augmented Generation (RAG). RAG involves vector databases for embedding storage, retrieval, augmentation, and generation.
MCP (Model Communication Protocol) has primitives for agent interaction.
The system includes an MCP client and server with three primitives: tools, resources, and prompts, which are crucial for agent functionality.
State management and progressive discovery are key agent components.
State is stored for various parts of the agent's process, including responses from RAG. Progressive discovery is applied in MCP tools to enhance functionality.
Traces capture logs, evaluations assess performance, and test cases validate functionality.
All system logs are stored in traces. Evaluations use metrics to assess how outputs perform, and test cases are applied before and during production.
Deterministic software has one correct answer, unlike probabilistic AI.
Traditional software has a single, deterministic answer (e.g., a=b, a>b). AI systems, particularly LLM-based ones, are probabilistic and can produce varied outputs for the same input.
Probabilistic nature of AI makes traditional assertions impossible.
The probabilistic output of LLMs means standard assertions used in deterministic software testing (like a=b) are not feasible, making assertions dangerous and impossible to guarantee consistency every time.
Evaluating complex AI agent systems is critical due to cost and complexity.
Evaluating agent systems is crucial because LLMs have token-based costs. The complexity arises from interconnected agents, data flow between them, and ensuring outputs align with business logic.
AI reliability is paramount for enterprise-level solutions.
Understanding traces, evaluations, and test cases is critical for building better enterprise-level AI agents, especially concerning cost and consistent performance.
Why Traditional Testing Fails for AI
Deterministic software is defined by right/wrong answers.
Deterministic software, like traditional code, has a defined set of algorithms and a single correct answer.
Probabilistic AI systems can yield multiple valid answers.
Probabilistic AI systems, unlike deterministic software, can have multiple correct ways to answer a question, rendering traditional unit tests insufficient.
LLM outputs are inherently probabilistic and unpredictable.
LLMs produce probabilistic outputs influenced by prompts, system configurations, and internal mechanisms like attention and embeddings, making exact match assertions impossible.
Evaluation Frameworks and Libraries
Major libraries for AI evaluation include Langfuse, Ragas, and DeepEval.
Langfuse is primarily for traces, Ragas provides an evaluation framework with matrices, and DeepEval is for building test cases for agent systems.
Evaluation involves understanding input, output, and tool utilization.
The evaluation process considers inputs, outputs, the use of tools, RAG for retrieval, and the overall system architecture including MCP clients and servers.
RAG evaluation focuses on retrieval and context quality.
Ragas evaluates RAG performance through matrices like Context Precision, Context Recall, Faithfulness, and Answer Relevancy.
Langfuse focuses on tracing and observability of agent execution.
Langfuse logs the execution of agents, including LLM calls, tool calls, and retrieval processes, providing insights into what happened at each step.
DeepEval is used for building comprehensive test cases for AI systems.
DeepEval assists in creating test cases for AI agent systems, enabling validation through various metrics and assertions, both offline and online.
RAG involves retrieval, augmentation, and generation stages.
The RAG process includes retrieval (using hybrid, semantic, or lexical search), augmentation (feeding retrieved context to the LLM), and generation of the final answer.
Traces provide a record of execution, while observations detail specific events.
Traces capture the entire execution flow, while observations detail specific events within that flow, like LLM calls or tool interactions.
Evaluation metrics quantify system performance and quality.
Metrics like Faithfulness, Context Precision, Context Recall, and Answer Relevancy are used to score the performance of AI systems.
Evaluation techniques include deterministic, LLM-as-a-judge, and human-in-the-loop.
Three main evaluation techniques are deterministic (like traditional assertions), LLM-as-a-judge (using an LLM to score outputs), and human-in-the-loop (human review and approval).
Evaluation frameworks cover generation, retrieval, agent, and production levels.
Evaluation is structured across generation (faithfulness, correctness), retrieval (context precision, recall), agent (tool calls, task completion), and production (latency, cost, error rate).
RAG Evaluation Metrics and Challenges
Faithfulness measures how well the answer is grounded in the provided context.
Faithfulness assesses if the generated answer contains claims that are factually supported by the retrieved context; a low score indicates hallucination.
Context Precision measures the relevance of retrieved chunks to the query.
Context Precision calculates the ratio of relevant retrieved chunks to the total number of retrieved chunks, focusing on ranking quality.
Context Recall measures the completeness of retrieved information related to the query.
Context Recall assesses how much of the necessary information from the source documents was retrieved, focusing on coverage.
Answer Relevancy measures if the final answer addresses the user's question.
Answer Relevancy checks if the generated answer is pertinent to the original user query, generated by comparing the answer to a rephrased question.
RAG failures include hallucination, retrieval misses, and irrelevant retrieval.
Common RAG failures are hallucination (generating false information), retrieval misses (failing to find relevant documents), and irrelevant retrieval (returning unrelated documents).
Context Precision relates to ranking usefulness of retrieved chunks.
Context Precision focuses on whether useful chunks are ranked highly, indicating the quality of the retrieval and ranking process.
Context Recall relates to retrieving sufficient information (coverage).
Context Recall focuses on ensuring enough relevant information is retrieved to adequately answer the query.
Faithfulness checks factual accuracy of generated claims against context.
Faithfulness evaluates each claim in the generated answer against the retrieved context to ensure accuracy and prevent fabrication.
Answer Relevancy ensures the final output directly addresses the user's query.
Answer Relevancy is calculated by generating a question from the answer and comparing it to the original query to measure relevance.
Langfuse for Traces and Observability
Langfuse provides detailed traces of agent execution flows.
Langfuse captures logs and execution details for LLM calls, tool interactions, and retrieval processes within an AI agent, aiding in debugging and analysis.
Traces record entire agent runs, while observations detail specific steps.
A trace represents a complete run of an agent or pipeline, while an observation is a specific event within that trace, like an LLM call or tool execution.
Langfuse traces include detailed breakdowns of LLM, retrieval, and tool calls.
The anatomy of traces in Langfuse includes detailed logs for LLM calls, retrieval steps (like vector search parameters), tool calls, and prompt/response data.
Tracing helps identify failures and optimize agent performance.
By analyzing traces, developers can pinpoint failures, such as incorrect document retrieval or low faithfulness scores, and subsequently fix and improve the agent.
DeepEval for Test Cases and Regression
DeepEval helps create test cases and perform regression testing for AI agents.
DeepEval enables the creation of LLM test cases with assertions similar to traditional unit tests, facilitating regression testing and ensuring changes don't break functionality.
Golden datasets are crucial for evaluating AI agent performance.
Creating a golden dataset with input (questions) and expected output (e.g., Terraform code) allows for systematic evaluation and comparison of agent-generated results.
Offline and online evaluations are used to test agents.
Offline evaluation uses predefined datasets (golden datasets) for testing, while online evaluation involves real user interactions and feedback in a live environment.
CI/CD pipelines integrate traces, evaluations, and test cases for automated validation.
Combining Langfuse (traces), Ragas (evaluations), and DeepEval (test cases) within CI/CD pipelines allows for automated testing, scoring, and deployment decisions.
Production-Level Evaluation
Production evaluation focuses on latency, cost, error rates, and user feedback.
Key metrics for production systems include latency (response time), token/cost usage, error rates, and subjective user feedback, which inform prompt and system updates.
Data drift and concept drift require continuous re-evaluation and dataset updates.
Changes in user query patterns (data drift) or underlying concepts (concept drift) necessitate updating golden datasets and re-evaluating agent performance.
Ask a Question
*Uses 1 Wisdom coin from your coin balance










