Rate a retrieved passage against the original question. Keep the score alongside the passage identifier for downstream ranking.
Input and workflow
Score each retrieved passage against the identical question. Sort by relevance, retain passage IDs, and inspect the passages that fall just below the cutoff.
Request
{
"model": "ngila-judge",
"state": {
"query": "Where can I return a rental bike?",
"passage": "Bikes may be returned to any staffed rental station."
},
"questions": {
"relevance": {
"type": "score",
"instructions": "Does the passage answer the query?",
"criteria": [
"Unrelated",
"Partially relevant",
"Direct 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': 'Where can I return a rental bike?',
'passage': 'Bikes may be returned to any staffed rental station.'}
questions = {'relevance': {'type': 'score',
'instructions': 'Does the passage answer the query?',
'criteria': ['Unrelated',
'Partially relevant',
'Direct 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.
normalized_relevance = a["relevance"]["score"] / 2