- Catégories :
Fonctions de chaîne et fonctions binaires (Fonctions AI)
AI_EXTRACT¶
Extrait les informations d’une chaîne ou d’un fichier d’entrée.
Syntaxe¶
Extraire des informations d’une chaîne d’entrée :
AI_EXTRACT( <text>, <responseFormat> )
AI_EXTRACT( text => <text>,
responseFormat => <responseFormat> )
Extraire des informations d’un fichier :
AI_EXTRACT( <file>, <responseFormat> )
AI_EXTRACT( file => <file>,
responseFormat => <responseFormat> )
Arguments¶
textUne chaîne d’entrée pour l’extraction.
fileUn FILE pour l’extraction.
Formats de fichiers pris en charge :
PDF
PNG
PPTX, PPT
EML
DOC, DOCX
JPEG, JPG
HTM, HTML
TEXT, TXT
TIF, TIFF
BMP, GIF, WEBP
MD
La taille des fichiers ne doit pas dépasser 100 MB.
responseFormatInformations à extraire dans l’un des formats de réponse suivants :
Simple object schema that maps the label and information to be extracted; for example:
{'name': 'What is the last name of the employee?', 'address': 'What is the address of the employee?'}Tableau de chaînes contenant les informations à extraire, par exemple :
['What is the last name of the employee?', 'What is the address of the employee?']An array of arrays that contain two strings (label and the information to be extracted); for example:
[['name', 'What is the last name of the employee?'], ['address', 'What is the address of the employee?']]A JSON schema that defines the structure of the extracted information. Supports entity and table extraction. For example:
{ 'schema': { 'type': 'object', 'properties': { 'income_table': { 'description': 'Income for FY2026Q2', 'type': 'object', 'column_ordering': ['month', 'income'], 'properties': { 'month': { 'description': 'Month', 'type': 'array' }, 'income': { 'description': 'Income', 'type': 'array' } } }, 'title': { 'description': 'What is the title of the document?', 'type': 'string' }, 'employees': { 'description': 'What are the names of employees?', 'type': 'array' } } } }
Note
Vous ne pouvez pas combiner le format de schéma JSON avec d’autres formats de réponse. Si
responseFormatcontient la cléschema, vous devez définir toutes les questions à l’intérieur du schéma JSON. Les clés supplémentaires ne sont pas prises en charge.Le modèle n’accepte que certaines formes de schéma JSON. Le type de niveau supérieur doit toujours être un objet, qui contient des sous-objets extraits indépendamment. Les sous-objets peuvent être une table (objet de listes de chaînes représentant des colonnes), une liste de chaînes ou une chaîne.
Chaîne est actuellement le seul type scalaire pris en charge.
Le champ
descriptionest facultatif.Utilisez le champ
descriptionpour fournir un contexte au modèle ; par exemple, pour aider le modèle à localiser la table droite dans un document.Utilisez le champ
column_orderingpour spécifier l’ordre de toutes les colonnes de la table extraite. Le champcolumn_orderingest sensible à la casse et doit correspondre aux noms de colonnes définis dans le champproperties.
Renvoie¶
Un objet JSON contenant les informations extraites.
Exemple de sortie qui inclut un tableau, une table et une extraction de valeur unique :
{
"error": null,
"response": {
"employees": [
"Smith",
"Johnson",
"Doe"
],
"income_table": {
"income": ["$120 678","$130 123","$150 998"],
"month": ["February", "March", "April"]
},
"title": "Financial report"
}
}
Exigences en matière de contrôle d’accès¶
Users must use a role that has been granted the SNOWFLAKE.CORTEX_USER database role. For information about granting this privilege, see Cortex LLM privileges.
Notes sur l’utilisation¶
Vous ne pouvez pas utiliser les deux paramètres
textetfilesimultanément dans le même appel de fonction.You can either ask questions in natural language or describe information to be extracted (such as city, street, ZIP code); for example:
['address': 'City, street, ZIP', 'name': 'First and last name']Les langues suivantes sont prises en charge :
Arabe
Bengali
Birman
Cebuano
Chinois
Tchèque
Néerlandais
Anglais
Français
Allemand
Hébreu
Hindi
Indonésien
Italien
Japonais
Khmer
Coréen
Lao
Malais
Persan
Polonais
Portugais
Russe
Espagnol
Tagalog
Thaïlandais
Turc
Ourdou
Vietnamien
Les documents ne doivent pas dépasser 125 pages.
Dans un seul appel AI_EXTRACT, vous pouvez poser un maximum de 100 questions pour l’extraction d’entités, et un maximum de 10 questions pour l’extraction de tables.
Une question d’extraction de table est égale à 10 questions d’extraction d’entité. Par exemple, vous pouvez poser 4 questions sur l’extraction de tables et 60 questions sur l’extraction d’entités dans un seul appel AI_EXTRACT.
La longueur de sortie maximale pour l’extraction d’entités est de 512 jetons par question. Pour l’extraction de table, le modèle renvoie des réponses comportant un maximum de 4 096 jetons.
Client-side encrypted stages are not supported.
Les scores de confiance ne sont pas pris en charge.
Exemples¶
Extraction from an input string¶
L’exemple suivant extrait les informations du texte d’entrée :
SELECT AI_EXTRACT( text => 'John Smith lives in San Francisco and works for Snowflake', responseFormat => {'name': 'What is the first name of the employee?', 'city': 'What is the address of the employee?'} );
L’exemple suivant extrait et analyse les informations contenues dans le texte d’entrée :
SELECT AI_EXTRACT( text => 'John Smith lives in San Francisco and works for Snowflake', responseFormat => PARSE_JSON('{"name": "What is the first name of the employee?", "address": "What is the address of the employee?"}') );
Extraction from a file¶
L’exemple suivant extrait les informations du fichier
document.pdf:SELECT AI_EXTRACT( file => TO_FILE('@db.schema.files','document.pdf'), responseFormat => [['name', 'What is the first name of the employee?'], ['city', 'Where does the employee live?']] );
The following example extracts information from all files in a directory on a stage:
Note
Assurez-vous que la table de répertoire est activée. Pour plus d’informations, voir Gestion des tables de répertoire.
SELECT AI_EXTRACT( file => TO_FILE('@db.schema.files', relative_path), responseFormat => [ 'What is this document?', 'How would you classify this document?' ] ) FROM DIRECTORY (@db.schema.files);
The following example extracts the
titlevalue from thereport.pdffile:SELECT AI_EXTRACT( file => TO_FILE('@db.schema.files', 'report.pdf'), responseFormat => { 'schema': { 'type': 'object', 'properties': { 'title': { 'description': 'What is the title of document?', 'type': 'string' } } } } );
The following example extracts the
employeesarray from thereport.pdffile:SELECT AI_EXTRACT( file => TO_FILE('@db.schema.files', 'report.pdf'), responseFormat => { 'schema': { 'type': 'object', 'properties': { 'employees': { 'description': 'What are the surnames of employees?', 'type': 'array' } } } } );
The following example extracts the
income_tabletable from thereport.pdffile:SELECT AI_EXTRACT( file => TO_FILE('@db.schema.files', 'report.pdf'), responseFormat => { 'schema': { 'type': 'object', 'properties': { 'income_table': { 'description': 'Income for FY2026Q2', 'type': 'object', 'column_ordering': ['month', 'income'], 'properties': { 'month': { 'type': 'array' }, 'income': { 'type': 'array' } } } } } } );
The following example extracts table (
income_table), single value (title), and array (employees) from thereport.pdffile:SELECT AI_EXTRACT( file => TO_FILE('@db.schema.files', 'report.pdf'), responseFormat => { 'schema': { 'type': 'object', 'properties': { 'income_table': { 'description': 'Income for FY2026Q2', 'type': 'object', 'column_ordering': ['month', 'income'], 'properties': { 'month': { 'type': 'array' }, 'income': { 'type': 'array' } } }, 'title': { 'description': 'What is the title of document?', 'type': 'string' }, 'employees': { 'description': 'What are the surnames of employees?', 'type': 'array' } } } } );
Disponibilité régionale¶
Voir Disponibilité régionale.
Avis juridiques¶
Reportez-vous à Snowflake AI et ML pour les mentions légales.