Overview
The Document Relevance evaluator determines whether a retrieved document contains information relevant to answering a specific question. This is essential for evaluating RAG (Retrieval-Augmented Generation) systems where document quality directly impacts response quality.When to Use
Use the Document Relevance evaluator when you need to:- Evaluate RAG retrieval quality - Assess whether your retrieval system is returning useful documents
- Debug poor RAG responses - Identify if issues stem from retrieval vs generation
- Compare retrieval strategies - Test different embedding models, chunking strategies, or search algorithms
- Monitor retrieval in production - Track document relevance over time
This evaluator assesses individual document relevance to a query. For evaluating whether a response is faithful to its context, use the Faithfulness evaluator instead.
Supported Levels
The level of an evaluator determines the scope of the evaluation in OpenTelemetry terms. Some evaluations are applicable to individual spans, some to full traces or sessions, and some are applicable at multiple levels.
Relevant span kinds: Retriever spans, embedding spans, or any span that retrieves documents from a knowledge base.
Input Requirements
The Document Relevance evaluator requires two inputs:In TypeScript, the field is named
documentText (camelCase) instead of document_text (snake_case).Formatting Tips
For best results:- Evaluate one document at a time - Run the evaluator separately for each retrieved document
- Use the full document chunk - Include the complete text that was retrieved, not just snippets
- Include metadata if helpful - Document titles or sources can provide useful context
Output Interpretation
The evaluator returns aScore object with the following properties:
Interpretation:
- Relevant (1.0): The document contains information that can help answer the question
- Unrelated (0.0): The document does not contain relevant information for the question
Usage Examples
- Python
- TypeScript
Evaluating Multiple Documents
To evaluate all documents returned by a retriever, iterate over each document:- Python
- TypeScript
Using Input Mapping
When your data has different field names, use input mapping.- Python
- TypeScript
Configuration
For LLM client configuration options, see Configuring the LLM.Viewing and Modifying the Prompt
You can view the latest versions of our prompt templates on GitHub. The evaluators are designed to work well in a variety of contexts, but we highly recommend modifying the prompt to be more specific to your use case. Feel free to adapt them.- Python
- TypeScript
Using with Phoenix
Evaluating Traces
Run evaluations on traces collected in Phoenix and log results as annotations:Running Experiments
Use the Document Relevance evaluator in Phoenix experiments:API Reference
- Python: DocumentRelevanceEvaluator
- TypeScript: createDocumentRelevanceEvaluator
Related
- Faithfulness Evaluator - For evaluating response faithfulness to context
- Correctness Evaluator - For evaluating overall correctness

