M.Tech CDS · IISc Bengaluru

Finance AIa local RAG that gets the arithmetic right

Ask plain questions about your own spending and get an answer computed from your transaction records — citing the transactions it used, and refusing when the records cannot support one. Elasticsearch and all-distilroberta-v1 both run on the machine; the spending history never leaves it.

Elasticsearch 8.15 all-distilroberta-v1 RRF hybrid retrieval fully local no LLM in the loop
100%
aggregation accuracy
589
transactions indexed
100%
refusal correctness
0
bytes sent off the machine
The problem

A total computed from a sample is wrong

The obvious RAG design — embed every transaction, retrieve top-k, let a model answer — works for "what did I buy at Decathlon?" and fails badly for "how much did I spend on groceries?"

Retrieve 8 rows, then sum
wrong
8 of 47 grocery rows — a specific, confident, incorrect number, and every row it cites is real
Filtered aggregation over all rows
100%
exact to the rupee across 16 category and category-by-month totals

So the two jobs are separated. Retrieval finds the transactions a question is about. Arithmetic never touches retrieved rows — aggregation questions are answered by a filtered Elasticsearch aggregation across every matching record. Retrieval still runs, and its results become the citations, so the answer shows its working.

Retrieval

Two paths over one field

BM25 for the names

Finds BigBasket when you type BigBasket. For merchant strings, lexical matching is exactly right and not obsolete.

Dense kNN for the meaning

all-distilroberta-v1 (768-dim) finds grocery shops when you ask about "food shopping" — a phrase that appears nowhere in the data.

Reciprocal Rank Fusion to merge them

Each document scores 1/(k + rank), summed across both lists. RRF needs no score calibration, which matters because BM25 scores and cosine similarities are not on comparable scales. Implemented in Python rather than using Elasticsearch's rrf retriever, a licensed feature — so this runs on a plain open-source node.

Security is structural, not a promise

Identifiers are redacted before indexing, so a card number never reaches the index. Elasticsearch binds to 127.0.0.1, embeddings run locally, and there is no API key because there is no API call.

Evaluation

Ground truth from the raw records

Every expected answer is computed directly from the transaction file in Python, with no Elasticsearch involved. If the system disagrees with the dataframe, the system is wrong.

Evaluation results
Retrieval's 73.3% understates it. A hit requires one specific transaction id in the top 8 — but a merchant with 26 transactions that month has several equally correct answers, and the retriever returned a different valid one. Scored on the right merchant, it is 15/15. The strict metric is the one reported.
Spending breakdown
The records. Synthetic but deliberately plausible — salary on the same day each month, rent that never moves, subscriptions that renew, and two months that genuinely look different.
Honest limits

What this does not do

The data is synthetic

A real bank export has messier merchant strings, refunds, failed transactions and duplicates — all of which hurt the retriever more than the aggregation.

Filter parsing is rule-based

It handles "groceries in November"; it does not handle "the month I went to Goa". An LLM extraction step would generalise it, at the cost of a dependency the design currently avoids.

Answers are templated, not generated

No LLM in the loop is what makes the system fully local and hallucination structurally impossible. The cost is rigid phrasing.