WatsonxSQLDatabase#
- class langchain_ibm.utilities.sql_database.WatsonxSQLDatabase(
- *,
- connection_id: str,
- schema: str,
- project_id: str | None = None,
- space_id: str | None = None,
- url: str | None = None,
- apikey: str | None = None,
- token: str | None = None,
- password: str | None = None,
- username: str | None = None,
- instance_id: str | None = None,
- version: str | None = None,
- verify: str | bool | None = None,
- watsonx_client: APIClient | None = None,
- ignore_tables: List[str] | None = None,
- include_tables: List[str] | None = None,
- sample_rows_in_table_info: int = 3,
- max_string_length: int = 300,
Watsonx SQL Database class for IBM watsonx.ai databases connection assets. Uses Arrow Flight to interact with databases via watsonx.
- Parameters:
connection_id (str) โ ID of db connection asset
schema (str) โ name of the database schema from which tables will be read
project_id (Optional[str], optional) โ ID of project, defaults to None
space_id (Optional[str], optional) โ ID of space, defaults to None
url (Optional[str], optional) โ URL to the Watson Machine Learning or CPD instance, defaults to None
apikey (Optional[str], optional) โ API key to the Watson Machine Learning or CPD instance, defaults to None
token (Optional[str], optional) โ service token, used in token authentication, defaults to None
password (Optional[str], optional) โ password to the CPD instance., defaults to None
username (Optional[str], optional) โ username to the CPD instance., defaults to None
instance_id (Optional[str], optional) โ instance_id of the CPD instance., defaults to None
version (Optional[str], optional) โ version of the CPD instance, defaults to None
verify (Union[str, bool, None], optional) โ certificate verification flag, defaults to None
watsonx_client (Optional[APIClient], optional) โ instance of ibm_watsonx_ai.APIClient, defaults to None
ignore_tables (Optional[List[str]], optional) โ list of tables that will be ignored, defaults to None
include_tables (Optional[List[str]], optional) โ list of tables that should be included, defaults to None
sample_rows_in_table_info (int, optional) โ number of first rows to be added to the table info, defaults to 3
max_string_length (int, optional) โ max length of string, defaults to 300
- Raises:
ValueError โ raise if some required credentials are missing
RuntimeError โ raise if no tables found in given schema
Methods
__init__
(*,ย connection_id,ย schema[,ย ...])Return db context that you may want in agent prompt.
get_table_info
([table_names])Get information about specified tables.
get_table_info_no_throw
([table_names])Get information about specified tables.
Get names of tables available.
run
(command[,ย include_columns])Execute a SQL command and return a string representing the results.
run_no_throw
(command[,ย include_columns])Execute a SQL command and return a string representing the results.
- __init__(
- *,
- connection_id: str,
- schema: str,
- project_id: str | None = None,
- space_id: str | None = None,
- url: str | None = None,
- apikey: str | None = None,
- token: str | None = None,
- password: str | None = None,
- username: str | None = None,
- instance_id: str | None = None,
- version: str | None = None,
- verify: str | bool | None = None,
- watsonx_client: APIClient | None = None,
- ignore_tables: List[str] | None = None,
- include_tables: List[str] | None = None,
- sample_rows_in_table_info: int = 3,
- max_string_length: int = 300,
- Parameters:
connection_id (str)
schema (str)
project_id (str | None)
space_id (str | None)
url (str | None)
apikey (str | None)
token (str | None)
password (str | None)
username (str | None)
instance_id (str | None)
version (str | None)
verify (str | bool | None)
watsonx_client (APIClient | None)
ignore_tables (List[str] | None)
include_tables (List[str] | None)
sample_rows_in_table_info (int)
max_string_length (int)
- Return type:
None
- get_context() Dict[str, Any] [source]#
Return db context that you may want in agent prompt.
- Return type:
Dict[str, Any]
- get_table_info(
- table_names: Iterable[str] | None = None,
Get information about specified tables.
- Parameters:
table_names (Iterable[str] | None)
- Return type:
str
- get_table_info_no_throw(
- table_names: Iterable[str] | None = None,
Get information about specified tables.
- Parameters:
table_names (Iterable[str] | None)
- Return type:
str
- get_usable_table_names() Iterable[str] [source]#
Get names of tables available.
- Return type:
Iterable[str]