AI / LlamaIndex Interview Questions
How does LlamaIndex support structured data querying such as SQL?
LlamaIndex can answer natural-language questions against structured databases through query engines like NLSQLTableQueryEngine, which bridges plain English and SQL without the developer hand-writing queries.
The engine introspects the target database's schema, table names, column names, and types, and feeds that schema to the LLM along with the user's natural-language question. The LLM generates a SQL query, which the engine executes against the actual database, and the raw results can then optionally be synthesized back into a natural-language response.
from llama_index.core.query_engine import NLSQLTableQueryEngine query_engine = NLSQLTableQueryEngine(sql_database=sql_database, tables=["orders"]) response = query_engine.query("How many orders shipped last month?")
This is distinct from the usual RAG flow: instead of retrieving text chunks by similarity, it retrieves precise, aggregate answers directly from structured rows, which is far more accurate for questions involving counts, sums, or exact filters than embedding-based search would be.
More Related questions...