Skip to content

feat: production RAG hardening (15-task plan) - #44

Closed
n0nuser wants to merge 19 commits into
mainfrom
feat/production-rag-hardening
Closed

feat: production RAG hardening (15-task plan)#44
n0nuser wants to merge 19 commits into
mainfrom
feat/production-rag-hardening

Conversation

@n0nuser

@n0nuser n0nuser commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

Implements all 15 tasks from docs/superpowers/plans/2026-07-07-production-rag-hardening.md:

  • Ingestion metadata enrichment + incremental rebuild (content hash, mtime, git commit)
  • Chunk overlap ratio tuned to ~12.5% of max chunk size
  • Metadata pre-filtering across vector (Chroma where=) and BM25 retrieval paths
  • Hierarchical parent-section expansion for retrieved chunks
  • Optional cross-encoder reranking (sentence-transformers, off by default)
  • Optional LLM-based query rewriting for retrieval (off by default)
  • Low-confidence refusal gate (RAG_MIN_CONTEXT_SCORE, off by default)
  • Source traceability: heading_path/chunk_type on SourceRef
  • Durable local audit log (opt-in via AUDIT_LOG_PATH)
  • Async ingestion via background job registry (POST /ingest/directory/async)
  • In-process TTL query cache (off by default)
  • LLM provider resilience: retry + circuit breaker + optional fallback backend, uniformly applied to all providers (ollama/openai/anthropic)
  • RAGEngine now routed through the resilient provider abstraction — LLM_BACKEND actually governs /query (previously always hit Ollama regardless of setting)
  • Optional tenant_id metadata tagging for shared-deployment query scoping
  • RAGAS eval gate on PRs touching rag//ingestion/, judge LLM running fully offline against local Ollama (no OPENAI_API_KEY anywhere)

Also adds ADRs 007-009 documenting the resilient-provider-routing, reranking, and offline-ragas-judge decisions, plus log_reasonings/ session notes on the agent fan-out strategy used to implement this plan.

Test plan

  • uv run pytest -m "not integration" -q — 141 passed, 9 deselected
  • ruff check . / ruff format --check . — clean
  • Full ragas eval run completed offline against local Ollama: faithfulness 0.942, answer_relevancy 0.671, context_precision 0.891, context_recall 1.000 — all above threshold
  • Live end-to-end verification that LLM_BACKEND=openai with a bad key now produces a real 401 from the OpenAI SDK (proving routing actually works, not silently falling back to Ollama)

https://claude.ai/code/session_01Md71iujmpvewiisGX5u33H

n0nuser added 19 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.
Comment thread localrag/api/service.py Dismissed
Comment thread localrag/api/service.py Dismissed
@n0nuser

n0nuser commented Jul 8, 2026

Copy link
Copy Markdown
Owner Author

Content already landed on main — PR #43's rebase-merge picked up this branch's commits (all 19, replayed with new SHAs) plus its own fix on top. Verified via file-level diff: origin/main and this branch's tree are identical except for #43's extract_sources/ingest_paths cleanup, which main already has. Closing as redundant.

@n0nuser n0nuser closed this Jul 8, 2026
@n0nuser
n0nuser deleted the feat/production-rag-hardening branch July 8, 2026 17:44
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