Problem
A text-to-SQL assistant for business analysts has to find the right tables before it can write a query. In Sber's centralized data model the base data-mart layer alone holds about 1.5 thousand tables and 20 thousand business attributes, and the bank has more than a million entities and attributes overall. Passing all metadata to the LLM costs tokens and lowers accuracy. A single semantic index found all needed tables for only about 55% of benchmark questions.
Example from the article: the question "Find clients with high credit burden" should retrieve only matching columns and metadata, such as credit_score, loan_amount and income, and pass them to the LLM.
Solution in brief
Measure retrieval with Recall@K on question-SQL pairs. Replace one embedding index with two-step hybrid search (semantic plus BM25), data mart first and then table. Add LLM query decomposition and LLM-based table selection. Accuracy rose from about 55% to about 81%, at the price of about 30 seconds per search and about 80,000 tokens per LLM call.
Questions this case answers
- How to retrieve the few relevant schema objects out of thousands for a natural-language question when one embedding index is not accurate enough
- How to compare retrieval variants on a question-to-SQL benchmark and decide when extra LLM calls are worth their time and token cost
- How to find the right tables and columns for a text-to-SQL assistant when the data model has thousands of tables and tens of thousands of attributes?
- How to choose between semantic, keyword and hybrid retrieval over table metadata and measure the choice?
Tools and methods
- Hybrid search — semantic (FAISS) and BM25 retrievers merged by RRF or weighted ranking
- Query rewriting, decomposition, Step Back, HyDE — LLM changes the query before hybrid search
- GigaChat, GigaChain — the LLM and the LangChain fork that holds the retriever ensembles
- E5, GritLM, GigaChat Embeddings — embedding models compared
Google or a one-time email code. No password.