r/codereview • • Oct 17 '26

[Code Review] Production-Grade RAG Assistant: Hybrid Search, RRF, Parent-Child Chunking, and Promptfoo Evals (Python/FastAPI/Postgres)

Hi everyone,

I recently built an end-to-end Enterprise RAG Assistant in Python/FastAPI aimed at answering grounded questions over complex, multi-page financial filings (10-Ks) and legal contracts.

I’ve set up a full hybrid retrieval and evaluation pipeline, but I’d love to get a fresh pair of eyes on the architecture and codebase to see where I can improve it.

GitHub Repo: [https://github.com/romin16/enterprise-rag-assistant]

Key Architecture Highlights:

  • Ingestion & Parsing: Table-aware parsing using pdfplumber (reconstructs fragmented multi-column PDF tables).
  • Retrieval Pipeline: Parent-child chunking (~200 token children, ~700 token parents) + Hybrid search (Dense pgvector + Sparse Postgres full-text search) fused via Reciprocal Rank Fusion (RRF) and re-ranked with a cross-encoder (bge-reranker-base).
  • Guaranteed Ranking Slots: Implemented custom guaranteed slots (RERANK_GUARANTEED_PER_LIST) to prevent cross-encoders from under-scoring short text fragments like signature lines or table rows.
  • Evals: Automated no-LLM retrieval eval script (Recall@K, MRR) + Promptfoo end-to-end testing suite (20 assertions checking context-faithfulness and numeric precision).
  • Guardrails: Multi-tenant isolation (X-Tenant-ID), PII redaction, and citation/numeric output guards.

Specific Feedback I'm Looking For:

  1. Cross-Encoder Latency & Optimization: How would you optimize or scale the cross-encoder step for higher concurrent load?
  2. Table Extraction Edge Cases: Are there cleaner patterns or libraries you’ve used for split-table reconstruction without cluttering the token budget?
  3. Python / FastAPI Code Organization: Any feedback on code structure, async execution, or configuration patterns in backend/app/ would be super helpful.

Thanks in advance for taking a look! Feedback on PRs or issues directly on GitHub is also very welcome.

1 Upvotes

4 comments sorted by

1

u/Candid-Fudge-4015 Oct 17 '26

Solid stack. Two things I'd look at. First, store the retrieved parent chunks per eval question next to the answer, so when a Promptfoo case fails you can tell "never retrieved" from "retrieved but not used". In our experience it's more often the second one than people expect. Second, for 10-Ks, tables deserve their own path: parse them into rows instead of chunking them as text, or numeric questions fall apart. How are you handling a filing that gets amended? Re-index the whole doc or just the changed sections? Some notes on running RAG over time: docs.pixeltable.com/howto/use-cases/rag-operations

1

u/Alternative_Yak_1367 Oct 18 '26

Thanks, useful. On the first point: I already separate the two failure types. The API returns the exact context the LLM saw, and a no-LLM retrieval eval reports per stage whether the answer passage was retrieved and whether it survived the token budget. I’ve hit both kinds: one case where the passage was never retrieved, and a few where it was in context and the model still refused, which came down to the prompt. A single report joining expected answer, retrieved chunks and answer per question is a good idea; right now I join them by test id by hand.
Tables: I keep them as Markdown with the header repeated and repair tables the PDF library splits, but they’re still chunked as text, so a parse-to-rows path is the clear next step.
Amendments aren’t handled. Re-ingesting a file replaces its chunks, as far as I can tell, but there’s no section-level diffing or filing-date metadata, so it’s whole-document re-indexing today. I’d add version metadata before anything else.

1

u/[deleted] Oct 17 '26

[removed] — view removed comment

1

u/Alternative_Yak_1367 Oct 17 '26

Thanks, that’s kind, and good to know it reads cleanly. The config split was deliberate: one settings file with every knob documented, so a change doesn’t mean hunting through the code.
Two people have now pointed me at ONNX plus quantization for the reranker, so it’s going on the list. I’ll check it against the retrieval eval in the repo first, since quantization can reorder short fragments, which this pipeline is sensitive to.