Bring-your-own model for AI_EMBED

AI_EMBED supports running inference against a user-deployed model inference service on SPCS along with Snowflake’s Cortex models. To use this feature, the model argument needs to point to an SPCS model inference service that hosts a Sentence Transformer model.

FILE input (image embeddings) is not supported yet. See Limitations.

Prerequisites

Before you can use this feature, log a Sentence Transformer model, then deploy it as an SPCS model inference service using the Snowsight UI or the Python API.

For more examples on creating SPCS inference services, see Example workflows.

Syntax

The function accepts the same arguments as the standard AI_EMBED function. The only change is that the model argument is an SPCS service name instead of the name of a Cortex embedding model.

AI_EMBED( <model> , <input> )

Arguments

model

Name of an SPCS model inference service which hosts a Sentence Transformer model.

input

A string to generate an embedding from. FILE input is not supported. See Limitations.

Returns

An embedding vector of type VECTOR derived from the input text.

Examples

The examples in this section use a SQL variable for the service name:

SET service_name = '<db>.<schema>.<service>';

You can confirm the service exists with the following command:

DESC SERVICE IDENTIFIER($service_name);

Single embedding

SELECT AI_EMBED($service_name, 'hello world');

Embeddings from a table column

CREATE OR REPLACE TABLE documents (id INT, content VARCHAR);
INSERT INTO documents VALUES
  (1, 'Snowflake is a cloud data platform.'),
  (2, 'Embeddings represent text as vectors.'),
  (3, 'AI_EMBED generates vector embeddings.');

SELECT
  id,
  content,
  AI_EMBED($service_name, content) AS embedding
FROM documents
ORDER BY id;

Limitations

The following AI_EMBED inputs are not yet supported when the function points to an SPCS service.

FILE input

Image embedding via FILE input is not supported. The SPCS path only accepts text input.

-- Image input is not supported.
SELECT AI_EMBED(
  $service_name,
  TO_FILE('@my_images', 'cat.png')
);

PROMPT input

PROMPT inputs are rejected to avoid handling multimodal inputs, which are not supported yet on the SPCS path. As a result, even PROMPT() templates that contain only text arguments are rejected.

-- PROMPT() input is not supported.
SELECT AI_EMBED(
  $service_name,
  PROMPT('Embed: {0}', 'hello world')
);

Access control requirements

The user must have the USAGE privilege on the SPCS service and on its inference function.

Refer to Snowflake AI and ML for legal notices.