Skip to main content

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

gatrag_context_classifier-1.0.0.tar.gz (2.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gatrag_context_classifier-1.0.0-py3-none-any.whl (2.2 kB view details)

Uploaded Python 3

File details

Details for the file gatrag_context_classifier-1.0.0.tar.gz.

File metadata

File hashes

Hashes for gatrag_context_classifier-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b6ab577e99978f6774031d2976e1c8645223093f5dad9cc13be776d132c5dfee
MD5 99de5718f70cde83262d4019f14379f6
BLAKE2b-256 763c7cc2a7c27b6bab8abf134225615d3ebaf93561a08e630b0d610a0ea649d4

See more details on using hashes here.

File details

Details for the file gatrag_context_classifier-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gatrag_context_classifier-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86a558755bb95f18bcc6e09139ba6b6c57cc4ca3ebe9038269112bb199f26f78
MD5 05579a731712b64be1785e410d46c154
BLAKE2b-256 ca3e9af173df45844a3e7be6e04bb88d6f5b2d75506c6213d4ed521428a2b8ea

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page