Rank a shortlist by its ability to answer the query, preserving a stable candidate ID.
Input and workflow
Start with an inexpensive lexical shortlist. Score candidates against the same rubric and preserve retrieval order as a deterministic tie breaker.
Request
{
"model": "ngila-judge",
"state": {
"query": "When is the reading room open?",
"passage": "Reading room: weekdays, 9 am to 6 pm."
},
"questions": {
"relevance": {
"type": "score",
"instructions": "How directly does the passage answer the question?",
"criteria": [
"Unrelated",
"Related topic",
"Partial answer",
"Complete answer"
]
}
}
}Run locally
Save ngila.py alongside your script and set NGILA_API_KEY. Save any linked input images in the same directory.
import json
from ngila import NgilaClient
state = {'query': 'When is the reading room open?',
'passage': 'Reading room: weekdays, 9 am to 6 pm.'}
questions = {'relevance': {'type': 'score',
'instructions': 'How directly does the passage answer the '
'question?',
'criteria': ['Unrelated',
'Related topic',
'Partial answer',
'Complete answer']}}
response = NgilaClient().system_one(state, questions)
a = response["answers"]
print(json.dumps(a, indent=2, ensure_ascii=False))Use the answers
The following application fragment uses a = response["answers"]. Supply any thresholds, lookup tables, or previous results from your workflow before applying it.
ranked = sorted(scored_passages, key=lambda x: -x["relevance"]["score"])