SnowflakeTableRetriever
连接到 Snowflake 数据库以执行 SQL 查询。
| pipeline 中的最常见位置 | 在 PromptBuilder 之前 |
| 必需的初始化变量 | “user”: 用户的登录名 “account”: Snowflake 账户标识符 “api_key”: Snowflake 账户密码。可以通过 SNOWFLAKE_API_KEY 环境变量设置 |
| 强制运行变量 | “query”: 要执行的 SQL 查询 |
| 输出变量 | “dataframe”: 结果 Pandas DataFrame 格式的表 |
| API 参考 | Snowflake |
| GitHub 链接 | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/snowflake |
概述
该SnowflakeTableRetriever 连接到 Snowflake 数据库并通过 SQL 查询检索数据。然后,它返回一个 Pandas DataFrame 和一个 Markdown 格式的表。
要开始使用该集成,请通过以下方式安装它:
pip install snowflake-haystack
用法
单独使用
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;"""")
在 pipeline 中
在下面的管道示例中,PromptBuilder 使用从SnowflakeTableRetriever 收到的表来创建提示模板并将其传递给 LLM。
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;"})
更新于 大约 1 年前
