ragrefine
Evidence-first post-retrieval refinement for RAG systems.
ragrefine improves an existing retriever's candidate set before it reaches an
LLM. It reranks, fuses, deduplicates, and selects context while preserving the
original evidence and recording an auditable trace.
retriever -> Top-N candidates -> ragrefine -> refined Top-K + trace -> LLM
The core library is framework- and retriever-agnostic. Haystack support is available as an optional integration.
Core deliverables
| Capability | Delivered behaviour |
|---|---|
| Candidate contract | Immutable candidates retain IDs, text, metadata, retrieval rank, and retrieval score |
| Ranking channels | Independent original, neural, lexical, and configurable pattern rankings over the same candidate pool |
| Rank fusion | Deterministic reciprocal-rank fusion without mixing incompatible raw-score scales |
| Context refinement | Exact/near-duplicate suppression and rank-preserving Top-K/token-budget selection |
| Traceability | Per-channel evidence, fusion contributions, stage timings, configuration, and explicit failure records |
| Neural reranking | Optional SentenceTransformers CrossEncoder adapter with batched inference |
| Haystack integration | Serializable component profiles and a retriever-to-generator pipeline builder |
| Evaluation | Frozen BEIR candidate pools, checksummed artifacts, reproducibility commands, and a paired Ragas harness |
Output candidates always originate from the supplied input pool; ragrefine
does not invent or rewrite evidence.
Quick start
Python 3.12+ is required. From this checkout:
uv sync
from ragrefine import Candidate, CandidateSet, Refiner
candidates = CandidateSet(
name="my-retriever",
candidates=(
Candidate(
id="doc-1",
text="Python 3.12 improves f-string parsing.",
retrieval_rank=1,
retrieval_score=0.91,
),
Candidate(
id="doc-2",
text="Python 3.11 introduced exception groups.",
retrieval_rank=2,
retrieval_score=0.84,
),
),
)
result = Refiner().refine(
query="Which Python version improves f-string parsing?",
candidate_set=candidates,
top_k=1,
)
print(result.candidates[0].candidate.id)
print(result.trace)
Refiner() preserves the original ranking. Explicit RefinerConfig settings
enable lexical, pattern, neural, or fused profiles. See the
technical design for the configuration contract.
Haystack integration
uv sync --extra haystack
The optional integration provides document conversion, a serializable
RagRefineComponent, registered refiner profiles, prompt construction, and a
complete Haystack pipeline builder. The RAG pipeline guide
contains the runnable recipe and customization points.
Evaluation summary
Post-retrieval comparisons reuse the same frozen first-stage Top-50 candidates. Retrieval is not regenerated between profiles, and candidate-pool Recall@50 is a fixed ceiling rather than a refinement gain.
| Experiment | SciFact result | Decision |
|---|---|---|
| B0 — frozen dense baseline | nDCG@5 0.4592 | Baseline |
| B1-reference — MiniLM-L6/CUDA | nDCG@5 0.6262 | Retained neural profile |
| B1-light — TinyBERT-L2/CPU | nDCG@5 0.6112 | Retained measured profile |
| B2-L — lexical/CPU | nDCG@5 0.5432 | Retained lightweight profile |
| B2-P — patterns/CPU | nDCG@5 0.4559 | Not retained |
| B3 — equal-weight fusion | Best profile nDCG@5 0.5715 | Not retained; below B1-reference |
The end-to-end Ragas A/B used 13 paired DeepSeek queries. It is statistically inconclusive: the positive directional score differences have 95% paired bootstrap confidence intervals spanning zero, and both context metrics are saturated at 1.0. The run establishes neither an end-to-end benefit nor a regression. See the retained A/B report.
Machine-readable artifacts are the source of truth. No experiment is described as improved unless its recorded measurements support that claim.
Documentation
Detailed material removed from this README remains in the repository's focused documents:
- Product requirements — supported scope and product boundary
- Technical hypotheses — testable claims and current evidence
- Technical design — architecture, configuration, selection, and tracing contracts
- Evaluation contract — frozen-pool rules, metrics, profiles, and reporting policy
- Benchmark guide — execution and reproduction commands
- Retained artifact manifest — checksummed benchmark inputs and verification
- Haystack pipeline guide — integration and serialization
- Ragas evaluation guide — paired A/B design and analysis
- v0.2 release record — delivered scope, validation, and limitations
Scope
ragrefine owns post-retrieval candidate refinement, context selection, and
tracing. It deliberately does not own ingestion, parsing, chunking, embeddings,
vector databases, first-stage retrieval, LLM generation, agents, or deployment.
Development
uv sync --extra haystack --extra ragas
uv run ruff check .
uv run ruff format --check .
uv run mypy src/
uv run pytest
uv build
Heavy model and benchmark dependencies remain optional so the core package has no runtime dependencies.
License
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 ragrefine-0.2.1.tar.gz.
File metadata
- Download URL: ragrefine-0.2.1.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d14fb3b784d7aa8c97866182ff7ef588a110446d50a84c117129c16a75a0527e
|
|
| MD5 |
28222bd89f387b97e6a21cb15b87cb03
|
|
| BLAKE2b-256 |
cab67d2805a4e183849f94fe24829730626b7d5be60ffed8c3eed0a16b9b455c
|
Provenance
The following attestation bundles were made for ragrefine-0.2.1.tar.gz:
Publisher:
release.yml on Atharva01/ragrefine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ragrefine-0.2.1.tar.gz -
Subject digest:
d14fb3b784d7aa8c97866182ff7ef588a110446d50a84c117129c16a75a0527e - Sigstore transparency entry: 2799038140
- Sigstore integration time:
-
Permalink:
Atharva01/ragrefine@8968a37c542218f60688f1a2fb34a1e5f2d8a51b -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Atharva01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8968a37c542218f60688f1a2fb34a1e5f2d8a51b -
Trigger Event:
push
-
Statement type:
File details
Details for the file ragrefine-0.2.1-py3-none-any.whl.
File metadata
- Download URL: ragrefine-0.2.1-py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5860194216d1463dce3071f13b51abb0353308550fce577c219b64b13cbbe0a9
|
|
| MD5 |
9b00ec80de8ad8f7302bbf4f7b2cd875
|
|
| BLAKE2b-256 |
15433e3a093f6252ffa7839b5ac183861ce558b43d74c8caeb8e3d3cd0c5b5fd
|
Provenance
The following attestation bundles were made for ragrefine-0.2.1-py3-none-any.whl:
Publisher:
release.yml on Atharva01/ragrefine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ragrefine-0.2.1-py3-none-any.whl -
Subject digest:
5860194216d1463dce3071f13b51abb0353308550fce577c219b64b13cbbe0a9 - Sigstore transparency entry: 2799038269
- Sigstore integration time:
-
Permalink:
Atharva01/ragrefine@8968a37c542218f60688f1a2fb34a1e5f2d8a51b -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Atharva01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8968a37c542218f60688f1a2fb34a1e5f2d8a51b -
Trigger Event:
push
-
Statement type: