airflow.providers.common.ai.utils.sql_search¶
Table search for SQLToolset.
Attributes¶
Classes¶
Finds tables relevant to a free-text query, for the |
|
Default backend: case-insensitive substring match of each query word against table names (without their schema) and comments. |
Module Contents¶
- class airflow.providers.common.ai.utils.sql_search.SQLTableSearchBackend[source]¶
Bases:
ProtocolFinds tables relevant to a free-text query, for the
search_tablestool.The toolset filters whatever a backend returns through
allowed_tablesbefore the agent sees it, so a backend that knows about more tables than the agent may use cannot widen access. It can still waste its ownlimit, so an index built for the agent should cover only the tables the agent may use.- search_tables(query, limit, *, get_catalog)[source]¶
Return up to
limittables, best match first.- Parameters:
query (str) – The agent’s free-text query.
limit (int) – Maximum number of results wanted.
get_catalog (collections.abc.Callable[[], collections.abc.Sequence[TableEntry]]) – Lists the tables the toolset exposes, introspected with the same connection the agent queries with and cached for the toolset’s lifetime. Comments are the full text, not cut to the length the agent sees, with the secrets Airflow has registered already masked as
***; the toolset cuts comments when it returns them to the agent. A backend with its own index (a vector store, a search service) ignores it.
- class airflow.providers.common.ai.utils.sql_search.KeywordTableSearchBackend[source]¶
Default backend: case-insensitive substring match of each query word against table names (without their schema) and comments.
Query words are split on whitespace. A table’s score is the number of words found in its table name (the part after any schema) weighted at
_NAME_WEIGHTplus the number found in its comment; tables scoring zero are dropped, and ties are broken by name.