Skip to content

Evaluating quality

A RAG search can look right on the questions you try and fail on the ones your visitors ask. The evaluation module lets you keep a reviewed set of questions, run it against a profile, and compare runs before and after a change.

Enable it with drush en drupal_rag_toolkit_evaluation and grant Administer Drupal RAG evaluation sets. Sets live at /admin/config/services/drupal-rag/evaluation-sets.

Write a set

A set is a JSON list of cases. Each case is one question and what a good result looks like:

[
  {
    "case_id": "renew-business-license",
    "question": "How do I renew my business license?",
    "expected_terminal_states": ["evidence", "grounded"],
    "expected_node_ids": [4396],
    "alternative_node_ids": [4401, 4410],
    "forbidden_node_ids": [12],
    "maximum_total_ms": 5000
  }
]
Field Meaning
case_id A unique lowercase identifier.
question The question, written the way a visitor would ask it.
expected_terminal_states The acceptable outcomes: grounded, evidence, no_grounded_answer or unavailable.
expected_node_ids Nodes that should be among the sources.
alternative_node_ids Other nodes that also answer the question. Finding one counts as finding an expected node.
forbidden_node_ids Nodes that must never be shown for this question, such as restricted content.
maximum_total_ms The slowest acceptable response.

Node IDs are converted to UUIDs when the set is saved, so a set can be exported and imported on another copy of the site.

Saving creates a new revision. Only an active revision can be run.

What makes a useful set

  • Real questions. Take them from search logs or support requests when you can. Questions you write yourself tend to repeat the page's own wording, which makes retrieval look better than it is.
  • Two styles. Include short, specific questions and longer, chatty ones ("my landlord hasn't fixed the heat and it's January, what can I do?"). They fail differently.
  • Out-of-scope questions. Add questions your content does not answer, with no_grounded_answer as the expected outcome. They show whether the search admits it does not know.
  • Alternatives. Large sites often have several pages that answer the same question. List them as alternatives so a correct answer is not counted as a miss.
  • Enough cases. A few dozen show large problems; around 200 let you see a change of a few percent.

Run a set

Select Run this active set and choose a profile. A run records, for each question, the outcome, the sources returned and the timings. It keeps no answer text, passages or prompts.

Select Judge answers to also generate each answer and have a judge model rate it:

  • Faithfulness: is every statement supported by the passages the answer was written from?
  • Relevance: does the answer address the question?

Judging takes several minutes and uses both the profile's generation model and the judge model. Use a capable judge that differs from the generation model.

Read the results

Metric What it tells you
Expected source recall The share of expected sources found. Low recall means retrieval or reranking is missing the right pages.
Forbidden source violations Any count above zero is a problem to fix before anything else.
Terminal-state failures Questions whose outcome was not one of the acceptable ones, such as an answer to an out-of-scope question.
Latency-budget failures Questions slower than their maximum_total_ms.
Answer faithfulness Below 1.0 means some answers state things the sources do not.
Answer relevance Low relevance with good recall usually means the answer instruction or summary length needs work.

Questions that logged warnings, such as a reranking fallback, are flagged.

Compare runs

Change one thing at a time: the purpose, the minimum rerank score, the number of results, the answer instruction. Run the same set and compare. Comparisons are direct only when both runs used the same set revision and the same index.

For reference, on a 5,000-page public-services site with 198 questions, the maintainers' latest run had 0.97 expected source recall, answer faithfulness of 1.0 and answer relevance of 0.97. At that size, alternatives mattered: many apparent misses had cited an equally good copy of the expected page.

Export and import

Export reviewed JSONL writes the set to one file. Import always creates a draft, and every node must exist on the receiving site.