---
title: RetrievalSufficiency judge | Databricks on AWS
source: https://docs.databricks.com/aws/en/mlflow3/genai/eval-monitor/concepts/judges/is_context_sufficient
ingestedAt: "2026-06-18T08:14:58.030Z"
---

    from mlflow.genai.scorers import RetrievalSufficiencyfrom mlflow.entities import Documentfrom typing import List# Define a retriever function with proper span type@mlflow.trace(span_type="RETRIEVER")def retrieve_docs(query: str) -> List[Document]:    # Simulated retrieval - some queries return insufficient context    if "capital of france" in query.lower():        return [            Document(                id="doc_1",                page_content="Paris is the capital of France.",                metadata={"source": "geography.txt"}            ),            Document(                id="doc_2",                page_content="France is a country in Western Europe.",                metadata={"source": "countries.txt"}            )        ]    elif "mlflow components" in query.lower():        # Incomplete retrieval - missing some components        return [            Document(                id="doc_3",                page_content="MLflow has multiple components including Tracing and Evaluation.",                metadata={"source": "mlflow_intro.txt"}            )        ]    else:        return [            Document(                id="doc_4",                page_content="General information about data science.",                metadata={"source": "ds_basics.txt"}            )        ]# Define your RAG app@mlflow.tracedef rag_app(query: str):    # Retrieve documents    docs = retrieve_docs(query)    context = "\n".join([doc.page_content for doc in docs])    # Generate response    messages = [        {"role": "system", "content": f"Answer based on this context: {context}"},        {"role": "user", "content": query}    ]    response = client.chat.completions.create(        # This example uses Databricks hosted Claude.  If you provide your own OpenAI credentials, replace with a valid OpenAI model e.g., gpt-4o, etc.        model=model_name,        messages=messages    )    return {"response": response.choices[0].message.content}# Create evaluation dataset with ground trutheval_dataset = [    {        "inputs": {"query": "What is the capital of France?"},        "expectations": {            "expected_facts": ["Paris is the capital of France."]        }    },    {        "inputs": {"query": "What are all the MLflow components?"},        "expectations": {            "expected_facts": [                "MLflow has main components",                "Components include Tracing",                "Components include Evaluation",                "Components include Prompt Engineering",                "Components include Model Registry"            ]        }    }]# Run evaluation with RetrievalSufficiency scorereval_results = mlflow.genai.evaluate(    data=eval_dataset,    predict_fn=rag_app,    scorers=[        RetrievalSufficiency(            model="databricks:/databricks-gpt-oss-120b",  # Optional. Defaults to custom Databricks model.        )    ])
