Skip to main content

Evaluation

Evaluation measures how good the answers of your application are: how often they are correct, based on the right sources and helpful, over many realistic inputs, ideally taken from real use. You evaluate when something changes that can affect the answers, for example a new model version, a new prompt or new content for retrieval, and you compare the results over time.

Testing or evaluation?​

Testing and evaluation answer different questions. Testing checks that your code works. Evaluation measures how good the answers are.

TestingEvaluation
QuestionDoes my code work?How good are the answers?
WhenWhile you develop and on every buildWhen something that affects the answers changes, and on data from real use
ModelMostly a mock, a real model in a few integration testsThe real model of your application
DataA few cases you writeMany realistic inputs, often from real use
ResultPass or fail for each behavior you checkScores and pass rates over many realistic inputs, compared over time
CostMostly fast and cheapSlower, and every model call costs money

Start with testing: it is useful from the first day of a project. Evaluation becomes important as your application gets closer to production and real users.

Repeated runs​

The same input can get a good answer in one run and a bad one in the next. So evaluate each input several times, and look at how often its answers are good:

  • Choose the required pass rate with a margin. The number of passes varies between runs even when nothing changed. An application that answers well 9 times out of 10 on average gets fewer than 9 good answers out of 10 in about one run out of four, and fewer than 8 in about one out of fourteen. Require fewer passes than you usually see, or run more times.
  • Small differences are usually chance. With few runs, a small difference between two pass rates says little. Run more times before you decide that a new model version, prompt or retrieval setup is better or worse.
  • Keep the runs independent. An AI Service with chat memory must start a new conversation in each run, for example with a new memory id.
  • Check the judge first. When a model judges the answers, run it on a few answers that you labelled yourself, including bad ones, and see whether it agrees with you.

Tools​

In a Quarkus application, Quarkus LangChain4j has its own evaluation support, which runs each input several times and reports the pass rates with a confidence interval: see Testing AI-Infused Applications.

The judges of the langchain4j-test module check an answer against criteria written in natural language. Judge.evaluate(...) returns their verdicts as values (JudgeResponse.verdicts()) instead of failing, so you can also use them to score answers. Judging an answer this way adds at least one request to the judge model for each answer, and evaluate(...) throws a JudgeException when the judge's answer cannot be understood.