GATRAG
Guarded Abstention / Answering for Retrieval-Augmented Generation (RAG)
GATRAG is a lightweight context-sufficiency gate for RAG pipelines. It sits between the retriever and the LLM/generator, evaluates whether retrieved passages contain enough information to answer a user's query, filters weak passages, and provides an explicit generate / abstain decision.
Instead of always sending retrieved documents to an LLM, GATRAG uses an NLI cross-encoder to estimate whether the retrieved context actually supports the query.
Core idea: retrieve → validate context → generate only when the context is sufficient.
This can help RAG applications reduce unnecessary generation, expose an inspectable confidence signal, and avoid confidently answering when retrieval produced weak or irrelevant context.
Features
NLI-based context sufficiency classification.
Per-document relevance/sufficiency scoring.
Document filtering and ranking.
Optional whole-context ("packed") scoring.
Explicit SUFFICIENT, INSUFFICIENT, and UNCERTAIN results.
Simple boolean generation gate through validate_context_simple().
Batch validation through batch_validate().
Supports plain strings, SimpleDocument, and document-like objects exposing page_content and optional metadata.
Configurable score thresholds, uncertainty margins, model, device, batching, context length, and ranking limits.
Optional conservative fallback when model inference fails.
Compatible with CPU and CUDA environments.
Small public API with typed configuration and inspectable results.
Installation
Basic installation
pip install gatrag-context-classifier
Model-enabled installation
The default classifier loads an NLI model through sentence-transformers. Install the model extra:
pip install "gatrag[model]"
Or with uv:
uv add "gatrag[model]"
The default model is:
cross-encoder/nli-deberta-v3-small
The model is loaded automatically when ContextSufficientClassifier is created without a custom model.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file gatrag_context_classifier-1.0.0.tar.gz.
File metadata
- Download URL: gatrag_context_classifier-1.0.0.tar.gz
- Upload date:
- Size: 2.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6ab577e99978f6774031d2976e1c8645223093f5dad9cc13be776d132c5dfee
|
|
| MD5 |
99de5718f70cde83262d4019f14379f6
|
|
| BLAKE2b-256 |
763c7cc2a7c27b6bab8abf134225615d3ebaf93561a08e630b0d610a0ea649d4
|
File details
Details for the file gatrag_context_classifier-1.0.0-py3-none-any.whl.
File metadata
- Download URL: gatrag_context_classifier-1.0.0-py3-none-any.whl
- Upload date:
- Size: 2.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86a558755bb95f18bcc6e09139ba6b6c57cc4ca3ebe9038269112bb199f26f78
|
|
| MD5 |
05579a731712b64be1785e410d46c154
|
|
| BLAKE2b-256 |
ca3e9af173df45844a3e7be6e04bb88d6f5b2d75506c6213d4ed521428a2b8ea
|