Skip to main content
InterSystems IRIS Data Platform 2024.3
AskMe (beta)

EMBEDDING (SQL)

Converts a piece of text to an embedding that represents it.

Synopsis

EMBEDDING(text)
EMBEDDING(text, config-name)

Description

Transforms a piece of text into an embedding using the provided embedding configuration. The embedding is returned in the VECTOR type.

Users that execute this function must have the %USE_EMBEDDING privilege.

Arguments

text

A string representing the text that you would like to translate into an embedding.

config-name

The name of the embedding configuration (stored in %Embedding.Config) that you would like to use to translate text into an embedding. See Create an Embedding Configuration for more information.

This argument is optional when used against an EMBEDDING-typed column in a table, as the system uses the embedding configuration associated with the column by default.

Examples

The following example returns the names of entries in the Store.RunningShoes table that have descriptions that are most similar to an input search term. Note that config-name is optional and omitted because the DescriptionEmbedding column contains EMBEDDING-typed data and the EMBEDDING function uses embedding configuration already associated with that column.

SELECT TOP 5 Name FROM Store.RunningShoes
  ORDER BY VECTOR_DOT_PRODUCT(DescriptionEmbedding, 
                              EMBEDDING('comfortable and lightweight')) DESC

The following example adds a new embedding configuration (using the %Embedding.SentenceTransformers class), then uses that configuration to return a piece of text into an embedding with the EMBEDDING function.

INSERT INTO %Embedding.Config (Name, Configuration, EmbeddingClass, Description) 
  VALUES ('huggingface', 
          '{"hfCachePath":"/InterSystems/VEC147/hfCache", 
            "modelName":"sentence-transformers/all-MiniLM-L6-v2"}',
          '%Embedding.SentenceTransformers',
          'a generic open source embedding model') 
SELECT EMBEDDING('comfortable and lightweight','huggingface')

See Also

FeedbackOpens in a new tab