rag-quality-kit
Heuristic quality metrics for RAG retrieval and grounded answers. Zero runtime dependencies, pure-Python.
Python port of @mukundakatta/rag-quality-kit. The JS sibling has the original heuristics; this README sticks to the Python API.
Install
pip install rag-quality-kit
Usage
from rag_quality_kit import score, missing_evidence
question = "Who wrote Hamlet and when was it first performed?"
contexts = [
{"id": "doc-1", "text": "Hamlet is a tragedy by William Shakespeare, written around 1600."},
{"id": "doc-2", "text": "Records suggest Hamlet was first performed in 1602."},
]
answer = "Hamlet was written by Shakespeare and first performed in 1602."
r = score(question, contexts, answer)
r.groundedness # 0..1 -- answer terms that appear in any context
r.context_relevance # 0..1 -- question terms covered by the contexts
r.answer_relevance # 0..1 -- question terms covered by the answer
r.conciseness # 0..1 -- 1.0 if answer is roughly question-sized, decays as it balloons
r.overall # unweighted mean of the four
missing_evidence(answer, contexts) # -> list[str] of answer terms not in any context
Metrics
| Metric | Range | Behavior |
|---|---|---|
groundedness |
0..1 | Fraction of answer terms found in any context. |
context_relevance |
0..1 | Fraction of (longer) question terms covered by the contexts. Mirrors the JS retrievalCoverage. |
answer_relevance |
0..1 | Fraction of question terms that the answer addresses. |
conciseness |
0..1 | 1.0 when the answer is up to ~2x the question's term count; linearly decays to 0 at 10x. |
overall |
0..1 | Unweighted mean of the four. |
All metrics are heuristic and token-overlap based -- fast, deterministic, no LLM calls. For evaluation-grade scoring layer an LLM judge on top.
API differences from the JS sibling
- Python signature is
score(question, contexts, answer)(positional) instead ofscoreRag({ query, answer, contexts }). - Returns a
QualityResultdataclass instead of a plain object. - Metric names:
context_relevance(wasretrievalCoverage),groundednessis unchanged. Adds two extra heuristics:answer_relevanceandconciseness. The aggregate isoverall(wasscore) and now averages all four. - Drops the
citationCoveragemetric -- it's heavily citation-format dependent and best owned by the calling app. Usemissing_evidence(answer, contexts)for an analogous signal.
See the JS sibling for the original heuristics and broader design notes.
Metadata
Release files for rag-quality-kit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rag_quality_kit-0.1.0.tar.gz | 6.1 kB | Without provenance | Details for rag_quality_kit-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rag_quality_kit-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for rag_quality_kit-0.1.0-py3-none-any.whl |
Total release size: 11.9 kB
Release files / rag_quality_kit-0.1.0.tar.gz
| Download URL | rag_quality_kit-0.1.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf20a1ca372b8bfb3c5f404cc82eccf47199bdddd155c198687b5561c73f284e
|
|
BLAKE2b-256 checksum How to use checksums |
923b0ce9dcf77e1c5adb0aef3fc423e656cfd81e2f160855eeaf50739f0429ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / rag_quality_kit-0.1.0-py3-none-any.whl
| Download URL | rag_quality_kit-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46a0b61162a9da136c8d502513f1ccc9ae4eefb6d833077c7aa7ee731b59ef3b
|
|
BLAKE2b-256 checksum How to use checksums |
59d0fbe4099fd936448524dd8dda2cfcc4e93dee26af141156d611d15eaa6945
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for rag-quality-kit 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.