SnowflakeTableRetriever
SnowflakeTableRetriever
SnowflakeTableRetriever 는 Snowflake 데이터베이스에 연결해 SQL 쿼리를 실행하는 컴포넌트예요. 쿼리 결과를 Pandas 데이터프레임과 마크다운 문자열로 돌려줘서, 그대로 LLM에 넣거나 표로 활용할 수 있어요.
출처: 문서
본문
개요 (Overview)
SnowflakeTableRetriever 는 Snowflake 데이터베이스에 연결하고 SQL 쿼리로 데이터를 조회해요. 결과로 Pandas 데이터프레임과 테이블의 마크다운 버전을 반환해요.
통합을 쓰려면 먼저 설치해야 해요:
pip install snowflake-haystack
사용법 (Usage)
단독으로 쓰기
from haystack.utils import Secret
from haystack_integrations.components.retrievers.snowflake import (
SnowflakeTableRetriever,
)
snowflake = SnowflakeTableRetriever(
user="",
account="",
api_key=Secret.from_env_var("SNOWFLAKE_API_KEY"),
warehouse="",
)
snowflake.run(query="select * from table limit 10;")
파이프라인에서 쓰기
아래 파이프라인 예시에서는 ChatPromptBuilder 가 SnowflakeTableRetriever 로부터 받은 테이블을 이용해 프롬프트를 만들고 LLM에 넘겨요:
from haystack import Pipeline
from haystack.utils import Secret
from haystack.components.builders import ChatPromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.retrievers.snowflake import (
SnowflakeTableRetriever,
)
executor = SnowflakeTableRetriever(
user="",
account="",
api_key=Secret.from_env_var("SNOWFLAKE_API_KEY"),
warehouse="",
)
pipeline = Pipeline()
pipeline.add_component(
"builder",
ChatPromptBuilder(
template=[ChatMessage.from_user("Describe this table: {{ table }}")],
required_variables="*",
),
)
pipeline.add_component("snowflake", executor)
pipeline.add_component("llm", OpenAIChatGenerator(model="gpt-4o"))
pipeline.connect("snowflake.table", "builder.table")
pipeline.connect("builder.prompt", "llm.messages")
pipeline.run(data={"query": "select employee, salary from table limit 10;"})
더 알아보기 (Learn more)
- PromptBuilder — 조회한 테이블을 프롬프트에 넣는 빌더
- Snowflake API 참조
- GitHub 저장소