fix: remove private-method boundary leak, dedupe ingest retry loop - #43
Merged
Conversation
…D now actually governs /query)
ragas 0.4.3 removed the pre-instantiated `ragas.metrics.collections`
singletons from the classic `evaluate()` path; it now requires actual
Metric instances (isinstance(m, Metric)), raising:
TypeError: All metrics must be initialised metric objects, e.g:
metrics=[BleuScore(), AspectCritic()]
Import Faithfulness/AnswerRelevancy/ContextPrecision/ContextRecall from
ragas.metrics (the legacy-compatible classes, still available via a
deprecation shim) and construct instances for evaluate().
Also fixes a related break: EvaluationResult.__getitem__ now returns a
list of per-row scores instead of a scalar, so float(result["metric"])
raised TypeError. Added _mean_score() to average per-row scores (NaN-safe),
preserving the existing PASS_THRESHOLDS gating logic.
Modern ragas.metrics.collections classes require per-sample async .ascore() calls, not the deprecated singleton-style ragas.metrics imports; the judge LLM/embeddings now run against the same local Ollama instance LocalRAG itself uses (via Ollama's OpenAI-compatible /v1 endpoint and the openai client already a core dependency), so evals stay fully offline with no OPENAI_API_KEY required anywhere, including CI.
log_reasonings/ captures decisions made during the production-RAG-hardening plan rollout (ragas judge LLM choice, agent fan-out strategy, retry discipline) as lighter-weight session notes alongside the formal docs/adr/.
Retroactively documents three architecture decisions from the production- RAG-hardening plan rollout that were missing formal ADRs (only captured in log_reasonings/ session notes): resilient/uniformly-routed LLM providers (Task 13-14), optional cross-encoder reranking (Task 6), and the offline Ollama-backed ragas judge (Task 1). Also clarifies in evals/run_evals.py that AsyncOpenAI/OpenAIEmbeddings there are OpenAI-shaped clients pointed at local Ollama, not a dependency on the OpenAI service.
RAGEngine._extract_sources was private but reached across the API/rag boundary via a noqa-suppressed access; made it public (extract_sources) instead. IngestionService.ingest_paths had two near-identical retry-loop bodies; extracted the shared per-file try/except into _safe_ingest_one, keeping exception-vs-no-chunks-produced distinguishable via a (result, error) tuple.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RAGEngine._extract_sourceswas private but reached across the API/rag boundary via anoqa: SLF001-suppressed access fromapi/service.py. Made it public (extract_sources) instead of suppressing the lint.IngestionService.ingest_pathshad two near-identical retry-loop bodies (first pass, retry pass). Extracted the shared per-file try/except into_safe_ingest_one, which returns a(chunks_added, error)tuple so "file raised" and "file legitimately produced 0 chunks" stay distinguishable (a naive collapse of the two loops first conflated these, which would've wrongly retried/failed empty files).Found via a code-quality review against
python-anti-patterns,python-code-style,api-design-principles, andthermo-nuclear-code-quality-reviewchecklists. Ruff (ALLrules) and mypy were already clean going in — no lint/type debt, just these two structural findings.Test plan
uv run pytest tests/— 147 passed, 3 skippedruff check localrag/ tests/— all checks passeduv run mypy localrag/— no new errors (only pre-existing 3rd-party stub gaps)