gatrag-context-classifier 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: gatrag-context-classifier
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: NLI cross-encoder gate that scores whether retrieved RAG context is sufficient to answer a query.
|
|
5
|
+
Project-URL: Homepage, https://github.com/YOUR_USER/gatrag-context-classifier
|
|
6
|
+
Author-email: Gattupalli Saketh <18saketh@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Keywords: classifier,context,cross-encoder,nli,rag
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Requires-Dist: numpy>=1.24
|
|
15
|
+
Provides-Extra: model
|
|
16
|
+
Requires-Dist: sentence-transformers>=3.0; extra == 'model'
|
|
17
|
+
Requires-Dist: torch>=2.0; extra == 'model'
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
GATRAG
|
|
21
|
+
|
|
22
|
+
Guarded Abstention / Answering for Retrieval-Augmented Generation (RAG)
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
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.
|
|
27
|
+
|
|
28
|
+
Core idea: retrieve → validate context → generate only when the context is sufficient.
|
|
29
|
+
|
|
30
|
+
This can help RAG applications reduce unnecessary generation, expose an inspectable confidence signal, and avoid confidently answering when retrieval produced weak or irrelevant context.
|
|
31
|
+
|
|
32
|
+
Features
|
|
33
|
+
|
|
34
|
+
NLI-based context sufficiency classification.
|
|
35
|
+
|
|
36
|
+
Per-document relevance/sufficiency scoring.
|
|
37
|
+
|
|
38
|
+
Document filtering and ranking.
|
|
39
|
+
|
|
40
|
+
Optional whole-context ("packed") scoring.
|
|
41
|
+
|
|
42
|
+
Explicit SUFFICIENT, INSUFFICIENT, and UNCERTAIN results.
|
|
43
|
+
|
|
44
|
+
Simple boolean generation gate through validate_context_simple().
|
|
45
|
+
|
|
46
|
+
Batch validation through batch_validate().
|
|
47
|
+
|
|
48
|
+
Supports plain strings, SimpleDocument, and document-like objects exposing page_content and optional metadata.
|
|
49
|
+
|
|
50
|
+
Configurable score thresholds, uncertainty margins, model, device, batching, context length, and ranking limits.
|
|
51
|
+
|
|
52
|
+
Optional conservative fallback when model inference fails.
|
|
53
|
+
|
|
54
|
+
Compatible with CPU and CUDA environments.
|
|
55
|
+
|
|
56
|
+
Small public API with typed configuration and inspectable results.
|
|
57
|
+
|
|
58
|
+
Installation
|
|
59
|
+
|
|
60
|
+
Basic installation
|
|
61
|
+
|
|
62
|
+
pip install gatrag-context-classifier
|
|
63
|
+
|
|
64
|
+
Model-enabled installation
|
|
65
|
+
|
|
66
|
+
The default classifier loads an NLI model through sentence-transformers. Install the model extra:
|
|
67
|
+
|
|
68
|
+
pip install "gatrag[model]"
|
|
69
|
+
|
|
70
|
+
Or with uv:
|
|
71
|
+
|
|
72
|
+
uv add "gatrag[model]"
|
|
73
|
+
|
|
74
|
+
The default model is:
|
|
75
|
+
|
|
76
|
+
cross-encoder/nli-deberta-v3-small
|
|
77
|
+
|
|
78
|
+
The model is loaded automatically when ContextSufficientClassifier is created without a custom model.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
GATRAG
|
|
2
|
+
|
|
3
|
+
Guarded Abstention / Answering for Retrieval-Augmented Generation (RAG)
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
Core idea: retrieve → validate context → generate only when the context is sufficient.
|
|
10
|
+
|
|
11
|
+
This can help RAG applications reduce unnecessary generation, expose an inspectable confidence signal, and avoid confidently answering when retrieval produced weak or irrelevant context.
|
|
12
|
+
|
|
13
|
+
Features
|
|
14
|
+
|
|
15
|
+
NLI-based context sufficiency classification.
|
|
16
|
+
|
|
17
|
+
Per-document relevance/sufficiency scoring.
|
|
18
|
+
|
|
19
|
+
Document filtering and ranking.
|
|
20
|
+
|
|
21
|
+
Optional whole-context ("packed") scoring.
|
|
22
|
+
|
|
23
|
+
Explicit SUFFICIENT, INSUFFICIENT, and UNCERTAIN results.
|
|
24
|
+
|
|
25
|
+
Simple boolean generation gate through validate_context_simple().
|
|
26
|
+
|
|
27
|
+
Batch validation through batch_validate().
|
|
28
|
+
|
|
29
|
+
Supports plain strings, SimpleDocument, and document-like objects exposing page_content and optional metadata.
|
|
30
|
+
|
|
31
|
+
Configurable score thresholds, uncertainty margins, model, device, batching, context length, and ranking limits.
|
|
32
|
+
|
|
33
|
+
Optional conservative fallback when model inference fails.
|
|
34
|
+
|
|
35
|
+
Compatible with CPU and CUDA environments.
|
|
36
|
+
|
|
37
|
+
Small public API with typed configuration and inspectable results.
|
|
38
|
+
|
|
39
|
+
Installation
|
|
40
|
+
|
|
41
|
+
Basic installation
|
|
42
|
+
|
|
43
|
+
pip install gatrag-context-classifier
|
|
44
|
+
|
|
45
|
+
Model-enabled installation
|
|
46
|
+
|
|
47
|
+
The default classifier loads an NLI model through sentence-transformers. Install the model extra:
|
|
48
|
+
|
|
49
|
+
pip install "gatrag[model]"
|
|
50
|
+
|
|
51
|
+
Or with uv:
|
|
52
|
+
|
|
53
|
+
uv add "gatrag[model]"
|
|
54
|
+
|
|
55
|
+
The default model is:
|
|
56
|
+
|
|
57
|
+
cross-encoder/nli-deberta-v3-small
|
|
58
|
+
|
|
59
|
+
The model is loaded automatically when ContextSufficientClassifier is created without a custom model.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "gatrag-context-classifier"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "NLI cross-encoder gate that scores whether retrieved RAG context is sufficient to answer a query."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Gattupalli Saketh", email = "18saketh@gmail.com" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["rag", "nli", "cross-encoder", "context", "classifier"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"numpy>=1.24",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
model = [
|
|
28
|
+
"sentence-transformers>=3.0",
|
|
29
|
+
"torch>=2.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/YOUR_USER/gatrag-context-classifier"
|
|
34
|
+
|
|
35
|
+
[tool.hatch.build.targets.wheel]
|
|
36
|
+
packages = ["src/gatrag"]
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.sdist]
|
|
39
|
+
include = [
|
|
40
|
+
"src/gatrag",
|
|
41
|
+
"README.md",
|
|
42
|
+
"pyproject.toml",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[tool.uv]
|
|
46
|
+
package = true
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|