https://github.com/snowflake-labs/snowflake-ai-toolkit
Snowflake AI Toolkit is an AI Accelerator and Playground for enabling AI in Snowflake. It is an Plug and Play Streamlit based Native App that can be used to explore, learn and build rapid prototypes of AI Solutions in Snowflake powered by the Snowflake's Cortex and AI Functions.
https://github.com/snowflake-labs/snowflake-ai-toolkit
Last synced: about 1 year ago
JSON representation
Snowflake AI Toolkit is an AI Accelerator and Playground for enabling AI in Snowflake. It is an Plug and Play Streamlit based Native App that can be used to explore, learn and build rapid prototypes of AI Solutions in Snowflake powered by the Snowflake's Cortex and AI Functions.
- Host: GitHub
- URL: https://github.com/snowflake-labs/snowflake-ai-toolkit
- Owner: Snowflake-Labs
- License: apache-2.0
- Created: 2024-12-08T04:07:51.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-01T03:25:14.000Z (over 1 year ago)
- Last Synced: 2025-04-04T06:06:05.072Z (about 1 year ago)
- Language: Python
- Size: 20.9 MB
- Stars: 245
- Watchers: 2
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Snowflake AI Toolkit
Snowflake AI Toolkit is an AI Accelerator and Playground for enabling AI in Snowflake. It is an Plug and Play Streamlit based Native App that can be used to explore, learn and build rapid prototypes of AI Solutions in Snowflake powered by the Snowflake's Cortex and AI Functions.
# Features
### Playground
An interactive environment where users can chat and experiment with Snowflake Cortex functions, test prompts, and and play around with cortex functions.
### Build
A dedicated section for constructing and deploying data pipelines and workflows using Snowflake Cortex's powerful AI capabilities, enabling seamless integration with your Snowflake databases and tables
- Text completion and generation using the COMPLETE function
- Retrieval-Augmented Generation (RAG) for question answering with your own data
- Fine-tuning large language models on your custom datasets
### Search
Get a hybrid (vector and keyword) search engine on your text data in minutes,
- Create and manage Cortex Search Service
- Use Cortex Search for your RAG Application
- Use Cortex Search Powered Chat
### Agent
Cortex Agents orchestrate across both structured and unstructured data sources to deliver insights.
- Create and Manage Cortex Agent Instances
- Test the Agent against the Data
- Utilize Cortex Search and Cortex Analyst through Agents
## Prerequisites
Before you begin, ensure you have met the following requirements:
- **Snowflake Account**: Ensure you have an active Snowflake account in a region where Cortex functionalities are supported. For detailed information, refer to the [Availability Region documentation](https://docs.snowflake.com/en/user-guide/snowflake-cortex/llm-functions#availability).
- **Private Preview Access**: To try private preview models in Snowflake, you need to contact your Snowflake account team to request access to the private preview feature.
- **Role Permissions**: ACCOUNTADMIN or equivalent role with permissions to create:
- Stages
- Databases
- Other resources
- **Python**: Version 3.7 or higher.
- **Streamlit**: Installed on your local machine.
- **Snowflake-CLI** : Install snowflake-cli through pip
## Installation
1. Clone the repository:
```bash
git clone https://github.com/sgsshankar/Snowflake-AI-Toolkit.git
cd snowflake-ai-toolkit
```
2. Install dependencies (only required for local development):
```bash
pip install -r requirements.txt
```
All necessary libraries are listed in `requirements.txt`.
## Setup
The application will automatically handle:
- Database creation
- Stage setup
- Required resource initialization
Make sure your Snowflake role has the necessary privileges for these operations.
To configure the application mode, update the `mode` parameter in `src/settings_config.json`:
- Set to `"debug"` for local development and editing.
- Set to `"native"` for running natively in Snowflake.
### Authentication for Cortex Agent – JWT Token Support Only
This app currently supports **only JWT-based authentication** using RSA key pairs for Cortex Agents. OAuth is **not supported** at this time.
#### Step 1: Generate RSA Key Pair
```bash
openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_private_key.p8 -nocrypt
openssl rsa -in rsa_private_key.p8 -pubout -out rsa_public_key.pub
```
#### Step 2: Upload Public Key to Snowflake
1. Copy the content from `rsa_public_key.pub` (exclude `-----BEGIN PUBLIC KEY-----` headers).
2. In Snowflake, run:
```sql
alter user set rsa_public_key='';
```
3. Retrieve the public key fingerprint:
```sql
desc user ;
```
Use the fingerprint in `rsa_public_key_fp`.
#### Step 3: Add to `settings_config.json`
- Paste full contents of `rsa_private_key.p8` into `rsa_private_key` (escape newlines if needed).
- Paste fingerprint into `rsa_public_key_fp`.
For more details, refer to the [Snowflake documentation](https://docs.snowflake.com/en/user-guide/key-pair-auth.html#using-key-pair-authentication).
## Running the App
### Locally
Launch the application locally using:
```bash
streamlit run streamlit_app.py
```
### Natively on Snowflake
To deploy the application natively in Snowflake, use the following command:
```bash
snow streamlit deploy --account "" --user "" --password "" --role "" --warehouse "" --database "" --replace
```
Replace the placeholders (``, ``, etc.) with your actual Snowflake account details. When running natively in Snowflake, installing dependencies from `requirements.txt` is not needed.
## Project Structure
| File/Directory | Description |
|-------------------------------------|--------------------------------------------------|
| [src/](src/) | Source code for setup and styling |
| [src/setup.py](src/setup.py) | Setup and initialization code |
| [src/styles.css](src/styles.css) | Custom styling |
| [src/build.py](src/build.py) | Build mode functionality |
| [src/cortex_functions.py](src/cortex_functions.py) | Core functions for Cortex operations |
| [src/query_result_builder.py](src/query_result_builder.py) | Query result handling and display |
| [src/playground.py](src/playground.py) | Playground mode functionality |
| [src/rag.py](src/rag.py) | RAG mode functionality |
| [src/fine_tune.py](src/fine_tune.py) | Fine-tuning functionality |
| [src/search.py](src/search.py) | Cortex Search Functionality |
| [.gitignore](.gitignore) | Git ignore file |
| [requirements.txt](requirements.txt)| Project dependencies |
| [streamlit_app.py](streamlit_app.py)| Main application entry point |
## Troubleshooting
Common issues and solutions:
1. **Snowflake Permission Errors**
- Verify role privileges for database and stage creation
- Ensure Cortex functionalities are enabled
2. **Dependency Issues**
- If pandas/pyarrow installation fails:
```bash
pip install pandas pyarrow
```
3. **Connection Issues**
- Verify Snowflake account credentials
- Check network connectivity
- Ensure proper role assignments
## Contributing
We welcome contributions! Please:
1. Fork the repository
2. Create a feature branch
3. Submit a pull request
## Support
For assistance:
- Open an issue in the GitHub repository
- Contact project maintainers
- Check documentation for common solutions
## Warranty
The Software is provided as Open Source. This software is provided “as is” and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
## Legal
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this tool except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This is an Open Source repository and not an official Snowflake offering. This tool is not endorsed by Snowflake or any of the previous or current employers of the developers.
## Trademarks
This project may contain trademarks or logos for projects, products, or services. SNOWFLAKE is a trademark of Snowflake Computing, Inc in the United States and/or other countries. Any use of third-party trademarks or logos are subject to those third-party's policies.