SnowflakeSearchTool
Description
TheSnowflakeSearchTool
is designed to connect to Snowflake data warehouses and execute SQL queries with advanced features like connection pooling, retry logic, and asynchronous execution. This tool allows CrewAI agents to interact with Snowflake databases, making it ideal for data analysis, reporting, and business intelligence tasks that require access to enterprise data stored in Snowflake.
Installation
To use this tool, you need to install the required dependencies:Steps to Get Started
To effectively use theSnowflakeSearchTool
, follow these steps:
- Install Dependencies: Install the required packages using one of the commands above.
- Configure Snowflake Connection: Create a
SnowflakeConfig
object with your Snowflake credentials. - Initialize the Tool: Create an instance of the tool with the necessary configuration.
- Execute Queries: Use the tool to run SQL queries against your Snowflake database.
Example
The following example demonstrates how to use theSnowflakeSearchTool
to query data from a Snowflake database:
Code
Code
Parameters
SnowflakeConfig Parameters
TheSnowflakeConfig
class accepts the following parameters:
- account: Required. Snowflake account identifier.
- user: Required. Snowflake username.
- password: Optional*. Snowflake password.
- private_key_path: Optional*. Path to private key file (alternative to password).
- warehouse: Required. Snowflake warehouse name.
- database: Required. Default database.
- snowflake_schema: Required. Default schema.
- role: Optional. Snowflake role.
- session_parameters: Optional. Custom session parameters as a dictionary.
password
or private_key_path
must be provided.
SnowflakeSearchTool Parameters
TheSnowflakeSearchTool
accepts the following parameters during initialization:
- config: Required. A
SnowflakeConfig
object containing connection details. - pool_size: Optional. Number of connections in the pool. Default is 5.
- max_retries: Optional. Maximum retry attempts for failed queries. Default is 3.
- retry_delay: Optional. Delay between retries in seconds. Default is 1.0.
- enable_caching: Optional. Whether to enable query result caching. Default is True.
Usage
When using theSnowflakeSearchTool
, you need to provide the following parameters:
- query: Required. The SQL query to execute.
- database: Optional. Override the default database specified in the config.
- snowflake_schema: Optional. Override the default schema specified in the config.
- timeout: Optional. Query timeout in seconds. Default is 300.
Code
Advanced Features
Connection Pooling
TheSnowflakeSearchTool
implements connection pooling to improve performance by reusing database connections. You can control the pool size with the pool_size
parameter.
Automatic Retries
The tool automatically retries failed queries with exponential backoff. You can configure the retry behavior with themax_retries
and retry_delay
parameters.
Query Result Caching
To improve performance for repeated queries, the tool can cache query results. This feature is enabled by default but can be disabled by settingenable_caching=False
.
Key-Pair Authentication
In addition to password authentication, the tool supports key-pair authentication for enhanced security:Code
Error Handling
TheSnowflakeSearchTool
includes comprehensive error handling for common Snowflake issues:
- Connection failures
- Query timeouts
- Authentication errors
- Database and schema errors
Conclusion
TheSnowflakeSearchTool
provides a powerful way to integrate Snowflake data warehouses with CrewAI agents. With features like connection pooling, automatic retries, and query caching, it enables efficient and reliable access to enterprise data. This tool is particularly useful for data analysis, reporting, and business intelligence tasks that require access to structured data stored in Snowflake.