Back to Writings

You're Optimizing RAG in the Wrong Place

We improved our RAG pipeline by 20% nDCG without changing embeddings, retrieval strategies, or rerankers.

Originally published on X.

You’re Optimizing RAG in the Wrong Place

We improved our RAG pipeline by 20% nDCG without changing embeddings, retrieval strategies, or rerankers.

The issue wasn’t retrieval.

We embedded the technical schema descriptions while users asked business questions.

Here’s the context: we’re building an NL2SQL system, where we had to ground the right tables, columns, joins, metrics, and KPIs before generating SQL. We store this Schema Knowledge as JSON documents in Qdrant.

When the data looked right, but the retrieval felt wrong

Each JSON record was already clean, structured data about tables, columns, joins, and metrics, so for embedding this, we created a technical summary for each record, and we embedded it.

The summary was accurate; it mentioned the schema, so technically, it looked accurate.

Then, when we did some testing, it didn’t perform consistently across samples.

The moment it became obvious

We then looked at the questions the user actually asked.

No one asked, “Retrieve the product tables, and their related order_line items”

They asked, “Show me the top-selling items last quarter.” Or “Which products drove the most revenue in Q2?” Or “What moved the most units in the last three months?”

It was like a couple who speak different love languages and wonder why the other person doesn’t “get them”

Basically, the records contained structured “technical content” and schema-oriented descriptions. On the query side, it contained business-friendly, everyday language that never appears in a schema.

So both are correct in their own world, but when we put both together, neither is in the same region in the embedding space.

The Redesign

We’ve found our problem, and the solution is simple: we need to represent both in the same format.

What did we do?

Redesigning Schema Knowledge Ingestion and Retrieval

During Ingestion, we stopped embedding technical summaries. Instead, we wrote business-friendly descriptions without including any formulas and SQL syntax. For categorical tables, we even added a few sample values.

Before:
Table: products. Columns: product_id, name, category, price. Joins to order_items.

After:
Product catalog — every item we sell, with name, category, and price. Used to answer “top-selling items”, revenue by product, or performance of a category over time. Links to orders and sales data.

During Retrieval, we never embed the raw user question. We first decompose it into the same business-friendly style - separately for each record type (tables, columns, joins, metrics, KPIs), before embedding.

User query:
“Show me the top-selling items last quarter.”

Rewritten for search (example for table/column records):
Top products by units sold or revenue in the previous quarter. Rank by quantity or sales amount. Use product catalog + order/sales data.

Only then did we run dense + sparse retrieval across all record types.

The change was simple, but the impact was not.

What improved?

Queries that had been inconsistent suddenly started grounding the right tables, columns, joins, and metrics much more reliably.

When we measured it against our golden dataset, nDCG improved by around 20%, with Recall improving by roughly 15%.

Looking back, we spent weeks trying to improve retrieval. The biggest improvement came from changing how the knowledge was represented.

– rac

Dharshan Athiaman’s résumé

Résumé page 1 of 2. Skills, professional experience, and projects.Résumé page 2 of 2. Publications, grants, and education.