QueryCatalog
relationalai.agent.cortex.queries
QueryCatalog(*query_funcs: Callable)Query provider that registers Python functions as executable queries.
Extracts metadata from Python callables (functions, methods) including their docstrings, type annotations, and source code. This metadata is exposed to Cortex agents for query discovery, while the functions remain executable for query execution.
Query functions should follow these conventions:
- Return type: Must return either
rai.Fragmentorpandas.DataFrame - Parameters: Can have any parameters with type annotations (recommended)
- Docstring: Should include a clear description of what the query does
- Function name: Will be used as the query ID (e.g.,
"top_customers")
Parameters
Section titled “Parameters”
(*query_funcsCallable, default:()) - Variable number of Python callables to register as queries.
Examples
Section titled “Examples”>>> from functools import partial>>> def top_customers(model, limit=10):... return model.query(...)>>> queries = QueryCatalog(partial(top_customers, jaffle_model))Methods
Section titled “Methods”.get_available_queries()
Section titled “.get_available_queries()”QueryCatalog.get_available_queries() -> dictReturn metadata for all registered queries.
Returns:
dict- Dict with"queries"and"query_instructions"keys.
.explain()
Section titled “.explain()”QueryCatalog.explain(query_id: str) -> Optional[str]Return source code for a registered query by ID.
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()”QueryCatalog.execute(query_id: str, args: dict) -> Union[rai.Fragment, pandas.DataFrame]Execute a registered query by ID.
Parameters:
(query_idstr) - ID of the query to execute.
(argsdict) - Arguments to pass to the query function.
Returns:
relationalai.semantics.Fragment or pandas.DataFrame- Query results.
Raises:
KeyError- Ifquery_idis not registered.