Dwarves
Memo
Type ESC to close search bar

Evaluation guidelines for LLM applications

Overview

Evaluation is a hard part of building an RAG system, especially for application-integrated LLM solving your business problem. This guide outlines a clear, step-by-step approach to effectively evaluating and optimizing the integration of a third-party Large Language Model (LLM) into your application. By following these articles, you’ll make sure the model fits your business goals and technical needs.

Evaluation checklist

The evaluation checklist helps make sure that all important parts of the LLM are reviewed during integration. Each checklist item should address a key part of the system or model to confirm it meets technical, business, and user needs.

By providing a structured way to assess the system’s performance, the checklist helps we ensure that the model meets both technical and business needs while delivering a positive user experience. For additional insights, you can refer to the following articles: LLM product development checklist and Understanding LLM user experience expectations.

Product evaluation checklist

In case RAG system:

graph TD
    A[Retrieval system] --> B[Search engine]
    B --> C[Metric precision, recall]
    C --> F[How to test: Compare retrieved docs]
    B --> D[Task-specific search]
    D --> G[How to measure: Check relevant sections for task]

    A --> H[Retrieval efficiency]
    H --> I[Latency]
    I --> J[How to measure: Time from query to retrieved document]
    H --> K[Scalability]
    K --> L[How to measure: Stress testing with multiple users]

    A --> M[Response generation]
    M --> N[LLM as a judge]
    N --> P[Evaluation with library evaluation]

    M --> R[Human-in-the-loop]
    R --> S[User satisfaction]
    S --> T[How to measure: Human feedback on relevance and usefulness]
    R --> U[Edge cases]
    U --> V[How to test: Humans handle specific complex cases]

    A --> W[Cost efficiency]
    W --> X[Token usage per query]
    X --> Y[How to measure: Track token usage in API calls]

In case of fine-tuning model:

graph TD
    J[Fine-tuning model]
    J --> K[Apply fine-tuning on task-specific data]
    K --> L[How to measure: Monitor loss, accuracy during fine-tuning]

    J --> M[Post-fine-tuning]
    M --> N[Evaluate performance post-fine-tuning]
    N --> O[How to test: Compare pre and post model performance]
    M --> P[Prevent overfitting and bias]
    P --> Q[How to measure: Track validation vs. training performance]

    M --> R[Optimize model]
    R --> S[How to measure: Monitor inference speed and token]
    M --> T[Task-specific accuracy and generalization]
    T --> U[How to measure: Analysis feedback user]

Business and user expectation

This section is all about putting users first! It helps us understand what users need and ensures they get quick, personalized responses. By matching the assistant’s replies to what users really want, we create a satisfying experience for everyone.

graph TD
  A[User expected]
  A --> B[Understand user needs]
  B --> D[Match assistant responses to user want]

  A --> E[Happy case]
  E --> J[Quick responses]
  E --> M[Personalize responses based on conversation]

Here, we focus on our goals as a business. This part guides us in making sure our system runs smoothly, stays affordable, and meets user needs effectively. By keeping an eye on performance and costs, we can deliver a reliable and efficient service that users want.

graph TD
  A[Business goal]

  A --> B[User expectations]
  B --> C[Understand user needs]
  C --> D[Match responses to user intent]
  B --> E[Improve user satisfaction]
  E --> F[Personalize interactions]
  E --> G[Provide fast responses]

  A --> H[Technical adoption]
  H --> I[Optimize performance]
  I --> J[Monitor latency and throughput]
  I --> K[Ensure low error rates]
  H --> L[Cost efficiency]
  L --> N[Control API and infrastructure costs]

The type of evaluation

Model evaluations

Let’s look at the key metrics for calculates accuracy of search engine.

MetricDescriptionExample
PrecisionHow many of the documents you retrieved are actually relevant.If you retrieved 10 documents and 8 were relevant, your precision is 80%.
RecallHow many of the relevant documents were actually retrieved.If there were 20 relevant documents total and you retrieved 15, your recall is 75%.
F1 scoreA balance between precision and recall, giving you a single accuracy score.With a precision of 80% and recall of 75%, your F1 score would be around 77%.
Hit rateThe percentage of searches that returned at least one relevant document.If users made 100 searches and found relevant info in 85, your hit rate is 85%.
Top-K accuracyHow many relevant documents are in the top K results returned.If your system returns 10 documents and 7 of them are relevant, your top-10 accuracy is 70%.
Mean average precision (MAP)The average precision for several queries, taking into account the order of results.If you had 5 different queries, you could average their precisions to get MAP.
Mean reciprocal rank (MRR)The average position where the first relevant document shows up in the results.If relevant docs appear at positions 1, 3, and 5 across multiple searches, MRR would reflect the average of those positions.
Normalized discounted cumulative gain (NDCG)Measures how useful the ranked results are, considering their positions.If your top result is highly relevant and the second is less so, NDCG will reflect that importance.

LLMs can act as reliable judges for evaluating outputs quickly. Below is a list of common metrics used for evaluation.

MetricWhat it checksWhen to useExample
CorrectnessEnsures the output is factually accurate based on the information provided.Use when verifying that responses are grounded in correct information or facts.Checking if the answer to “Who is the current president of the US?” returns the correct name.
Answer relevancyDetermines if the response is directly related to the user’s query.Use when you need to evaluate whether the response is aligned with the question asked.Ensuring that a question about weather forecasts gives weather-related responses.
FaithfulnessVerifies whether the output stays true to the source material without hallucinating or adding incorrect info.Use when you need to guarantee that a summary or paraphrase accurately reflects the original content.Checking if a model’s summary of an article stays true to the key points without adding extra information.
CoherenceChecks whether the response logically flows and makes sense as a whole.Use for long-form answers where the response needs to be consistent and easy to follow.Reviewing if a multi-sentence response explaining a technical concept is coherent and logical.
Contextual recallMeasures how well the response retrieves all relevant information from the context provided.Use when evaluating the completeness of information retrieval tasks.Ensuring that a model answers all aspects of a multi-part question based on the context provided.
Contextual relevancyEnsures the response uses the given context to directly address the user’s query.Use when it’s critical for the response to be specifically tied to the context or previous conversation.Checking if a chatbot follows up correctly on a previous conversation about booking a flight.
Contextual precisionMeasures the relevance and precision of the retrieved information from the context.Use when the response must be highly accurate and precise based on the context.Evaluating if a model picks the most relevant part of a conversation to respond to a follow-up query.
BiasDetects whether the response shows signs of prejudice or unfair bias in its content.Use when ensuring fairness, especially in sensitive or controversial topics.Checking if a model-generated description of a profession avoids gender or racial bias.
ToxicityIdentifies if the response contains harmful, offensive, or inappropriate language.Use when generating public-facing content where safety and neutrality are priorities.Evaluating a chatbot response to ensure it avoids offensive or inflammatory language.

Tools to define and evaluate these metrics

Product evaluations

Defining baselines, targets, and acceptable ranges for our RAG system metrics helps us stay on track and reach our goals. These benchmarks guide improvements and adapt to changes, ensuring we deliver the best experience for users while adding value to our organization.

MetricBaselineTargetAcceptable range
Accuracy85% correct responses90% correct responses85% – 95%
Latency700ms per query400ms per query300ms – 500ms
Throughput100 queries/second150 queries/second120 – 200 queries/second
Cost per query$0.01/query$0.008/query$0.007 – $0.012/query
Context window size4,096 tokens8,192 tokens6,000 – 10,000 tokens
Error rate3% failure rate1% failure rate0.5% – 2%

Tools for tracing and monitoring

Considerations

Coverage and monitoring

To keep your LLM application running smoothly, you’ll want to:

Use analytics and user feedback

Need fine-tuning model

RAG systems are fantastic for retrieving information, but they sometimes miss the mark when it comes to understanding the finer details of specific tasks. Fine-tuning serves as a solution to this challenge by adapting pre-trained models to specific datasets to apply specific tasks.

  1. Deeper understanding of context: Fine-tuning allows a model to learn the ins and outs of specific tasks, making it better at understanding details that are important for accurate responses
  2. Fewer errors in specific scenarios: By focusing on task-related examples, fine-tuning reduces the chances of mistakes, allowing the model to perform reliably—especially in complex or unique requests.
  3. Handling edge cases: Fine-tuning prepares the model to tackle unusual or rare scenarios better, ensuring it can provide the right answers when faced with unexpected questions.

Assume how the model’s performance changes before and after fine-tuning:

MetricBefore fine-tuningAfter fine-tuningChange
Task-specific accuracy75%90%+15%
Error rate5%2%–3%
Edge case handling70%85%+15%
Search precision80%95%+15%

Summary

This guide provides a simple, step-by-step approach to evaluating and optimizing your RAG system, ensuring it meets your business goals and user needs. With handy checklists and tools, you’ll effectively assess model performance and improve user experience!

Reference


Next: AI-as-a-judge