Snowflake Gen AI Functions · Topic 15 of 26

Unstructured Data Analysis with AI_PARSE_DOCUMENT, AI_EXTRACT, AI_SIMILARITY and AI_COMPLETE

Choose between AI_PARSE_DOCUMENT, AI_EXTRACT, AI_SIMILARITY and AI_COMPLETE to analyze documents, text and images stored on a Snowflake stage.

  • 4 min
In a nutshell
  • AI_PARSE_DOCUMENT modes: OCR (default), LAYOUT (Markdown with tables), AGENTIC (Preview).
  • AI_EXTRACT returns response and error, with 125 pages per file without cross region inference.
  • AI_SIMILARITY returns -1 to 1 and needs two inputs of the same type.

What it is

Unstructured data is files and free text: PDFs, scans, images, emails and notes. Snowflake analyzes it with Cortex AI functions that you call from SQL. Files stay on a stage and you point to them with a FILE value made by TO_FILE.

The four functions in this topic solve four different problems, and the exam asks you to choose.

FunctionJobReturns
AI_PARSE_DOCUMENTTurn a document into text or MarkdownJSON string with content
AI_EXTRACTPull specific fields, lists or tablesJSON with response and error
AI_SIMILARITYScore how alike two texts or two images areFLOAT from -1 to 1
AI_COMPLETEFree form reasoning over text, images or documentsText or structured object
StagePDF filesTO_FILEFILE valueparseAI_PARSE_DOCUMENTtext or MarkdownpromptAI_COMPLETEsummaryFILE valuequestionsAI_EXTRACTnamed fields

How it works

AI_PARSE_DOCUMENT

It reads a document on a stage and returns its content. The call is AI_PARSE_DOCUMENT(<file>, <options>).

OptionValues and default
modeOCR (default, text only), LAYOUT (text plus structure such as tables, output as Markdown), AGENTIC (Preview, interprets charts and diagrams)
page_splitTRUE or FALSE (default FALSE); works only for PDF, .pptx and .docx
extract_imagesNeeds LAYOUT mode
page_filterArray of start and end page objects, zero based, end exclusive
SELECT PARSE_JSON(
  AI_PARSE_DOCUMENT(TO_FILE('@docs', 'contract.pdf'), {'mode': 'LAYOUT'})
):content::STRING AS markdown;

The result is a JSON string, so wrap it in PARSE_JSON. A failed row returns NULL and does not stop the query. Use LAYOUT when tables matter and when the text will be chunked for search.

AI_EXTRACT

Use it when you know what you want out of the document: an invoice number, a date, a table of line items. You pass the file and a responseFormat.

SELECT AI_EXTRACT(
  file => TO_FILE('@docs', 'invoice.pdf'),
  responseFormat => {'invoice_no': 'What is the invoice number?',
                     'total': 'What is the total amount?'}
) AS result;

The result is a JSON object with a response key holding your fields and an error key. The responseFormat can be an object of label to question, an array of questions, or a JSON schema for lists and tables. Limits from the docs: files under 100 MB, 125 pages per file (1,000 with cross region inference), up to 100 entity questions per call, and 10 table questions. It accepts PDF, Word, PowerPoint, images, HTML, text and more. AI_EXTRACT replaces the older EXTRACT_ANSWER.

Exam tip

Fixed fields from a document point to AI_EXTRACT. A summary or an opinion about a document points to AI_COMPLETE.

AI_SIMILARITY

It compares two inputs by the cosine similarity of their embeddings and returns a FLOAT from -1 to 1. Both inputs must be text, or both must be images. Text and image cannot be mixed.

The default model is snowflake-arctic-embed-l-v2.0 for text and voyage-multimodal-3 for images. An optional config object sets the model. Typical uses are duplicate detection, matching a product photo to a catalog photo, and ranking candidates against a reference.

AI_COMPLETE on unstructured data

AI_COMPLETE accepts text, and for models that support it also images and documents (for example .pdf, .txt and .md). With files you build the prompt with PROMPT and refer to files by {0}, {1}:

SELECT AI_COMPLETE('claude-sonnet-4-5',
  PROMPT('Summarize this report: {0}', TO_FILE('@docs', 'report.pdf')));

Not every model accepts images or documents, so check the model list before choosing. Audio and video are not accepted by AI_COMPLETE.

Choosing quickly

  • Need text out of a scan or PDF for later steps: AI_PARSE_DOCUMENT.
  • Need known fields, lists or tables: AI_EXTRACT.
  • Need "how close are these": AI_SIMILARITY.
  • Need judgment, summary or classification in free text: AI_COMPLETE.

Common mistakes

Using AI_COMPLETE where AI_EXTRACT is built for the job. Extraction gives a predictable JSON shape.

Forgetting PARSE_JSON on the parse result. It is a JSON string, not a VARIANT.

Setting page_split on a plain image or text file. It supports only PDF, .pptx and .docx.

Comparing a text with an image in AI_SIMILARITY. That is not supported.

Watch out

FILE values do not work for files on internal stages with SNOWFLAKE_FULL encryption, on user or table stages, or on stages with client side encryption. Use a server side encrypted stage.

What to remember for the exam

  • AI_PARSE_DOCUMENT modes: OCR (default), LAYOUT (Markdown with tables), AGENTIC (Preview).
  • AI_EXTRACT returns response and error, with 125 pages per file without cross region inference.
  • AI_SIMILARITY returns -1 to 1 and needs two inputs of the same type.
  • TO_FILE builds the FILE value from a stage and a path.
  • Callers need the USE AI FUNCTIONS privilege and the SNOWFLAKE.CORTEX_USER (or AI_FUNCTIONS_USER) database role; USE AI FUNCTIONS and CORTEX_USER are granted to PUBLIC by default.

Check yourself

  • Which AI_PARSE_DOCUMENT mode returns tables as Markdown?

    LAYOUT mode.

  • Which function pulls an invoice total and date from a PDF into named fields?

    AI_EXTRACT.

  • Can AI_SIMILARITY compare a text string with an image?

    No, both inputs must be text or both must be images.

Topic 15 of 26 in Snowflake Gen AI Functions

Test yourself on Snowflake Gen AI Functions

The full Snowflake GES-C02 question bank has 585 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Snowflake. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.