Skip to main content

Find stale RAG chunks by age, version, and freshness requirements. Python port of @mukundakatta/rag-staleness-auditor.

Project description

rag-staleness-auditor-py

PyPI Python License: MIT

Find stale RAG chunks by age, version, and freshness requirements. Run a quick audit over your retrieved documents before stuffing them into a prompt. Flag anything older than your max-age, or anything pinned to a stale version. Zero runtime dependencies.

Python port of @mukundakatta/rag-staleness-auditor.

Install

pip install rag-staleness-auditor-py

Usage

from rag_staleness_auditor import audit, filter_fresh

records = [
    {"id": "doc1", "updated_at": "2026-04-01T00:00:00Z", "version": "v3"},
    {"id": "doc2", "updated_at": "2024-01-01T00:00:00Z", "version": "v2"},
    {"id": "doc3", "updated_at": None,                    "version": "v1"},
]

report = audit(records, max_age_days=90, current_version="v3")

report.total           # 3
report.stale_count     # 2
report.fresh_count     # 1
report.stale_ids       # ["doc2", "doc3"]
report.entries[0].reasons  # [] for fresh, e.g. ["too_old", "version_mismatch"] otherwise

# Drop the stale ones from your retrieval result before building the prompt:
fresh = filter_fresh(records, max_age_days=90, current_version="v3")

API

Symbol Behavior
audit(records, *, max_age_days=90, current_version=None, date_field='updated_at', version_field='version', now=None) Returns an AuditReport with per-doc verdicts.
audit_staleness(records, *, max_age_days=30, current_version=None, ...) Lower-level helper -- returns list[StalenessEntry] (matches the JS sibling's shape).
filter_fresh(records, *, ...) Returns the input list with stale records dropped.
AuditReport Dataclass with total, stale_count, fresh_count, stale_ids, entries.
StalenessEntry Dataclass with id, stale, age_days, reasons.

reasons values are "too_old" and "version_mismatch", matching the JS sibling.

date_field and version_field let you swap field names without rewriting your records (e.g. version_field="schema_version").

See the JS sibling's README for the full design notes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rag_staleness_auditor_py-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

rag_staleness_auditor_py-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file rag_staleness_auditor_py-0.1.0.tar.gz.

File metadata

File hashes

Hashes for rag_staleness_auditor_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cf523b1f9f7123a9d5d3e16de594577b3bc26e52e093e85a9fa59f12efdc03f8
MD5 89a214b46f4923794085249efdc74c7c
BLAKE2b-256 50d70ee5a521e3fb9e10bfa61fbca5afc17e8fbe8d6d6576b50f31326ba60b4e

See more details on using hashes here.

File details

Details for the file rag_staleness_auditor_py-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rag_staleness_auditor_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c0d41ad12c5fe9f03c7196487301881f50305d3d913cc2a59c2985af13bb668
MD5 04b9223e824c1fb74d4b09891b07f2eb
BLAKE2b-256 e5630ff54fb5e281072ddbcef551cb72a3f0557d3cb84d73f39dfaf6f75740bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page