llm.embed(options)

Note:

The content in this help topic pertains to SuiteScript 2.1.

Method Description

Returns the embeddings from the LLM for a given input.

You can use embeddings to compare the similarity of a set of inputs, which is useful for finding similar items based on item attributes, implementing semantic search, and applying text classification or text clustering. For example, consider a scenario where you sell items, and if an item is out of stock, you want to provide a list of similar items for customers to purchase instead. Here's an example of how you might use embeddings to find similar items:

  1. Generate embeddings for each item that you sell.

  2. Generate embeddings for the original item that you want to find similar items for.

  3. Calculate the cosine similarity between these embeddings, which gives you the similarity of each item with respect to the original item. For more information about cosine similarity, see Cosine similarity.

NetSuite supports specific embeddings models from Cohere. For a list of these models, see llm.EmbedModelFamily.

Important:

Embeddings include the semantic information of the original data and should be treated with the same level of sensitivity. Embeddings created from sensitive data must be protected, stored, logged, shared, retained, and deleted according to the same rules as the original data.

This method consumes AI Units. For more information, see NetSuite AI Units and NetSuite Features and AI Units FAQ.

Returns

llm.EmbedResponse

Supported Script Types

Server scripts

For more information, see SuiteScript 2.1 Script Types.

Governance

50

Module

N/llm Module

Since

2025.1

Parameters

Parameter

Type

Required / Optional

Description

Since

options.inputs

string[]

required

An array of inputs to get embeddings for.

2025.1

options.dimensions

number

optional

The number of dimensions of the returned embeddings array.

Embedding dimensions refer to the length of the numeric vector used to represent data, such as text. Each dimension corresponds to a specific feature or attribute that the model has learned about the data's meaning or context. A higher number of dimensions can capture more nuanced semantic information and complex relationships within the data.

You can use this parameter to limit the number of dimensions in the returned embeddings. The embed model that's currently supported, Cohere Embed v4.0, returns embeddings with 1536 dimensions, which is more than those returned by previously supported embed models. If you generated embeddings using previously supported models and stored these embeddings for later use, you should regenerate those embeddings using the currently supported embed model with the additional supported dimensions.

The supported range of values for this parameter is 1 - 1536. The default value is 1536.

2025.2

options.embedModelFamily

string

optional

The embed model family to use.

Use values from llm.EmbedModelFamily to set this value. If not specified, the Cohere Embed model (cohere.embed-v4.0) is used.

2025.1

options.ociConfig

Object

optional

Important:

This object is no longer supported. Any values specified in this object are ignored.

2025.1

options.timeout

number

optional

The amount of time to wait for a response from the LLM, in milliseconds.

If not specified, the default value is 30,000.

2025.1

options.truncate

string

optional

The truncation method to use when embeddings input exceeds 512 tokens.

Use values from llm.Truncate to set this value. If not specified, no truncation method is used.

2025.1

Errors

Error Code

Thrown If

SSS_MISSING_REQD_ARGUMENT

The options.inputs parameter was not provided.

INVALID_MODEL_FAMILY_VALUE

The value provided for the options.embedModelFamily parameter is not included in the llm.EmbedModelFamily enum.

MAXIMUM_PARALLEL_REQUESTS_LIMIT_EXCEEDED

The number of parallel requests to the LLM is greater than 5.

NO_INPUTS_TO_EMBED

The value of the options.inputs parameter has a length of 0.

CAN_EMBED_1_INPUTS_AT_MAXIMUM

The value of the options.inputs parameter has a length greater than 96.

You can provide a maximum of 96 inputs in a single call to llm.embed(options).

INVALID_TRUNCATION_METHOD

The value of the options.truncate parameter is not included in the llm.Truncate enum.

UNSUPPORTED_NUMBER_OF_TOKENS

Too many tokens were provided as embeddings input.

Use a truncation method from llm.Truncate to reduce the size of the embeddings input.

Syntax

Important:

The following code sample shows the syntax for this member. It isn't a functional example. For a complete script example, see N/llm Module Script Samples.

            // Add additional code
...

const response = llm.embed({
    inputs: ["Hello World"],
    embedModelFamily: llm.EmbedModelFamily.COHERE_EMBED,
    timeout: 10000,
    truncate: llm.Truncate.START
});

...
// Add additional code 

          

Related Topics

General Notices