Skip to content

fix: remove private-method boundary leak, dedupe ingest retry loop - #43

Merged
n0nuser merged 20 commits into
mainfrom
fix/code-quality-review-findings
Jul 8, 2026
Merged

fix: remove private-method boundary leak, dedupe ingest retry loop#43
n0nuser merged 20 commits into
mainfrom
fix/code-quality-review-findings

Conversation

@n0nuser

@n0nuser n0nuser commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • RAGEngine._extract_sources was private but reached across the API/rag boundary via a noqa: SLF001-suppressed access from api/service.py. Made it public (extract_sources) instead of suppressing the lint.
  • IngestionService.ingest_paths had 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, and thermo-nuclear-code-quality-review checklists. Ruff (ALL rules) 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 skipped
  • ruff check localrag/ tests/ — all checks passed
  • uv run mypy localrag/ — no new errors (only pre-existing 3rd-party stub gaps)

n0nuser added 20 commits July 7, 2026 18:23
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.
Comment thread localrag/api/service.py Dismissed
Comment thread localrag/api/service.py Dismissed
@n0nuser
n0nuser merged commit a6f8878 into main Jul 8, 2026
9 checks passed
@n0nuser
n0nuser deleted the fix/code-quality-review-findings branch July 8, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants