Source
PortfolioGPT
Agentic RAG assistant for mutual-fund portfolios. Raised numeric accuracy from 66.7% to 91.7% behind a CI eval gate.
TypeScript / NestJS / Next.js 15 / pgvector / BullMQ / Claude on Bedrock
View codeHow every figure stays out of the model
PortfolioGPT answers questions about an Indian mutual fund portfolio from the investor's CAMS or KFintech statement. A LangGraph agent over Claude chooses the tools, but every figure the user sees, including XIRR, asset allocation and fund comparisons, is computed in TypeScript against Postgres and returned as a pre-rounded tool result.
Tool arguments are Zod-validated before anything runs, and the user id scoping every SQL query comes from the session, never the model. A projection tool takes a rate the user states or the position's own historical XIRR; with neither, it returns no scenarios and tells the model to ask. A provenance check logs any figure in an answer that no tool returned.
Retrieval as a tool, fused in one SQL statement
Document search is a tool the model calls for prose from factsheets or scheme documents, not a stage before every answer. Inside it, pgvector HNSW cosine search and Postgres full-text search each take their top 20 chunks, and reciprocal rank fusion merges them in one SQL statement, returning five by default. Chunks for schemes the user does not hold are excluded unless the scheme is named, and each is wrapped as untrusted content, cited by document id and page.
How password-protected statements are parsed and checked
Statement passwords are encrypted in the browser to the API's RSA public key and never outlive the parse job. A BullMQ worker on Redis reads the PDF from S3, decrypts it, picks an extractor by layout and writes the result in one transaction. Reconciliation replays each scheme's ledger from the stated opening balance, and a gap above 0.01 units against the stated closing balance becomes a parse warning. Raw PDFs are deleted 24 hours after upload.
Gating numeric accuracy in CI
A golden evaluation set runs in GitHub Actions against a frozen portfolio, failing the build if numeric accuracy drops more than five points below the last run on the same provider. CI runs it keyless, with a stub agent and hashing embedder, so it measures the tool, retrieval and guardrail pipeline, not a model's reasoning. On that baseline, a grader fix and tool-routing changes took numeric accuracy from 66.7% to 91.7% across measured iterations, at 100% retrieval accuracy and a 0% hallucination rate.