Craft RAG
const { rag } = MODULES;Table of Contents
Schemas
RetrieveResultValue
Type: Object
Properties
filePathstring Source file path.textstring The text chunk.scorenumber The score between the query dense embedding vector and the context text vector.
RagDataSchema
Type: Object
Properties
keystring The metadata key name.type("INTEGER"|"FLOAT"|"STRING"|"DATETIME"|"BOOLEAN"|"LIST") The data type of the metadata key.
RagMetadata
Type: Object
Properties
Methods
retrieveContexts
Parameters
-
paramObjectparam.corpusIdstring RAG Idparam.textstring The query text to get relevant contexts.param.vectorDistanceThresholdnumber? Optional. Only contexts with a vector distance smaller than the threshold are returned.param.topKnumber? Optional. The number of contexts to return.param.llmRankerModelstring? Optional. The name of the LLM ranker model to use for ranking results. Only accepts:gemini-2.5-flash,gemini-2.5-pro,gemini-2.5-flash-lite,gemini-3.5-flash,gemini-3.1-flash-lite, orgemini-3.1-pro-preview.param.rankServiceModelstring? Optional. The name of the rank service model to use for ranking results. Only accepts:semantic-ranker-512-003.param.metadataFilterstring? Optional. A metadata filter string using CEL (Common Expression Language) syntax (e.g.,category == "HR").
Returns Promise<Array<RetrieveResultValue>>
createDataSchemas
Define metadata schemas for a RAG corpus.
Parameters
-
paramObjectparam.corpusIdstring RAG corpus Id.param.schemasArray<RagDataSchema> Array of schema definitions with key and type.
attachMetadata
Attach metadata values to an existing RAG file.
Parameters
-
paramObjectparam.corpusIdstring RAG corpus Id.param.fileIdstring RAG file Id.param.metadataArray<RagMetadata> Array of metadata key-value pairs.
listDataSchemas
List metadata schemas defined on a RAG corpus.
Parameters
listMetadata
List metadata attached to a RAG file.