This work was done for a client under confidentiality. Client names and internal tooling are not shown.
The problem
Natural language and a trading database don't share a vocabulary. People ask about the best market, a client's repo positions or one broker's orders; the data lives under system naming conventions spread across many tables, with the same concept, such as a symbol, a client or a broker, appearing in dozens of them. A model that sees only the schema guesses at that mapping, and a wrong join returns an answer that looks right.
A confident wrong answer costs more than a null, so nothing runs until it has been checked.
Constraints
Architecture
Teach the system the business's vocabulary
- Context
- Schema names alone don't tell a model what a trader means by a term, or which of many similar tables holds the answer.
- Decision
- Retrieval across internal domain knowledge maps business terms to the right tables and fields before any query is formed.
- Trade-off
- The knowledge base becomes part of the system and has to be maintained as the data estate changes.
Engineering decisions
Benchmark models before committing to one
- Decision
- Several open-weight model families measured against closed APIs on this workload.
- Trade-off
- Time spent up front, in exchange for a model choice backed by measurements.
Separate agents with one narrow job each
- Decision
- Intent, planning, retrieval, execution and verification each have a narrow job and a checkable output.
- Trade-off
- More moving parts to orchestrate, but each failure is visible at the step where it happens.
What broke
Three problems showed up repeatedly.
- The wrong table. Many tables look alike, and the retrieval step sometimes picked a neighbour of the one that held the answer.
- Orders and trades. The two sound close in everyday speech and mean different things in the data. A question about one could be answered from the other.
- Expensive queries. Some generated queries took the costly route and scanned very long tables.
Each of these surfaced at a particular step, which is the reason the steps are separate.
Where it landed
Shipped as a Dockerised pipeline for internal use: a plain-English question in, the relevant data out, verified, and exportable as DOCX or CSV.
The specifics stay with the client. Happy to talk through the approach in more depth.
What I'd do differently
I would follow what is now standard industry practice for retrieval-augmented systems. The field has settled on better patterns since this was built, and I would start from those.
References
- Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, arXiv 2005.11401.