Skip to main content

SnowflakeSearchTool

Description

The SnowflakeSearchTool 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:
Or alternatively:

Steps to Get Started

To effectively use the SnowflakeSearchTool, follow these steps:
  1. Install Dependencies: Install the required packages using one of the commands above.
  2. Configure Snowflake Connection: Create a SnowflakeConfig object with your Snowflake credentials.
  3. Initialize the Tool: Create an instance of the tool with the necessary configuration.
  4. Execute Queries: Use the tool to run SQL queries against your Snowflake database.

Example

The following example demonstrates how to use the SnowflakeSearchTool to query data from a Snowflake database:
Code
You can also customize the tool with additional parameters:
Code

Parameters

SnowflakeConfig Parameters

The SnowflakeConfig 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.
*Either password or private_key_path must be provided.

SnowflakeSearchTool Parameters

The SnowflakeSearchTool 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 the SnowflakeSearchTool, 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.
The tool will return the query results as a list of dictionaries, where each dictionary represents a row with column names as keys.
Code

Advanced Features

Connection Pooling

The SnowflakeSearchTool 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 the max_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 setting enable_caching=False.

Key-Pair Authentication

In addition to password authentication, the tool supports key-pair authentication for enhanced security:
Code

Error Handling

The SnowflakeSearchTool includes comprehensive error handling for common Snowflake issues:
  • Connection failures
  • Query timeouts
  • Authentication errors
  • Database and schema errors
When an error occurs, the tool will attempt to retry the operation (if configured) and provide detailed error information.

Conclusion

The SnowflakeSearchTool 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.