/ docs-website / docs / pipeline-components / retrievers / snowflaketableretriever.mdx
snowflaketableretriever.mdx
 1  ---
 2  title: "SnowflakeTableRetriever"
 3  id: snowflaketableretriever
 4  slug: "/snowflaketableretriever"
 5  description: "Connects to a Snowflake database to execute an SQL query."
 6  ---
 7  
 8  # SnowflakeTableRetriever
 9  
10  Connects to a Snowflake database to execute an SQL query.
11  
12  <div className="key-value-table">
13  
14  |  |  |
15  | --- | --- |
16  | **Most common position in a pipeline** | Before a [`PromptBuilder`](../builders/promptbuilder.mdx) |
17  | **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 |
18  | **Mandatory run variables** | `query`: An SQL query to execute |
19  | **Output variables** | `dataframe`: The resulting Pandas dataframe version of the table |
20  | **API reference** | [Snowflake](/reference/integrations-snowflake) |
21  | **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/snowflake |
22  
23  </div>
24  
25  ## Overview
26  
27  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:
28  
29  To start using the integration, install it with:
30  
31  ```bash
32  pip install snowflake-haystack
33  ```
34  
35  ## Usage
36  
37  ### On its own
38  
39  ```python
40  from haystack_integrations.components.retrievers.snowflake import SnowflakeTableRetriever
41  
42  snowflake = SnowflakeRetriever(
43      user="<ACCOUNT-USER>",
44      account="<ACCOUNT-IDENTIFIER>",
45      api_key=Secret.from_env_var("SNOWFLAKE_API_KEY"),
46      warehouse="<WAREHOUSE-NAME>",
47  )
48  
49  snowflake.run(query="""select * from table limit 10;"""")
50  ```
51  
52  ### In a pipeline
53  
54  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:
55  
56  ```python
57  from haystack import Pipeline
58  from haystack.utils import Secret
59  from haystack.components.builders import PromptBuilder
60  from haystack.components.generators import OpenAIGenerator
61  from haystack_integrations.components.retrievers.snowflake import (
62      SnowflakeTableRetriever,
63  )
64  
65  executor = SnowflakeTableRetriever(
66      user="<ACCOUNT-USER>",
67      account="<ACCOUNT-IDENTIFIER>",
68      api_key=Secret.from_env_var("SNOWFLAKE_API_KEY"),
69      warehouse="<WAREHOUSE-NAME>",
70  )
71  
72  pipeline = Pipeline()
73  pipeline.add_component(
74      "builder",
75      PromptBuilder(template="Describe this table: {{ table }}"),
76  )
77  pipeline.add_component("snowflake", executor)
78  pipeline.add_component("llm", OpenAIGenerator(model="gpt-4o"))
79  
80  pipeline.connect("snowflake.table", "builder.table")
81  pipeline.connect("builder", "llm")
82  
83  pipeline.run(data={"query": "select employee, salary from table limit 10;"})
84  ```