Finance AI Assistant

Agentic RAG · LangGraph · MCP · pgvector · Ollama

A local agentic RAG assistant that answers questions about US and Taiwan listed companies from their filings and news, with cited sources — running entirely on Ollama.

DemoGitHub

01Architecture

Finance AI Assistant architectureA question flows from the Chainlit UI through an 11-node LangGraph pipeline (rewrite, filter extraction, market resolution, an agent loop with MCP tools, answer assembly and generation). Tools call an MCP server backed by pgvector and a query-triggered ETL that ingests SEC, TWSE and Yahoo sources. Ollama and Langfuse sit alongside the graph.LangGraph · 11 nodesUserChainlit UIrewrite_questionextract_filtersresolve_marketask_marketask_companyoff_topicagentENDENDENDtoolsmax 4 roundsassemblegenerateno_result+ citationsENDENDOllama · qwen3.5:9b· bge-m3Langfuse tracing· JSON Lines logsMCP server· 3 tools (Bearer)pgvector · HNSW· bge-m3 1024-dQuery-triggered ETLSEC EDGAR/XBRLTWSE/MOPSYahoo RSS

02By the numbers

03Engineering decisions

01

Raw pgvector SQL over LangChain PGVector

JSONB metadata filters can't express "rank only within the latest filing" — the target Q2 chunks ranked #242 by pure similarity. Hand-written SQL handles multi-filter retrieval and reserves a slot for the latest report.

View code →
02

Single-purpose MCP tools

Retrieval and fetching are split into 3 MCP tools shared by the built-in agent and external clients, served over streamable HTTP with constant-time Bearer auth; the server refuses to start without a token.

View code →
03

Deterministic guardrails around the agent

Code, not the LLM, ends the loop when news is already fresh, caps tool calls at 4 rounds, and asks the user for a ticker when structured extraction degrades instead of searching the whole corpus.

View code →
04

Two silent failures, found and fixed

Ollama's default context silently cut 50–75% of every prompt (125 truncations → 0 after resizing), and token-capped JSON still "parsed successfully" — now detected via done_reason.

View code →
← All projects