Skip to content

Judges API

evret.judges.base

Base interface for relevance judges.

Judge

Bases: ABC

Base interface for relevance judges.

All judges implement a simple contract: - judge(context) → bool (is relevant?) - batch_judge(contexts) → list[bool] (batch evaluation)

Subclasses should override judge() and optionally batch_judge() for optimized batch processing.

name abstractmethod property

Judge display name for logging/debugging.

batch_judge(contexts)

Batch evaluation of multiple contexts.

Default implementation calls judge() for each context sequentially. Override this method for optimized batch processing (e.g., vectorized operations, async API calls, etc.).

Parameters:

Name Type Description Default
contexts list[JudgmentContext]

List of judgment contexts

required

Returns:

Type Description
list[bool]

List of boolean judgments (same order as input)

judge(context) abstractmethod

Return True if retrieved_text is relevant to expected_text given query.

Parameters:

Name Type Description Default
context JudgmentContext

Judgment context with query and texts

required

Returns:

Type Description
bool

True if retrieved text is relevant, False otherwise

JudgmentContext dataclass

Context passed to judge for relevance decision.

Attributes:

Name Type Description
query str

User query text

expected_text str

Expected/ground-truth relevant text

retrieved_text str

Retrieved candidate text to judge

evret.judges.token_overlap

Token overlap judge for keyword-based relevance matching.

TokenOverlapJudge

Bases: Judge

Fast keyword/token-based relevance matching.

Suitable for exact/fuzzy text matching without semantic understanding. Uses weighted token overlap with configurable thresholds to determine relevance.

Algorithm
  1. Try exact match
  2. Try substring containment
  3. Remove common stopwords
  4. Score weighted token overlap
  5. Add small phrase and query overlap bonuses
  6. Penalize negation mismatches

Examples:

>>> judge = TokenOverlapJudge()  # Default settings
>>> judge = TokenOverlapJudge(min_tokens=50, overlap_ratio=0.7)
>>> judge = TokenOverlapJudge(min_tokens=15, overlap_ratio=0.6, query_boost=False)

Parameters:

Name Type Description Default
min_tokens int

Minimum shared tokens required (default: 15, suitable for RAG chunks)

15
overlap_ratio float

Minimum overlap ratio 0-1 (default: 0.6)

0.6
query_boost bool

Allow query tokens to relax threshold (default: True)

True
stopwords Iterable[str] | None

Tokens ignored during overlap scoring

None

name property

Judge display name.

__init__(min_tokens=15, overlap_ratio=0.6, query_boost=True, stopwords=None)

Initialize token overlap judge with configurable thresholds.

judge(context)

Judge using token overlap algorithm.

Parameters:

Name Type Description Default
context JudgmentContext

Judgment context with query and texts

required

Returns:

Type Description
bool

True if retrieved text matches expected text

score(context)

Return a relevance score in the range [0, 1].

evret.judges.semantic

Semantic similarity judge using sentence embeddings.

SemanticJudge

Bases: Judge

Embedding-based semantic similarity matching.

Uses sentence-transformers to compute dense embeddings and cosine similarity for relevance judgment. More accurate than token overlap but requires additional dependencies and computation.

Examples:

>>> judge = SemanticJudge()  # Default model
>>> judge = SemanticJudge(model="all-MiniLM-L6-v2", threshold=0.8)
>>> judge = SemanticJudge(threshold=0.7, device="cuda")

Parameters:

Name Type Description Default
model str

HuggingFace model name (default: sentence-transformers/all-MiniLM-L6-v2)

'sentence-transformers/all-MiniLM-L6-v2'
threshold float

Cosine similarity threshold 0-1 (default: 0.75)

0.75
device str

Device for computation: "cpu" or "cuda" (default: "cpu")

'cpu'
Requires

pip install sentence-transformers

name property

Judge display name.

__init__(model='sentence-transformers/all-MiniLM-L6-v2', threshold=0.75, device='cpu')

Initialize semantic judge with embedding model.

batch_judge(contexts)

Optimized batch evaluation using vectorized embeddings.

Parameters:

Name Type Description Default
contexts list[JudgmentContext]

List of judgment contexts

required

Returns:

Type Description
list[bool]

List of boolean judgments

judge(context)

Judge using embedding cosine similarity.

Parameters:

Name Type Description Default
context JudgmentContext

Judgment context with query and texts

required

Returns:

Type Description
bool

True if cosine similarity >= threshold

evret.judges.llm.base

LLM-powered semantic relevance judge.

LLMJudge

Bases: Judge

LLM-powered semantic relevance judgment.

Uses GPT/Claude/other LLMs to determine if retrieved text matches expected content semantically. Most accurate but slowest judge option.

Examples:

>>> judge = LLMJudge(provider="openai")  # Uses OPENAI_API_KEY env
>>> judge = LLMJudge(provider="openai", api_key="sk-...")
>>> judge = LLMJudge(provider="anthropic", model="claude-3-5-sonnet-20241022")
>>> judge = LLMJudge(provider="google", model="gemini-3.5-flash-lite")

Parameters:

Name Type Description Default
provider str

LLM provider ("openai", "anthropic", or "google")

'openai'
model str | None

Model name (uses provider default if None)

None
api_key str | None

API key (reads from env if None)

None
temperature float

Sampling temperature (default: 0.0 for deterministic)

0.0
max_retries int

Max retry attempts for failed API calls

3
Requires

pip install openai # for OpenAI pip install anthropic # for Anthropic pip install google-genai # for Google Gen AI

name property

Judge display name.

__init__(provider='openai', model=None, api_key=None, temperature=0.0, max_retries=3)

Initialize LLM judge with specified provider.

ajudge(context) async

Async judge using LLM.

Parameters:

Name Type Description Default
context JudgmentContext

Judgment context

required

Returns:

Type Description
bool

Boolean relevance judgment

batch_judge(contexts)

Batch evaluation with concurrent async API calls.

Parameters:

Name Type Description Default
contexts list[JudgmentContext]

List of judgment contexts

required

Returns:

Type Description
list[bool]

List of boolean judgments

judge(context)

Judge using LLM prompt.

Parameters:

Name Type Description Default
context JudgmentContext

Judgment context with query and texts

required

Returns:

Type Description
bool

True if LLM determines texts are semantically relevant

evret.judges.trulens

LLM-as-a-judge relevance judge backed by TruLens feedback functions.

TruLensJudge

Bases: Judge

Relevance judgment using a TruLens feedback function.

Scores the query against the retrieved text with a TruLens provider's feedback function (default: context_relevance) and thresholds the resulting 0.0-1.0 score to a boolean so it plugs into the evaluator. Use :meth:score directly when you want the raw graded score.

Only feedback functions that take two strings and return a 0.0-1.0 score map onto :class:JudgmentContext: context_relevance and relevance. Groundedness and answer-relevance against a generated response are not exposed because :class:JudgmentContext has no generated-answer field.

Note: unlike the other judges, TruLens feedback functions score query against retrieved_text directly and ignore expected_text.

Examples:

>>> judge = TruLensJudge()  # OpenAI provider, context_relevance
>>> judge = TruLensJudge(provider="openai", model="gpt-6-luna")
>>> judge = TruLensJudge(provider="litellm", model="claude-3-5-sonnet-latest")
>>> judge = TruLensJudge(metric="relevance", threshold=0.6)

Parameters:

Name Type Description Default
provider str

TruLens provider ("openai" or "litellm"). LiteLLM routes to Anthropic, Gemini, Cohere, Mistral, Ollama, and more via its model string (e.g. "claude-3-5-sonnet-latest", "gemini/gemini-3.5-flash-lite").

'openai'
model str | None

Model engine name (uses the provider default if None). Required in practice for the litellm provider.

None
metric str

Feedback function to use (one of SUPPORTED_METRICS, default "context_relevance").

'context_relevance'
threshold float

Score cutoff in [0, 1]; scores >= threshold judge as relevant (default: 0.5).

0.5
provider_kwargs dict | None

Extra keyword arguments forwarded to the TruLens provider constructor (e.g. api_base for a local LiteLLM model).

None
Requires

pip install trulens-providers-openai # for provider="openai" pip install trulens-providers-litellm # for provider="litellm"

name property

Judge display name.

__init__(provider='openai', model=None, metric='context_relevance', threshold=0.5, provider_kwargs=None)

Initialize the TruLens-backed judge.

judge(context)

Judge relevance by thresholding the TruLens feedback score.

Parameters:

Name Type Description Default
context JudgmentContext

Judgment context with query and texts

required

Returns:

Type Description
bool

True if the feedback score >= threshold

score(context)

Return the raw TruLens feedback score in [0, 1].

The feedback function scores context.query against context.retrieved_text; context.expected_text is not used.

Parameters:

Name Type Description Default
context JudgmentContext

Judgment context with query and texts

required

Returns:

Type Description
float

Graded relevance score in [0.0, 1.0]