Defining a Custom Content Retriever
A Custom Content or RAG Retriever Function can be used to retrieve content that will be directly injected into the LLM Prompt.
Once defined, a Custom Content Retriever Function can be utilised in multiple Stages or in the Common Stage Settings and will be called after the user's utterance is processed and just before prompting the LLM for a response at each turn.

Defining a Custom Content Retriever Function
To fully define a Custom Content Retriever Function, you must specify:
- A Function Interface - define each input and secret parameter required.
- A Function Implementation - define the Javascript code that uses the parameters and implements the logic of the function.
Note: Other arguments passed to a Custom RAG/Content Retrieval function are specified where the definition get's used, not where it is defined.
Terminology
The discussion that follows uses specific terms to specifically differentiate:
- Agent Variables - the variables defined in the agent
- Parameters - the input parameters of the function.
At runtime, agent variables are mapped to input parameters according to the mappings specified where the custom function definition is used in Stages and/or Common Stage Settings.
Input Parameters
-
For each input parameter, specify a Javascript parameter name that will be used by the function logic to access that parameter.
-
In addition, to aid in the identification of each input parameter when the function actually gets used in Stages or Common Stage Settings, specify a description for each.
Secrets
-
For each secret used in the function, specify a Javascript parameter name that will be used by the function logic to access that secret.
-
In addition, select the secret that will be mapped to that parameter.
Implementing a Function
Execution Environment
The function execution environment is a V8 Javascript environment supporting ECMAScript 2022.
fetch() and GraphQL Support
The environment has embedded support for fetch() and GraphQL for interacting with external endpoints. For more information, refer to the documentation on their use in Custom Functions.
Function Definition
The function definition must take the following specific form:
Note:
- The function must be async.
- The function must be named main.
- The function must take a single argument object containing correct parameters (see below)
- The function must return a single object containing a docs array element.
Passing data in to the function
All input data is passed to the Javascript Function as a single argument object.
The argument object contains 5 specific parameters:
Input Parameters
Note
With the exception of the inputParams and secrets, the following arguments are not specified as part of the Integration definition. Instead they are configured where the RAG/Content Retrieval is used in Stages or Common Stage Settings, enabling specialization by context.
| Parameter | Details |
|---|---|
| query | The user utterance - when this integrations is used, if it is configured to resolve ambiguous language, this will be the resolved version of the user utterance |
| topK | The maximum number of docs to retrieve |
| metadataFields | The configured list of additional metadata fields to include in the metadata object |
| inputParams | As in a Custom JS Integration, these are additional agent variables configured in the function definition |
| secrets | As in a Custom JS Integration, these are any secrets configured in the function definition |
Returning documents from the function
All documents are returned from the Javascript Function as a single return object with a single docs member.
Return type
Each entry of the returned docs array must conform to the following shape: