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 is 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.

Returns

llm.EmbedResponse

Supported Script Types

Server scripts

For more information, see SuiteScript 2.x 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.embedModelFamily

string

optional

The embed model family to use.

Use values from llm.EmbedModelFamily to set this value. If not specified, the Cohere Embed Multilingual model is used.

2025.1

options.ociConfig

Object

optional

Configuration needed for unlimited usage through OCI Generative AI Service. Required only when accessing the LLM through an Oracle Cloud Account and the OCI Generative AI Service. SuiteApps installed to target accounts are prevented from using the free usage pool for N/llm and must use the OCI configuration.

2025.1

options.ociConfig.compartmentId

string

optional

Compartment OCID. For more information, refer to Managing Compartments in the Oracle Cloud Infrastructure Documentation.

2025.1

options.ociConfig.endpointId

string

optional

Endpoint ID. This value is needed only when a custom OCI DAC (dedicated AI cluster) is to be used. For more information, refer to Managing an Endpoint in Generative AI in the Oracle Cloud Infrastructure Documentation.

2025.1

options.ociConfig.fingerprint

string

optional

Fingerprint of the public key (only a NetSuite secret is accepted—see Creating Secrets ). For more information, refer to Required Keys and OCIDs in the Oracle Cloud Infrastructure Documentation.

2025.1

options.ociConfig.privateKey

string

optional

Private key of the OCI user (only a NetSuite secret is accepted—see Creating Secrets ). For more information, refer to Required Keys and OCIDs in the Oracle Cloud Infrastructure Documentation.

2025.1

options.ociConfig.tenancyId

string

optional

Tenancy OCID. For more information, refer to Managing the Tenancy in the Oracle Cloud Infrastructure Documentation.

2025.1

options.ociConfig.userId

string

optional

User OCID. For more information, refer to Managing Users in the Oracle Cloud Infrastructure Documentation.

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.

UNRECOGNIZED_OCI_CONFIG_PARAMETERS

One or more unrecognized parameters for the OCI configuration were provided.

ONLY_API_SECRET_IS_ACCEPTED

The options.ociConfig. privateKey or options.ociConfig.fingerprint parameters are not NetSuite API secrets.

For more information about API secrets, see Secrets Management.

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 is not 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_ENGLISH,
    timeout: 10000,
    truncate: llm.Truncate.START
});

...
// Add additional code 

          

Related Topics

General Notices