quant.cpp
quant.cpp copied to clipboard
Confidence score API: quantify answer reliability [0.0-1.0]
Summary
Add a structured confidence score to all API responses, turning RLV's internal verification signals into a user-facing reliability metric.
Motivation
RLV's key differentiator over RAG is knowing WHEN it's wrong. Currently this is a binary CONFIDENT/EXHAUSTED verdict. Users need a continuous score to make decisions:
- confidence > 0.9: show answer directly
- confidence 0.5-0.9: show answer with caveat
- confidence < 0.5: show "I'm not sure" + suggest human review
Proposed Response Format
{
"answer": "Battle of Midway",
"confidence": 0.92,
"verification": {
"literal_grounded": true,
"coherence_check": "YES",
"retries": 0,
"method": "literal+fast-accept"
}
}
Scoring Formula
confidence = base_score * coherence_factor * retry_penalty
base_score:
literal a-matched ≥80%: 0.9
literal a-matched 50-80%: 0.7
literal a-matched <50%: 0.4
coherence_factor:
fast-accept (specific entity): 1.0
coherence YES: 0.95
coherence NO: 0.3
self-check NONE: 0.1
retry_penalty:
0 retries: 1.0
1 retry: 0.85
2 retries: 0.7
exhausted: 0.4
Priority: P2
Implemented in 393bdd5. Model.ask_verified(context, question) → (answer, confidence).