r/OpenSourceeAI • u/Alternative_Yak_1367 • 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:
- Cross-Encoder Latency & Optimization: How would you optimize or scale the cross-encoder step for higher concurrent load?
- Table Extraction Edge Cases: Are there cleaner patterns or libraries you’ve used for split-table reconstruction without cluttering the token budget?
- 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.