Evaluate Conversation Relevance
Evaluate whether chatbot responses stay relevant across a conversation using promptfoo's sliding-window conversation-relevance assertion.
Why it matters
Assess the relevance of conversational turns within a dialogue. This asset helps determine if responses are on-topic and contribute meaningfully to the overall conversation flow.
Outcomes
What it gets done
Classify individual conversation turns for relevance.
Summarize the relevance of a full conversation.
Evaluate the coherence of dialogue exchanges.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/pfoo-eval-conversation-relevance | bash Steps
Steps in the chain
Overview
Eval Conversation Relevance
Uses promptfoo's conversation-relevance assertion with a sliding window to score whether each chatbot response in a multi-turn conversation stays on-topic, including a case with a deliberately off-topic response. Use when evaluating whether a chatbot's responses stay relevant across a multi-turn conversation, with the threshold and window size tuned to the domain.
What it does
This example demonstrates promptfoo's conversation-relevance assertion, which evaluates whether each response in a conversation stays relevant to the context and prior messages, using a sliding-window approach. It includes four test cases: a single-turn evaluation of relevance for a query-response pair about travel to Paris, a multi-turn travel-planning conversation where every response should be relevant, a wedding-planning conversation containing one deliberately off-topic response about the stock market to demonstrate detection of an irrelevant reply in the middle of an otherwise-relevant conversation, and a high-quality technical support conversation scored with a 0.95 threshold. Configuration options include threshold (minimum passing score, 0-1), config.windowSize (messages per sliding window, default 5), and an overridable grading provider. Scoring works by evaluating the last assistant response in each window for relevance; for a 5-message conversation with window size 3, Window 1 covers message 1 only, Window 2 covers messages 1-2, Window 3 covers messages 1-3, Window 4 slides to messages 2-4, and Window 5 slides to messages 3-5 - each window scoring whether the last assistant response within it is relevant. The final score is the number of relevant windows divided by the total number of windows.
When to use - and when NOT to
Use this when evaluating a chatbot or conversational agent's tendency to stay on-topic across multiple turns. The example's own tips recommend lower thresholds (0.7-0.8) for general conversations and higher thresholds (0.9-0.95) for specialized domains like technical support, adjusting window size based on conversation complexity, and using a more capable grading model (e.g. GPT-4) for judging complex conversations.
Not needed for single-turn, stateless prompts with no conversational context to drift from.
Inputs and outputs
Requires OPENAI_API_KEY (or npm install -g promptfoo). Input is promptfooconfig.yaml with conversation-relevance assertions across the four test cases. Output is a normal promptfoo eval run, reporting a relevance score (the proportion of conversation windows deemed relevant), pass/fail against the threshold, and a reason when responses are found irrelevant.
Integrations
Uses an overridable grading provider (defaulting to OpenAI via OPENAI_API_KEY) to judge relevance per sliding window; more capable models are recommended for grading complex conversations.
Who it's for
Teams evaluating chatbots or multi-turn conversational agents that need to detect topic drift, with different relevance bars for general versus specialized domains. The provider config option lets teams override the default grading model entirely, which pairs with the tip to use a more capable model for judging complex, multi-topic conversations.
npx promptfoo@latest init --example eval-conversation-relevance
cd eval-conversation-relevance
Source README
eval-conversation-relevance (Conversation Relevance)
You can run this example with:
npx promptfoo@latest init --example eval-conversation-relevance
cd eval-conversation-relevance
This example demonstrates how to use the conversation-relevance assertion to evaluate whether chatbot responses remain relevant throughout a conversation.
What is Conversation Relevance?
The conversation relevance metric evaluates whether each response in a conversation is relevant to the context and previous messages. It uses a sliding window approach to analyze conversation segments.
Running the Example
Install dependencies:
npm install -g promptfooSet your OpenAI API key:
export OPENAI_API_KEY=your-api-keyRun the evaluation:
promptfoo eval
Example Test Cases
1. Single-turn Evaluation
Tests basic relevance for a single query-response pair about travel to Paris.
2. Multi-turn Travel Conversation
Evaluates a complete conversation about travel planning where all responses should be relevant.
3. Conversation with Irrelevant Response
Demonstrates detection of an off-topic response (stock market comment) in the middle of a conversation about wedding planning.
4. Technical Support Conversation
Shows a high-quality technical support conversation with a high relevance threshold (0.95).
Configuration Options
threshold: Minimum score required to pass (0-1)config.windowSize: Number of messages in each sliding window (default: 5)provider: Override the default grading model
Interpreting Results
- Score: Proportion of conversation windows deemed relevant
- Pass/Fail: Based on whether the score meets the threshold
- Reason: Explanation when responses are found irrelevant
Tips
- Use lower thresholds (0.7-0.8) for general conversations
- Use higher thresholds (0.9-0.95) for specialized domains like technical support
- Adjust window size based on conversation complexity
- Consider using more capable models (GPT-4) for grading complex conversations
How Scoring Works
The metric evaluates each message position using a sliding window approach. For example, with a 5-message conversation and window size of 3:
- Window 1: Message 1 only (evaluates if Response 1 is relevant)
- Window 2: Messages 1-2 (evaluates if Response 2 is relevant given context)
- Window 3: Messages 1-3 (evaluates if Response 3 is relevant given context)
- Window 4: Messages 2-4 (evaluates if Response 4 is relevant given context)
- Window 5: Messages 3-5 (evaluates if Response 5 is relevant given context)
Each window evaluates whether the LAST assistant response in that window is relevant. The final score is:
Score = Number of Relevant Windows / Total Number of Windows
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.