Semantic Model Query Tool¶
The Semantic Model Query tool is an Agent tool leveraging a Semantic Model to translate natural language queries into SQL queries, and providing answers based on the execution of the SQL queries.
Configuration¶
Once you’ve instantiated a Semantic Model Query tool, you need to configure the following parameters:
Which semantic model to use
The LLM to use for the agent reasoning and SQL generation
Optionally, an embedding LLM for semantic value matching
Input and output¶
The tool is automatically called by agents, so you don’t usually need to care about its input and output.
It takes a natural query as input, and directly retursns the synthesized answer
Internal details¶
The Semantic Model Query tool is itself an agent, that uses multiple tools under the hood, in order to:
Explore the schema of datasets (get the list of entities, their attributes, the relationships)
Resolve values (i.e. to match user query terms with resolvable attributes to correct typos and find exact values in the data.)
Perform SQL operations (generate, validate and execute SQL). Importantly, it validates that SQL queries only read data (no INSERT/UPDATE/DELETE).
This means that the tool can fetch context dynamically (i.e. all the context in the semantic model isn’t provided in bulk to generate SQL queries, only the minimum context is fetched), making the tool scalable with datasets with a high number of attributes or big semantic models.
The Semantic Model Query Tool follows the following general workflow:
Planning & Metadata Retrieval: The tool starts by exploring the entities, their attributes and relationships relevant to identify information relevant to the user’s query and ensure entities are joined correctly.
Value Resolution & Term Extraction: Maps terms in the user query to the semantic model, to fix typos, ensure values match the database exactly, use business metrics and clarify jargon/acronyms.
SQL Generation: Generates SQL candidates based on the metadata gathered, relationships and resolved values.
Validation & Execution: SQL queries are checked for syntax and security (read-only) before being executed. If the query execution fails, analyzes the error logs and loops back to refine the SQL (up to five times). Synthesizes the data results back into a concise natural language response for the user.