LlamaIndex Llms Integration: Cortex
Overview
Integrate with Snowflake Cortex API. 3 ways to authenticate:
-
Snowpark Session object (recommended way) this allows authentication via Snowpark Container Services default token, via Oauth, password, private key, web browser, or any other method.
Guide to creating sessions: https://docs.snowflake.com/en/developer-guide/snowpark/python/creating-session
-
Path to a private key file. Encrypted private keys unsupported. For encrypted keys: use a Snowpark Session instead, with the 'private_key_file_pwd' parameter.
-
JWT token
Installation
pip install llama-index-llms-cortex
Example using a Private Key
import os
from llama_index.llms.cortex import Cortex
llm = Cortex(
model="llama3.2-1b",
user=os.environ["YOUR_SF_USER"],
account=os.environ["YOUR_SF_ACCOUNT"],
private_key_file=os.environ["PATH_TO_SF_PRIVATE_KEY"],
)
completion_response = llm.complete(
"write me a haiku about a snowflake", temperature=0.0
)
print(completion_response)
Example Using a Session
import os
from snowflake.snowpark import Session
from llama_index.llms.cortex import Cortex
connection_parameters = {
"account": "<your snowflake account>",
"user": "<your snowflake user>",
"role": "<your snowflake role>",
"database": "<your snowflake database>",
"schema": "<your snowflake schema",
"warehouse": "<your snowflake warehouse>",
"private_key_file": "<path to file>",
"authenticator": "JWT_AUTHENTICATOR", # use this for private key
}
session = Session.builder.configs(connection_parameters).create()
llm = Cortex(
model="llama3.2-1b",
user=os.environ["YOUR_SF_USER"],
account=os.environ["YOUR_SF_ACCOUNT"],
session=session,
)
completion_response = llm.complete(
"write me a haiku about a snowflake", temperature=0.0
)
print(completion_response)
Connect in an SPCS environment
# That's it! That's all we need.
llm = Cortex(model="llama3.2-1b")
completion_response = llm.complete(
"write me a haiku about a snowflake", temperature=0.0
)
print(completion_response)
Create a session within an SPCS environment
import os
from snowflake.snowpark import Session
from llama_index.llms.cortex import Cortex
from llama_index.llms.cortex import utils as cortex_utils
#! Note now the user and role parameters are left blank for SPCS !
connection_parameters = {
"account": "<your snowflake account>",
"database": "<your snowflake database>",
"schema": "<your snowflake schema",
"warehouse": "<your snowflake warehouse>",
"token": cortex_utils.get_default_spcs_token(),
"host": cortex_utils.get_spcs_base_url(),
"authenticator": "OAUTH",
}
session = Session.builder.configs(connection_parameters).create()
llm = Cortex(model="llama3.2-1b", session=session)
completion_response = llm.complete(
"write me a haiku about a snowflake", temperature=0.0
)
print(completion_response)
TODO
1 snowflake token counting 2 Pull metadata for snowflake models from Snowflake official documentation (support ticket is out, they said they'll get back to me 4-20-2025)
Metadata
Release files for llama-index-llms-cortex 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llama_index_llms_cortex-0.5.0.tar.gz | 9.1 kB | Without provenance | Details for llama_index_llms_cortex-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llama_index_llms_cortex-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for llama_index_llms_cortex-0.5.0-py3-none-any.whl |
Total release size: 18.2 kB
Release files / llama_index_llms_cortex-0.5.0.tar.gz
| Download URL | llama_index_llms_cortex-0.5.0.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f2575cd97c32863082bc5d4a39e088191c33192aa6a0e0171963230d11a07c7
|
|
BLAKE2b-256 checksum How to use checksums |
3f769b22b4ed4ada8737142dd9a8edd94a7616f785b942a474f733e6ac80319d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / llama_index_llms_cortex-0.5.0-py3-none-any.whl
| Download URL | llama_index_llms_cortex-0.5.0-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3a33a62e2f6cb22cd31910ca24900c95388e58dd3872f56ff4e48cebf07a48f
|
|
BLAKE2b-256 checksum How to use checksums |
2de237438ff9ddf65c14a823366e495af41aa7e8c70000f963bdc22b2fbe3b46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for llama-index-llms-cortex 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.