Kategorien:

Zeichenfolgen- und Binärfunktionen (AI-Funktionen)

AI_EXTRACT

Extrahiert Informationen aus einer Eingabezeichenfolge oder Datei.

Syntax

Extract information from an input string:

AI_EXTRACT( <text>, <responseFormat> ) 
Copy
AI_EXTRACT( text => <text>, responseFormat => <responseFormat> ) 
Copy

Extract information from a file:

AI_EXTRACT( <file>, <responseFormat> ) 
Copy
AI_EXTRACT( file => <file>, responseFormat => <responseFormat> ) 
Copy

Argumente

text

Eine Eingabezeichenfolge für die Extraktion.

file

Eine FILE für die Extraktion.

Unterstützte Dateiformate:

  • PDF

  • PNG

  • PPTX, PPT

  • EML

  • DOC, DOCX

  • JPEG, JPG

  • HTM, HTML

  • TEXT, TXT

  • TIF, TIFF

  • BMP, GIF, WEBP

  • MD

Die Dateien müssen kleiner als 100 MB sein.

responseFormat

Informationen, die in einem der folgenden Antwortformate extrahiert werden sollen:

  • 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?'} 
  • Ein Array von Zeichenfolgen, die die zu extrahierenden Informationen enthalten, z. B.:

    ['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'  }  }  } } 

    Bemerkung

    • Sie können das JSON-Schemaformat nicht mit anderen Antwortformaten kombinieren. Wenn responseFormat den schema-Schlüssel enthält, müssen Sie alle Fragen innerhalb des JSON-Schemas definieren. Zusätzliche Schlüssel werden nicht unterstützt.

    • Das -Modell akzeptiert nur bestimmte Formen des JSON-Schemas. Der Typ der obersten Ebene muss immer ein Objekt sein, das unabhängig voneinander extrahierte Unterobjekte enthält. Unterobjekte können eine Tabelle (Objekt von Listen von Zeichenfolgen, die Spalten darstellen), eine Liste von Zeichenfolgen oder eine Zeichenfolge sein.

      Zeichenfolge ist derzeit der einzige unterstützte Skalartyp.

    • Das Feld description ist optional.

      Verwenden Sie das description-Feld, um Kontext für das Modell bereitzustellen; zum Beispiel, um dem Modell zu helfen, die richtige Tabelle in einem Dokument zu lokalisieren.

    • Verwenden Sie das Feld column_ordering, um die Reihenfolge aller Spalten in der extrahierten Tabelle anzugeben. Im Feld column_ordering wird zwischen Groß- und Kleinschreibung unterschieden, und dieses muss mit den im Feld properties definierten Spaltennamen übereinstimmen.

Rückgabewerte

Ein JSON-Objekt, das die extrahierten Informationen enthält.

Beispiel für eine Ausgabe, die die Extraktion von Arrays, Tabellen und Einzelwerten umfasst:

{  "error": null,  "response": {  "employees": [  "Smith",  "Johnson",  "Doe"  ],  "income_table": {  "income": ["$120 678","$130 123","$150 998"],  "month": ["February", "March", "April"]  },  "title": "Financial report"  } } 

Anforderungen an die Zugriffssteuerung

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.

Nutzungshinweise

  • Sie können im selben Funktionsaufruf nicht beides gleichzeitig verwenden, text- und file-Parameter.

  • 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'] 
  • Die folgenden Sprachen werden unterstützt:

    • Arabisch

    • Bengalisch

    • Birmanisch

    • Cebuano

    • Chinesisch

    • Tschechisch

    • Holländisch

    • Englisch

    • Französisch

    • Deutsch

    • Hebräisch

    • Hindi

    • Indonesisch

    • Italienisch

    • Japanisch

    • Khmer

    • Koreanisch

    • Lao

    • Malaiisch

    • Persisch

    • Polnisch

    • Portugiesisch

    • Russisch

    • Spanisch

    • Tagalog

    • Thailändisch

    • Türkisch

    • Urdu

    • Vietnamesisch

  • Die Dokumente dürfen nicht mehr als 125 Seiten umfassen.

  • In einem einzigen AI_EXTRACT-Aufruf können Sie maximal 100 Fragen zur Extraktion von Entitäten und maximal 10 Fragen zur Extraktion von Tabellen stellen.

    Eine Frage zur Extraktion von Tabellen entspricht 10 Fragen zur Extraktion von Entitäten. Sie können in einem einzigen AI_EXTRACT-Aufruf zum Beispiel 4 Fragen zur Extraktion von Tabellen und 60 Fragen zur Extraktion von Entitäten auf einmal stellen.

  • Die maximale Ausgabelänge für die Extraktion von Entitäten beträgt 512 Token pro Frage. Bei der Tabellenextraktion liefert das Modell Antworten, die maximal 4.096 Token umfassen.

  • Client-side encrypted stages are not supported.

  • Konfidenzwerte werden nicht unterstützt.

Beispiele

Extraction from an input string

  • Im folgenden Beispiel werden Informationen aus dem Eingabetext extrahiert:

    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?'} ); 
    Copy
  • Im folgenden Beispiel werden Informationen aus dem Eingabetext extrahiert und zurückgegeben:

    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?"}') ); 
    Copy

Extraction from a file

  • Im folgenden Beispiel werden Informationen aus der document.pdf-Datei extrahiert:

    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?']] ); 
    Copy
  • The following example extracts information from all files in a directory on a stage:

    Bemerkung

    Stellen Sie sicher, dass die Verzeichnistabelle aktiviert ist. Weitere Informationen dazu finden Sie unter Verwalten von Verzeichnistabellen.

    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); 
    Copy
  • The following example extracts the title value from the report.pdf file:

    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' } } } } ); 
    Copy
  • The following example extracts the employees array from the report.pdf file:

    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' } } } } ); 
    Copy
  • The following example extracts the income_table table from the report.pdf file:

    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' } } } } } } ); 
    Copy
  • The following example extracts table (income_table), single value (title), and array (employees) from the report.pdf file:

    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' } } } } ); 
    Copy

Regionale Verfügbarkeit

Siehe Regionale Verfügbarkeit.