Combining Text-to-SQL with Semantic Search for Retrieval Augmented Generation
text-to-sqlragvector-databasesemantic-searchstructured-data
Abstraction: LlamaIndex engine joins SQL structured data with vector semantic search
Key points:
- LlamaIndex's
SQLAutoVectorQueryEngineroutes queries to a SQL database, a vector store, or both in sequence depending on query type - For hybrid queries (e.g., "arts of the city with the highest population"), SQL runs first, its result transforms the natural language query, then the vector store is queried with the refined question
- Auto-retrieval module (
VectorIndexAutoRetriever) infers metadata filters and top-k from SQL results, simulating a SQL-vector "join" without an explicit mapping - Selector prompt determines routing; if SQL fully answers the question, no vector store call is made
- Experiments on city_stats SQL table + Pinecone Wikipedia articles show correct routing for structured-only, unstructured-only, and hybrid queries
- Addresses the enterprise data lake problem where analytics (SQL) and contextual understanding (RAG) are siloed
Connections: Llamaindex · Pinecone · Retrieval Augmented Generation · Text To Sql · Semantic Search · Vector Databases