Abstention-Aware RAG Decision Layer
Project description
A2RAG — Abstention-Aware RAG Decision Layer
Decides when your RAG system should answer, ask for clarification, or abstain.
Installation
pip install a2rag
Quick Start
from a2rag import A2RAGClient
client = A2RAGClient(api_key="your_key_here")
# Your existing RAG pipeline
contexts = your_rag.retrieve(user_query)
draft_answer = your_llm.generate(user_query, contexts)
# A2RAG decides what to do
decision = client.decide(user_query, contexts, draft_answer)
if decision.should_answer:
show_to_user(draft_answer)
elif decision.should_clarify:
ask_user(decision.clarification)
elif decision.should_abstain:
escalate_to_human()
Decision Properties
decision.action # "answer" | "clarify" | "abstain"
decision.confidence # 0-1
decision.clarification # Question to ask user (if action=clarify)
decision.missing_fields # What info is missing
decision.should_answer # bool
decision.should_clarify # bool
decision.should_abstain # bool
decision.evidence_score # How well corpus supports the answer
decision.is_high_confidence # confidence >= 0.80
Metrics & Analytics
# Get metrics for last 30 days
m = client.metrics(days=30)
print(f"Answer rate: {m.answer_rate:.1%}")
print(f"UAR: {m.uar:.1%}") # Unsafe Answer Rate
print(f"ORS: {m.ors:.1%}") # Overall Reliability Score
print(f"Avg latency: {m.avg_latency_ms:.0f}ms")
# By domain
by_domain = client.metrics_by_domain()
# By language
by_lang = client.metrics_by_language()
# Over time
trends = client.trends(days=30, interval="day")
# Error analysis
errors = client.error_analysis()
Local Dashboard
client.dashboard() # Opens browser at http://localhost:7860
# or from terminal:
# a2rag dashboard
All data is stored locally. Nothing is sent to A2RAG servers (paid plans).
Feedback
decision = client.decide(query, contexts, draft)
# ... show to user, get feedback ...
client.feedback(decision.decision_id, was_correct=True)
Calibration
labeled_data = [
{"query": "...", "contexts": [...], "draft_answer": "...", "label": "answer"},
# ... 50+ examples
]
result = client.calibrate(labeled_data, domain="insurance")
print(f"Optimal tau_evidence: {result.tau_evidence}")
Export
client.export("decisions.csv", days=30)
# or: a2rag export decisions.csv
Privacy
- All decision history is stored locally in
~/.a2rag/decisions.db - Free tier: sends anonymous metrics (action, confidence, language, latency)
- Paid tiers:
A2RAGClient(telemetry=False)— zero data sent - Query content, contexts, and answers are NEVER sent to A2RAG servers
Supported Languages
English, Hebrew, Arabic, French, Spanish, and more — language is auto-detected.
Supported Context Formats
# Any of these work:
contexts = ["plain string"]
contexts = [{"text": "...", "score": 0.9}]
contexts = [langchain_document]
contexts = [llamaindex_node]
contexts = [your_custom_chunk] # any object with .text attribute
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
a2rag-0.1.0.tar.gz
(16.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
a2rag-0.1.0-py3-none-any.whl
(19.2 kB
view details)
File details
Details for the file a2rag-0.1.0.tar.gz.
File metadata
- Download URL: a2rag-0.1.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e835d1139561be3f856a322164fb8d2d4f8bcebe3dc6ec2e30bc586585a15654
|
|
| MD5 |
1dfa750b60b8cc5c1156e11ffa265f79
|
|
| BLAKE2b-256 |
2b67fbd289c474f91b501a2ce6b9419ab7b3dce5158911b12e46f3ad298f2fde
|
File details
Details for the file a2rag-0.1.0-py3-none-any.whl.
File metadata
- Download URL: a2rag-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c234d48d29fc0247057d607973f091b2505e62111068df58657e5465297228f8
|
|
| MD5 |
7ed807f2f071d68f417f895bab60181e
|
|
| BLAKE2b-256 |
2700798d061f42ba466a9205144a68ad78b86a2d0004341e4280eda46209ccab
|