Queries
Abstract base class for managing pre-defined RAI queries.
Queries provide a registry of pre-built query functions that Cortex agents can discover and execute. This allows domain experts to define common analytical queries that agents can use without writing RAI code.
Implement this interface to create custom query providers, or use
QueryCatalog for standard Python function-based queries.
Methods
Section titled “Methods”.get_available_queries()
Section titled “.get_available_queries()”Queries.get_available_queries() -> dictReturn metadata about available queries.
Returns:
dict- Dictionary with the following keys:-
queries:dictMapping from a query ID to a query metadata dictionary. Each query metadata dictionary contains:id:strUnique query identifier.description:strHuman-readable description of the query.args:dictMapping from parameter name to parameter type.
-
query_instructions:strInstructions describing how to use the catalog.
-
.explain()
Section titled “.explain()”Queries.explain(query_id: str) -> Optional[str]Return source code for a query by ID, or None if not found.
Parameters:
(query_idstr) - Unique identifier for the query to explain.
Returns:
str or None- Source code string, orNoneif the query ID is not found.
.execute()
Section titled “.execute()”Queries.execute(query_id: str, args: dict) -> Union[rai.Fragment, pandas.DataFrame]Execute a specific query by ID with provided arguments.
Parameters:
(query_idstr) - Unique identifier for the query to execute (e.g.,"top_customers").
(argsdict) - Dictionary mapping parameter names to values (e.g.,{"limit": 5, "days": 30}).
Returns:
Fragment|pandas.DataFrame- Query results.
Raises:
KeyError- If thequery_idis not found in registered queries.
Inheritance Hierarchy
Section titled “Inheritance Hierarchy”Subclassed By
Section titled “Subclassed By”agent > cortex > queries └── QueryCatalog
Used By
Section titled “Used By”agent > cortex > tool ├── DefaultTool └── ToolRegistry └── add