Files
wehub-resource-sync c56bef871b
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
Docker image release / Build base image (push) Has been cancelled
Sync docs with Docusaurus / sync (push) Has been cancelled
Tests / Check if changed (push) Has been cancelled
Tests / format (push) Has been cancelled
Tests / check-imports (push) Has been cancelled
Tests / Unit / macos-latest (push) Has been cancelled
Tests / Unit / ubuntu-latest (push) Has been cancelled
Tests / Unit / windows-latest (push) Has been cancelled
Tests / mypy (push) Has been cancelled
Tests / Integration / ubuntu-latest (push) Has been cancelled
Tests / Integration / macos-latest (push) Has been cancelled
Tests / Integration / windows-latest (push) Has been cancelled
Tests / notify-slack-on-failure (push) Has been cancelled
Tests / Mark tests as completed (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:22:28 +08:00

85 lines
2.7 KiB
Plaintext

---
title: "SnowflakeTableRetriever"
id: snowflaketableretriever
slug: "/snowflaketableretriever"
description: "Connects to a Snowflake database to execute an SQL query."
---
# SnowflakeTableRetriever
Connects to a Snowflake database to execute an SQL query.
<div className="key-value-table">
| | |
| --- | --- |
| **Most common position in a pipeline** | Before a [`PromptBuilder`](../builders/promptbuilder.mdx) |
| **Mandatory init variables** | `user`: User's login <br /> <br />`account`: Snowflake account identifier <br /> <br />`api_key`: Snowflake account password. Can be set with `SNOWFLAKE_API_KEY` env var |
| **Mandatory run variables** | `query`: An SQL query to execute |
| **Output variables** | `dataframe`: The resulting Pandas dataframe version of the table |
| **API reference** | [Snowflake](/reference/integrations-snowflake) |
| **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/snowflake |
</div>
## Overview
The `SnowflakeTableRetriever` connects to a Snowflake database and retrieves data using an SQL query. It then returns a Pandas dataframe and a Markdown version of the table:
To start using the integration, install it with:
```bash
pip install snowflake-haystack
```
## Usage
### On its own
```python
from haystack_integrations.components.retrievers.snowflake import SnowflakeTableRetriever
snowflake = SnowflakeRetriever(
user="<ACCOUNT-USER>",
account="<ACCOUNT-IDENTIFIER>",
api_key=Secret.from_env_var("SNOWFLAKE_API_KEY"),
warehouse="<WAREHOUSE-NAME>",
)
snowflake.run(query="""select * from table limit 10;"""")
```
### In a pipeline
In the following pipeline example, the `PromptBuilder` is using the table received from the `SnowflakeTableRetriever` to create a prompt template and pass it on to an LLM:
```python
from haystack import Pipeline
from haystack.utils import Secret
from haystack.components.builders import PromptBuilder
from haystack.components.generators import OpenAIGenerator
from haystack_integrations.components.retrievers.snowflake import (
SnowflakeTableRetriever,
)
executor = SnowflakeTableRetriever(
user="<ACCOUNT-USER>",
account="<ACCOUNT-IDENTIFIER>",
api_key=Secret.from_env_var("SNOWFLAKE_API_KEY"),
warehouse="<WAREHOUSE-NAME>",
)
pipeline = Pipeline()
pipeline.add_component(
"builder",
PromptBuilder(template="Describe this table: {{ table }}"),
)
pipeline.add_component("snowflake", executor)
pipeline.add_component("llm", OpenAIGenerator(model="gpt-4o"))
pipeline.connect("snowflake.table", "builder.table")
pipeline.connect("builder", "llm")
pipeline.run(data={"query": "select employee, salary from table limit 10;"})
```