Large Language Model (LLM)-Funktionen (Snowflake Cortex)¶
Snowflake Cortex gives you instant access to industry-leading large language models (LLMs) trained by researchers at companies like Mistral, Meta, and Google. It also offers models that Snowflake has fine-tuned for specific use cases.
Da diese LLMs vollständig von Snowflake gehostet und verwaltet werden, ist für ihre Nutzung keine spezielle Einrichtung erforderlich. Ihre Daten bleiben in Snowflake und bieten Ihnen die Leistung, Skalierbarkeit und Governance, die Sie erwarten.
Snowflake Cortex-Features werden als SQL-Funktionen bereitgestellt und sind auch in Python verfügbar. Die verfügbaren Funktionen sind im Folgenden zusammengefasst.
COMPLETE: Gibt zu einem Prompt eine Antwort zurück, die den Prompt abschließt (vervollständigt). Diese Funktion akzeptiert entweder einen einzelnen Prompt oder eine Konversation aus mehreren Prompts und Antworten.
EXTRACT_ANSWER: Gibt bei einer Frage und unstrukturierten Daten die Antwort auf die Frage zurück, wenn sie in den Daten gefunden werden kann.
SENTIMENT: Gibt einen Stimmungswert zwischen -1 und 1 zurück, der die erkannte positive oder negative Stimmung des gegebenen Textes darstellt.
SUMMARIZE: Gibt eine Zusammenfassung des gegebenen Textes zurück.
TRANSLATE: Übersetzt einen gegebenen Text aus einer beliebigen unterstützten Sprache in eine andere.
Erforderliche Berechtigungen¶
The CORTEX_USER database role in the SNOWFLAKE database includes the privileges that allow users to call Snowflake Cortex LLM functions. By default, this database role is granted to only the ACCOUNTADMIN role. ACCOUNTADMIN must propagate this role to user roles in order to allow users to access Cortex LLM Functions.
The SNOWFLAKE.CORTEX_USER database role cannot be granted directly to a user. A user with the ACCOUNTADMIN role must first grant it to an account role, and then grant the account role to users. For more information, see Verwenden von SNOWFLAKE-Datenbankrollen.
In the following example, you assume ACCOUNTADMIN and grant the user some_user
the CORTEX_USER database role via the
account role cortex_user_role
, which you create for this purpose.
USE ROLE ACCOUNTADMIN;
CREATE ROLE cortex_user_role;
GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE cortex_user_role;
GRANT ROLE cortex_user_role TO USER some_user;
Sie können den Zugriff auf die Snowflake Cortex-LLM-Funktionen auch über bestehende Rollen gewähren, die häufig von bestimmten Benutzergruppen verwendet werden. (siehe Benutzerrollen). Wenn Sie beispielsweise eine analyst
-Rolle erstellt haben, die von Analysten in Ihrer Organisation als Standardrolle verwendet wird, können Sie diesen Benutzern mit einer einzigen GRANT-Anweisung schnell Zugriff auf die Snowflake Cortex-LLM-Funktionen gewähren.
GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE analyst;
The PUBLIC pseudo-role is automatically granted to all users and roles, so granting cortex_user_role
to PUBLIC
allows all users in your account to use the Snowflake Cortex LLM functions.
GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE PUBLIC;
Tipp
Be mindful of the number of users to whom you are granting access and the impact their usage of Snowflake Cortex LLM functions may have on compute consumption. Establish policies around purpose of use (particularly of the most costly models) before granting widespread access to these features.
Expect users to explore the new features, potentially driving a temporary surge in cost, before settling into a more stable usage pattern.
Verfügbarkeit¶
Snowflake Cortex-LLM-Funktionen sind derzeit in den folgenden Regionen verfügbar.
Funktion
(Modell)
|
AWS US East
(N. Virginia)
|
AWS US West
(Oregon)
|
AWS Europe
(Frankfurt)
|
Azure East US 2
(Virginia)
|
Azure West Europe
(Niederlande)
|
---|---|---|---|---|---|
COMPLETE
(
mistral-large ) |
✔ |
||||
COMPLETE
(
mixtral-8x7b ) |
✔ |
✔ |
|||
COMPLETE
(
llama2-chat-70b ) |
✔ |
✔ |
✔ |
✔ |
✔ |
COMPLETE
(
mistral-7b ) |
✔ |
✔ |
✔ |
✔ |
✔ |
COMPLETE
(
gemma-7b ) |
✔ |
✔ |
✔ |
✔ |
✔ |
EXTRACT_ANSWER |
✔ |
✔ |
✔ |
✔ |
✔ |
SENTIMENT |
✔ |
✔ |
✔ |
✔ |
✔ |
SUMMARIZE |
✔ |
✔ |
✔ |
✔ |
✔ |
TRANSLATE |
✔ |
✔ |
✔ |
✔ |
✔ |
Hinweise zu Kosten¶
Snowflake Cortex LLM functions incur compute cost based on the number of tokens processed. The table below shows the cost in credits per 1 million tokens for each function.
Bemerkung
Ein Token ist die kleinste Texteinheit, die von den Snowflake Cortex-LLM-Funktionen verarbeitet wird, und entspricht etwa vier Textzeichen. Das Verhältnis des ein-/ausgegebene Rohtextes zur Tokenanzahl kann je nach Modell variieren.
Bei Funktionen, die neuen Text in der Antwort generieren (COMPLETE, SUMMARIZE und TRANSLATE), werden sowohl Eingabe- als auch Ausgabe-Token gezählt.
Bei Funktionen, die nur Informationen aus der Eingabe extrahieren (EXTRACT_ANSWER und SENTIMENT), werden nur die Eingabe-Token gezählt.
Bei EXTRACT_ANSWER ergibt sich die Anzahl der abrechenbaren Token aus der Summe der Anzahl der Token in den Feldern
from_text
undquestion
.
For general information on compute costs, see Erläuterungen zu den Computekosten.
Bemerkung
Snowflake recommends executing queries that call a Snowflake Cortex LLM Function with a smaller warehouse (no larger than MEDIUM) because larger warehouses do not increase performance. The cost associated with keeping a warehouse active will continue to apply when executing a query that calls a Snowflake Cortex LLM Function.
Function (Model) |
Snowflake credits per million tokens |
---|---|
COMPLETE ( |
5.10 |
COMPLETE ( |
0.50 |
COMPLETE ( |
0.45 |
COMPLETE ( |
0.12 |
COMPLETE ( |
0.12 |
EXTRACT_ANSWER |
0.08 |
SENTIMENT |
0.08 |
SUMMARIZE |
0.10 |
TRANSLATE |
0.33 |
Usage of Snowflake Cortex LLM functions appears in the Snowflake Organization Usage’s METERING_DAILY_HISTORY view with a service type of AI_SERVICES. To view credit consumption for AI services for all accounts in an organization, use the following query.
SELECT * FROM SNOWFLAKE.ORGANIZATION_USAGE.METERING_DAILY_HISTORY
WHERE service_type ILIKE '%ai_services%';
Bemerkung
The SNOWFLAKE.ORGANIZATION_USAGE.METERING_DAILY_HISTORY view may take up to four hours to update.
Nutzungskontingente¶
To ensure a high standard of performance for all Snowflake customers, Snowflake Cortex LLM functions are subject to usage quotas beyond which requests may be throttled. Snowflake may adjust these quotas from time to time. The quotas in the table below are applied per account.
Function (Model) |
Tokens processed per minute (TPM) |
Rows processed per minute (RPM) |
---|---|---|
COMPLETE ( |
200,000 |
100 |
COMPLETE ( |
300,000 |
400 |
COMPLETE ( |
300,000 |
400 |
COMPLETE ( |
300,000 |
500 |
COMPLETE ( |
300,000 |
500 |
EXTRACT_ANSWER |
1,000,000 |
3,000 |
SENTIMENT |
1,000,000 |
5,000 |
SUMMARIZE |
300,000 |
500 |
TRANSLATE |
1,000,000 |
2,000 |
Bemerkung
On-demand-Snowflake-Konten ohne gültige Zahlungsmethode (z. B. Testkonten) sind auf etwa einen Credit pro Tag für die Nutzung der Snowflake Cortex-LLM-Funktion beschränkt. Um diese Einschränkung aufzuheben, wandeln Sie Ihr Testkonto in ein kostenpflichtiges Konto um.
Kostenmanagement und Drosselung¶
During this preview, Snowflake recommends using a warehouse size no larger than MEDIUM when calling Snowflake Cortex LLM functions. Using a larger warehouse than necessary does not increase performance, but can result in unnecessary costs and a higher risk of throttling. This recommendation may not apply in the future due to upcoming product updates.
Modelleinschränkungen¶
Für die von Snowflake Cortex verwendeten Modelle gelten die in der nachstehenden Tabelle beschriebenen Größenbeschränkungen. Die Größen sind in Anzahl von Token angegeben. Token entsprechen im Allgemeinen Wörtern, aber nicht alle Token sind Wörter, sodass die Anzahl der Wörter, die einem Limit entsprechen, etwas geringer ist als die Anzahl der Token. Eingaben, die dieses Limit überschreiten, führen zu einem Fehler.
Funktion |
Modell |
Kontextfenster (Token) |
---|---|---|
COMPLETE |
|
32.000 |
|
32.000 |
|
|
4.096 |
|
|
32.000 |
|
|
8.000 |
|
EXTRACT_ANSWER |
Snowflake-verwaltetes Modell |
2.048 für Text
64 für Frage
|
SENTIMENT |
Snowflake-verwaltetes Modell |
512 |
SUMMARIZE |
Snowflake-verwaltetes Modell |
32.000 |
TRANSLATE |
Snowflake-verwaltetes Modell |
1.024 |
Auswählen eines Modells¶
Die Snowflake Cortex-Funktion COMPLETE unterstützt mehrere Modelle mit unterschiedlichen Fähigkeiten, Latenzen und Kosten. Diese Modelle wurden sorgfältig ausgewählt, um den gängigen Anwendungsfällen der Kunden gerecht zu werden. Um die beste Leistung pro Credit zu erzielen, wählen Sie ein Modell, das gut zu Umfang und Komplexität des Inhalts Ihrer Aufgabe passt. Im Folgenden finden Sie einen kurzen Überblick über die verfügbaren Modelle.
mistral-large
is a top-tier model that scores well on a variety of metrics (see table below). It features a context window of 32,000 tokens (about 24,000 words), allowing it to engage in complex reasoning across extended conversations. It is also the most compute-intensive of the models offered by Snowflake Cortex and thus the most costly to run.mixtral-8x7b
provides low latency and high quality results, while also supporting a context length of 32,000 tokens. It is ideal for many enterprise production use cases.llama2-70b-chat
is well-suited to complex, large-scale tasks that require a moderate amount of reasoning, like extracting data or helping you to write job descriptions.mistral-7b
andgemma-7b
are capable of executing simple tasks quickly and with better cost efficiency.mistral-7b
is ideal for your simplest summarization and classification tasks that require a smaller degree of customization. Its 32,000 token limit gives it the ability to process multiple pages of text.gemma-7b
ist für einfache Code- und Textvervollständigungsaufgaben geeignet. Es hat ein Kontextfenster von 8.000 Token, ist aber innerhalb dieses Limits erstaunlich leistungsfähig und recht kostengünstig.
If you’re not sure where to start, try mistral-large
first, whether you are already using another top-tier model or are
new to LLMs. It is the most broadly capable model offered by Snowflake Cortex, and will give you a good idea what a
state-of-the-art model can do. Its results can be used as a baseline in evaluating the other models.
To help you decide, the following table provides information on how popular models perform on various benchmarks, including the models offered by Snowflake Cortex COMPLETE as well as a few other popular models.
Modell |
Kontextfenster
(Token)
|
MMLU
(Begründungen)
|
MT-Bench
(Anweisungsbefolgung)
|
HumanEval
(Codierung)
|
Spider 1.0
(SQL)
|
---|---|---|---|---|---|
32.000 |
86,4 |
8,96 |
67 |
86,6 |
|
32.000 |
81,2 |
- |
45,1 |
81 |
|
Claude 2 * |
100,000 |
78,5 |
8,06 |
71,2 |
- |
32.000 |
70,6 |
8,30 |
40,2 |
- |
|
4,097 |
70 |
8,39 |
48,1 |
- |
|
4.096 |
68,9 |
6,86 |
30,5 |
- |
|
32.000 |
62,5 |
6,84 |
26,2 |
- |
|
8.000 |
64,3 |
- |
32,3 |
- |
|
4.096 |
45,3 |
6,27 |
12,2 |
- |
*Zu Vergleichszwecken bereitgestellt; nicht verfügbar in Snowflake Cortex-COMPLETE.
Übersicht zu LLM-Funktionen¶
COMPLETE¶
Bei einem Prompt generiert die Anweisungen befolgende COMPLETE-Funktion eine Antwort unter Verwendung des von Ihnen gewählten Sprachmodells. Im einfachsten Fall besteht der Prompt aus einer einzigen Zeichenfolge. Sie können auch eine Konversation aus mehreren Prompts und Antworten für eine interaktive Nutzung im Chat-Stil bereitstellen. In dieser Form der Funktion können Sie auch Hyperparameter-Optionen angeben, um den Stil und die Größe der Ausgabe anzupassen.
The COMPLETE function supports the following models. Different models can have different costs and quotas.
mistral-large
mixtral-8x7b
llama2-70b-chat
mistral-7b
gemma-7b
Syntax und Beispiele finden Sie unter COMPLETE (SNOWFLAKE.CORTEX).
EXTRACT_ANSWER¶
Die Funktion EXTRACT_ANSWER extrahiert aus einem Textdokument eine Antwort auf eine bestimmte Frage. Bei dem Dokument kann es sich um ein Dokument in einfachem Englisch oder um eine Zeichenfolgen-Darstellung eines semistrukturierten (JSON-)Datenobjekts handeln.
See EXTRACT_ANSWER (SNOWFLAKE.CORTEX) for syntax and examples.
SENTIMENT¶
Die SENTIMENT-Funktion gibt für einen gegebenen englischsprachigen Eingabetext die Stimmung als Punktwert zwischen -1 und 1 zurück (wobei -1 der negativste und 1 der positivste Wert ist und die Werte um 0 herum neutral sind).
See SENTIMENT (SNOWFLAKE.CORTEX) for syntax and examples.
SUMMARIZE¶
Die SUMMARIZE-Funktion gibt zu einem gegebenen englischsprachigen Text eine Zusammenfassung zurück.
See SUMMARIZE (SNOWFLAKE.CORTEX) for syntax and examples.
TRANSLATE¶
Die TRANSLATE-Funktion übersetzt Text aus der angegebenen oder erkannten Ausgangssprache in eine Zielsprache.
See TRANSLATE (SNOWFLAKE.CORTEX) for syntax and examples.
Fehlerbedingungen¶
Snowflake Cortex-LLM-Funktionen können die folgenden Fehlermeldungen erzeugen.
Meldung |
Erläuterung |
---|---|
|
Die Anfrage wurde wegen zu hoher Systembelastung abgelehnt. Versuchen Sie Ihre Anfrage erneut. |
|
Das an die Funktion übergebene |
|
Das Budget für den Modellverbrauch wurde überschritten. |
|
Das angegebene Modell ist nicht vorhanden. |
|
Die angegebene Sprache wird von der TRANSLATE-Funktion nicht unterstützt. |
|
Die Anfrage hat die maximale Anzahl der vom Modell unterstützten Token überschritten (siehe Modelleinschränkungen). |
|
The number of requests exceeds the limit. Try again later. |
Verwenden von Snowflake Cortex-LLM-Funktionen mit Python¶
Snowflake Cortex LLM functions are available in Snowpark ML version 1.1.2 and later. See Installieren von Snowpark ML for instructions on setting up Snowpark ML.
Wenn Sie Ihr Python-Skript außerhalb von Snowflake ausführen, müssen Sie eine Snowpark-Sitzung erstellen, um diese Funktionen nutzen zu können. Eine Anleitung dazu finden Sie unter Verbinden mit Snowflake.
Das folgende Python-Beispiel zeigt den Aufruf von Snowflake Cortex-LLM-Funktionen für einzelne Werte:
from snowflake.cortex import Complete, ExtractAnswer, Sentiment, Summarize, Translate
text = """
The Snowflake company was co-founded by Thierry Cruanes, Marcin Zukowski,
and Benoit Dageville in 2012 and is headquartered in Bozeman, Montana.
"""
print(Complete("llama2-70b-chat", "how do snowflakes get their unique patterns?"))
print(ExtractAnswer(text, "When was snowflake founded?"))
print(Sentiment("I really enjoyed this restaurant. Fantastic service!"))
print(Summarize(text))
print(Translate(text, "en", "fr"))
Sie können auch eine LLM-Funktion für eine Tabellenspalte aufrufen, wie unten gezeigt. Dieses Beispiel erfordert ein Sitzungsobjekt (gespeichert in session
) und eine Tabelle articles
mit einer Textspalte abstract_text
. Das Beispiel erstellt eine neue Spalte abstract_summary
mit einer Zusammenfassung des Abstracts.
from snowflake.cortex import Summarize
from snowflake.snowpark.functions import col
article_df = session.table("articles")
article_df = article_df.withColumn(
"abstract_summary",
Summarize(col("abstract_text"))
)
article_df.collect()
Bemerkung
Die erweiterte Form von COMPLETE im Chat-Stil (mehrere Meldungen) wird derzeit in Python nicht unterstützt.
Rechtliche Hinweise¶
Snowflake Cortex LLM Functions are powered by machine learning technology, including Meta’s LLaMA 2. The foundation LLaMA 2 model is licensed under the LLaMA 2 Community License and Copyright (c) Meta Platforms, Inc. All Rights Reserved. Your use of any LLM Functions based on the LLama 2 model is subject to Meta’s Acceptable Use Policy.
Machine learning technology and results provided may be inaccurate, inappropriate, or biased. Decisions based on machine learning outputs, including those built into automatic pipelines, should have human oversight and review processes to ensure model-generated content is accurate.
LLM function queries will be treated as any other SQL query and may be considered metadata.
For further information, see Snowflake AI Trust and Safety FAQ.