Retrieval quality
Compare answers using faithfulness, relevance, hallucination checks and configured principles. Quick mode uses one assessment per metric, standard adds critic/defender assessments, and thorough adds an independent judge. Live runs assess configured principles with domain-specific weights. Scores are judgments about supplied cases, not correctness guarantees.
Capabilities
| Capability | Kind | Signature | Module | Summary |
|---|---|---|---|---|
evaluate_metric | traversal | (metric: str, question: str, context: str, response: str, perspective: str = 'reviewer', principles: list[dict] | None = None) -> dict | examples/python/retrieval_quality/main.py | |
evaluate_rag_response | traversal | (question: str, context: str, response: str, mode: str = 'quick', domain: str = 'general', use_ml: bool = False) -> dict | examples/python/retrieval_quality/main.py |
Commands
ATFGRAPH_SERVER=http://127.0.0.1:18880 npm run dev -- --hostname 127.0.0.1
EXAMPLE_MODE=fixture python -m atfgraph.worker --module examples.python.retrieval_quality.main:app
atfg install ./examples/python/retrieval_quality
atfg run retrieval_quality
atfg server start
atfg traverse retrieval_quality.evaluate_rag_response --in '{"question": "When does the desk open?", "context": "The desk opens at 9am.", "response": "The desk opens at 9am.", "mode": "quick"}'
atfg traverse retrieval_quality.evaluate_rag_response --in '{"question":"When does the desk open?","context":"The desk opens at 9am.","response":"The desk opens at 9am.","mode":"quick"}'
docker build -f deploy/docker/Dockerfile.server -t atfgraph-vnext/graph-server:local .
docker compose -f examples/python/retrieval_quality/compose.yaml down
docker compose -f examples/python/retrieval_quality/compose.yaml up --build -d
python -m examples.python.retrieval_quality.call
Files
examples/python/retrieval_quality/Dockerfileexamples/python/retrieval_quality/Dockerfile.dockerignoreexamples/python/retrieval_quality/README.mdexamples/python/retrieval_quality/__init__.pyexamples/python/retrieval_quality/agentnode.yamlexamples/python/retrieval_quality/call.pyexamples/python/retrieval_quality/compose.yamlexamples/python/retrieval_quality/config/constitution.yamlexamples/python/retrieval_quality/config/presets/financial.yamlexamples/python/retrieval_quality/config/presets/legal.yamlexamples/python/retrieval_quality/config/presets/medical.yamlexamples/python/retrieval_quality/main.pyexamples/python/retrieval_quality/ml_services/__init__.pyexamples/python/retrieval_quality/ml_services/embeddings.pyexamples/python/retrieval_quality/ml_services/ner.pyexamples/python/retrieval_quality/ml_services/nli.pyexamples/python/retrieval_quality/node.pyexamples/python/retrieval_quality/requirements-ml.txtexamples/python/retrieval_quality/requirements.txtexamples/python/retrieval_quality/support.pyexamples/python/retrieval_quality/ui/Dockerfileexamples/python/retrieval_quality/ui/app/api/graph/[...path]/route.tsexamples/python/retrieval_quality/ui/app/globals.cssexamples/python/retrieval_quality/ui/app/layout.tsxexamples/python/retrieval_quality/ui/app/page.tsxexamples/python/retrieval_quality/ui/components/ClaimBreakdown.tsxexamples/python/retrieval_quality/ui/components/EvaluationForm.tsxexamples/python/retrieval_quality/ui/components/LoadingState.tsxexamples/python/retrieval_quality/ui/components/MarkdownContent.tsxexamples/python/retrieval_quality/ui/components/MetricCard.tsxexamples/python/retrieval_quality/ui/components/OverallScore.tsxexamples/python/retrieval_quality/ui/components/PoweredBy.tsxexamples/python/retrieval_quality/ui/components/eval/DashboardShell.tsxexamples/python/retrieval_quality/ui/components/eval/InputPanel.tsxexamples/python/retrieval_quality/ui/components/eval/ResultsPanel.tsxexamples/python/retrieval_quality/ui/components/ui/badge.tsxexamples/python/retrieval_quality/ui/components/ui/button.tsxexamples/python/retrieval_quality/ui/components/ui/card.tsxexamples/python/retrieval_quality/ui/components/ui/collapsible.tsxexamples/python/retrieval_quality/ui/components/ui/dropdown-menu.tsxexamples/python/retrieval_quality/ui/components/ui/input.tsxexamples/python/retrieval_quality/ui/components/ui/label.tsxexamples/python/retrieval_quality/ui/components/ui/popover.tsxexamples/python/retrieval_quality/ui/components/ui/progress.tsxexamples/python/retrieval_quality/ui/components/ui/scroll-area.tsxexamples/python/retrieval_quality/ui/components/ui/select.tsxexamples/python/retrieval_quality/ui/components/ui/separator.tsxexamples/python/retrieval_quality/ui/components/ui/tabs.tsxexamples/python/retrieval_quality/ui/components/ui/textarea.tsxexamples/python/retrieval_quality/ui/components.jsonexamples/python/retrieval_quality/ui/hooks/useEvaluation.tsexamples/python/retrieval_quality/ui/lib/api.tsexamples/python/retrieval_quality/ui/lib/presets.tsexamples/python/retrieval_quality/ui/lib/types.tsexamples/python/retrieval_quality/ui/lib/utils.tsexamples/python/retrieval_quality/ui/next.config.jsexamples/python/retrieval_quality/ui/package-lock.jsonexamples/python/retrieval_quality/ui/package.jsonexamples/python/retrieval_quality/ui/postcss.config.jsexamples/python/retrieval_quality/ui/public/atfgraph-icon-dark.svgexamples/python/retrieval_quality/ui/public/atfgraph-icon-light.svgexamples/python/retrieval_quality/ui/public/atfgraph-logo-dark.svgexamples/python/retrieval_quality/ui/public/atfgraph-logo-light.svgexamples/python/retrieval_quality/ui/scripts/smoke.pyexamples/python/retrieval_quality/ui/tailwind.config.tsexamples/python/retrieval_quality/ui/tsconfig.json
README
Compare answers using faithfulness, relevance, hallucination checks and configured principles. Quick mode uses one assessment per metric, standard adds critic/defender assessments, and thorough adds an independent judge. Live runs assess configured principles with domain-specific weights. Scores are judgments about supplied cases, not correctness guarantees.
Run locally
With the SDK installed, run from the repository root:
atfg server start
EXAMPLE_MODE=fixture python -m atfgraph.worker --module examples.python.retrieval_quality.main:app
# In a second terminal:
python -m examples.python.retrieval_quality.call
Or install and run the folder as a managed node package:
atfg install ./examples/python/retrieval_quality
atfg run retrieval_quality
A copied project also works through node.py. By default it uses http://127.0.0.1:18880; inspect its runs at /ui/.
Call with the CLI
atfg traverse retrieval_quality.evaluate_rag_response --in '{"question": "When does the desk open?", "context": "The desk opens at 9am.", "response": "The desk opens at 9am.", "mode": "quick"}'
Providers
Fixture mode uses deterministic local values with no external model/search calls. It checks the scoring workflow rather than model evaluator quality.
For live evaluations, set EXAMPLE_MODE=live and the worker's model URL/name/key before startup. Missing settings and provider errors fail explicitly rather than returning fixture judgments.
Python client
from atfgraph import Client
async with Client("http://127.0.0.1:18880") as client:
result = await client.traverse(
"retrieval_quality.evaluate_rag_response",
{'question': 'When does the desk open?', 'context': 'The desk opens at 9am.', 'response': 'The desk opens at 9am.', 'mode': 'quick'},
timeout=300,
)
print(result)
Evaluation dashboard
The optional Next.js dashboard submits traversers and displays results/events. Its server proxy holds the graph API key, while the worker selects the configured model. The page does not accept arbitrary provider models per request.
cd examples/python/retrieval_quality/ui
npm ci
ATFGRAPH_SERVER=http://127.0.0.1:18880 npm run dev -- --hostname 127.0.0.1
# Open http://127.0.0.1:3000
Use the dashboard on a trusted local machine. Its proxy acts under one configured server identity; add application user authentication and authorization before sharing it.
Docker Compose
Build the server image and choose a local API key. Stop any existing server using port 18880 before starting this stack:
docker build -f deploy/docker/Dockerfile.server -t atfgraph-vnext/graph-server:local .
export ATFGRAPH_API_KEY="$(python -c 'import secrets; print(secrets.token_urlsafe(32))')"
docker compose -f examples/python/retrieval_quality/compose.yaml up --build -d
atfg traverse retrieval_quality.evaluate_rag_response --in '{"question":"When does the desk open?","context":"The desk opens at 9am.","response":"The desk opens at 9am.","mode":"quick"}'
docker compose -f examples/python/retrieval_quality/compose.yaml down
Open the dashboard on 3000 and the server API/Console on 18880. The named Compose volume retains data across container replacement.
Local ML checks and principles
Edit config/constitution.yaml to define principles and weights. Its domain overrides are selected by the API's domain; neighboring domain preset files are examples rather than automatically active configuration.
For optional NLI checks, install requirements-ml.txt or build with INSTALL_ML_DEPS=true, then request use_ml=true. Model downloads happen on first use and need network access. NLI results remain separate from fixture/model scores. The NER and embedding utilities provide additional local experiments. Fixture mode needs none of these downloads. Evaluate the resulting diagnostics against labeled cases before using them for decisions.