An integration package connecting Snowflake and LangChain
Project description
langchain-snowflake
This package contains the LangChain integration with Snowflake
Installation
pip install -U langchain-snowflake
You can authenticate by one of the following ways:
- Configure credentials by setting the following environment variables:
SNOWFLAKE_USERNAME
should hold your Snowflake username.
SNOWFLAKE_PASSWORD
should hold your Snowflake password.
SNOWFLAKE_DATABASE
should hold a Snowflake database to operate in.
SNOWFLAKE_SCHEMA
should hold the name of the schema to operate in.
SNOWFLAKE_ROLE
should contain the name of the appropriate Snowflake role.
SNOWFLAKE_AUTHENTICATOR
should contain the name of Snowflake authentication method, if not using username/password authentication.
Any of these paramaters can also be passed directly into the CortexSearchRetriever
constructor. Those not passed will be inferred from the environment. For instance:
from langchain_snowflake.search_retriever import CortexSearchRetriever
search = CortexSearchRetriever(
role="snowflake_role",
database="your_db",
schema="your_schema",
service="your_cortex_search_service_name",
search_column="search_column_name",
)
Here, role
, database
, and schema
are passed directly, while SNOWFLAKE_USERNAME
, SNOWFLAKE_PASSWORD
, and SNOWFLAKE_AUTHENTICATOR
are inferred from the environment.
If the SNOWFLAKE_AUTHENTICATOR
environment variable or authenticator
property is set to externalbrowser
, the SNOWFLAKE_PASSWORD
/password
need not be provided. externalbrowser
auth will prompt to log in through an browser popup instead.
- Alternatively, you can pass in a
snowflake.snowpark.Session
directly into the constructor. See the Snowflake docs on how to create such a session.
from langchain_snowflake.search_retriever import CortexSearchRetriever
from snowflake.snowpark import Session
# Create a snowflake session
snowflake_session = Session.builder.config(...).create()
search = CortexSearchRetriever(
session=snowflake_session,
service="your_cortex_search_service_name",
search_column="search_column_name",
)
Search Retriever
CortexSearchRetriever
is a Third Party Retriever that allows users to utilize their Cortex Search Service within Langchain.
Given the service name and columns to search, the retriever will return matches found within the dataset with which the Cortex Search Service is associated.
from langchain_snowflake.search_retriever import CortexSearchRetriever
search = CortexSearchRetriever(
service="your_cortex_search_service_name",
search_column="<search_column_name>",
columns=["<col1>", "<col2>"],
filter={"@eq": {"<column>": "<value>"}},
limit=5
)
query="foo bar"
result = search.invoke(query)
for doc in result:
print(doc)
The class requires the arguments below:
service
corresponds to the name of your Cortex Search Service.
search_column
is the search column of the Cortex Search Service.
columns
corresponds to the columns to return in the search. If null or an empty list, only the search_column
will be returned.
filter
is an optional argument corresponding to any filters that should be utilized when searching.
limit
corresponds to the number of search hits to return.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file langchain_snowflake-0.1.1.tar.gz
.
File metadata
- Download URL: langchain_snowflake-0.1.1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a40f27194e49bc5da7eadc685ba2e01cea382f4036b7982c457b09a4ae95a9c3 |
|
MD5 | 3f41c372ba671778bd4b3e8cb1073871 |
|
BLAKE2b-256 | 42d0910c37c6c9a076cd647969364687ddf638bb2b96086bdfb9e3cc3355a2b5 |
File details
Details for the file langchain_snowflake-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: langchain_snowflake-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ad190ca0a8a8be86bde480fc5c17458eb71283f5fa7d1593839d6d4b72ee414 |
|
MD5 | dd292aabcceb000a85e1bc5b308f39b2 |
|
BLAKE2b-256 | a64b675c0523131356591b46be217226d3ecce953b7c48d3f9bdea7aa059cd76 |