llm.Document

Note:

The content in this help topic pertains to SuiteScript 2.1.

Object Description

A document returned from llm.createDocument(options).

A document represents source content that you can provide as additional context to the LLM when you call llm.generateText(options) or llm.generateText.promise(options). The LLM uses information in the provided documents to augment its response using retrieval-augmented generation (RAG). For more information about RAG, see What Is Retrieval-Augmented Generation (RAG)?

Document objects are included in the llm.Response object that is returned from llm.generateText(options) or llm.generateText.promise(options), if applicable, through the Response.documents property. This property is an array of document objects, each representing a document that was used to generate the response returned from llm.generateText(options) or llm.generateText.promise(options). You can use the document object to confirm the content that was used to generate the response. The object includes properties that specify the ID of the document used (Document.id) and the content of the document (Document.data).

Documents are used to provide additional context for the response, and the information in provided documents is processed together with ground truth information for the LLM model to produce a more comprehensive response. For example, consider the following code sample:

                    const doc1 = llm.createDocument({
    id: "doc1",
    data: "Emperor penguins are the tallest."
});
const doc2 = llm.createDocument({
    id: "doc2",
    data: "Emperor penguins only live in the Sahara desert."
});
const doc3 = llm.createDocument({
    id: "doc3",
    data: "Emperor penguins only live in Antarctica."
});

const response = llm.generateText({
    prompt: "Where do the tallest penguins live?",
    documents: [doc1, doc2, doc3]
}); 

                  

In this example, the provided documents include conflicting information about where emperor penguins live. The LLM considers this information alongside its ground truth information about penguins and the climates they typically live in, and it might produce a response similar to the following:

"Emperor penguins are the tallest penguins, and they live in Antarctica. However, one source suggests that emperor penguins only live in the Sahara desert. This seems unlikely, as the Sahara is a desert and emperor penguins are native to cold climates."

Supported Script Types

Server scripts

For more information, see SuiteScript 2.x Script Types.

Module

N/llm Module

Methods and Properties

Document Object Members

Since

2025.1

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

// The documents doc1 and doc2 are created using llm.createDocument(options)
const response = llm.generateText({
    prompt: "My test prompt",
    documents: [doc1, doc2]
});

// If information in the provided documents is used to generate the response,
// the returned llm.Response object includes the IDs of the documents that
// were used
const documents = response.documents;
for (var i = 0; i < documents.length; i++) {
    var data = documents[i].data;
    var id = documents[i].id;

    // Work with the document properties
}

...
// Add additional code 

          

Related Topics

General Notices