MCP Tools Reference: aiplatform.googleapis.com

Tool: retrieve_contexts

Retrieves relavant contexts from the specified RAG Engine Corpus via similarity search for the given query.

Parameters* parent : The parent resource, of the form projects/{project}/locations/{location} . * query : The query to search for. * query.text : The query text to search for. * query.rag_retrieval_config : The RAG retrieval config to use for the query. * query.rag_retrieval_config.top_k : The number of contexts to retrieve. * query.rag_retrieval_config.filter : The filter config to use for the query. * query.rag_retrieval_config.filter.vector_distance_threshold : The vector distance threshold to use for the query. * vertex_rag_store : The RAG store to use for the query. * vertex_rag_store.rag_resources : a list of RAG resources to use for the query. * vertex_rag_store.rag_resources.rag_corpus : A RAG corpus to use for the query.

The following sample demonstrate how to use curl to invoke the retrieve_contexts MCP tool.

Curl Request
  
curl  
--location  
 'https://aiplatform.googleapis.com/mcp/generate' 
  
 \ 
--header  
 'content-type: application/json' 
  
 \ 
--header  
 'accept: application/json, text/event-stream' 
  
 \ 
--data  
 '{ 
 "method": "tools/call", 
 "params": { 
 "name": "retrieve_contexts", 
 "arguments": { 
 // provide these details according to the tool' 
s  
MCP  
specification  
 } 
  
 } 
,  
 "jsonrpc" 
:  
 "2.0" 
,  
 "id" 
:  
 1 
 } 
 ' 
  

Input Schema

Request message for VertexRagService.RetrieveContexts .

RetrieveContextsRequest

JSON representation
 { 
 "parent" 
 : 
 string 
 , 
 "query" 
 : 
 { 
 object (  RagQuery 
 
) 
 } 
 , 
 // Union field data_source 
can be only one of the following: 
 "vertexRagStore" 
 : 
 { 
 object (  VertexRagStore 
 
) 
 } 
 // End of list of possible types for union field data_source 
. 
 } 
Fields
parent

string

Required. The resource name of the Location from which to retrieve RagContexts. The users must have permission to make a call in the project. Format: projects/{project}/locations/{location} .

query

object ( RagQuery )

Required. Single RAG retrieve query.

Union field data_source . Data Source to retrieve contexts. data_source can be only one of the following:
vertexRagStore

object ( VertexRagStore )

The data source for Vertex RagStore.

VertexRagStore

JSON representation
 { 
 "ragResources" 
 : 
 [ 
 { 
 object (  RagResource 
 
) 
 } 
 ] 
 , 
 // Union field _vector_distance_threshold 
can be only one of the following: 
 "vectorDistanceThreshold" 
 : 
 number 
 // End of list of possible types for union field _vector_distance_threshold 
. 
 } 
Fields
ragResources[]

object ( RagResource )

Optional. The representation of the rag source. It can be used to specify corpus only or ragfiles. Currently only support one corpus or multiple files from one corpus. In the future we may open up multiple corpora support.

Union field _vector_distance_threshold .

_vector_distance_threshold can be only one of the following:

vectorDistanceThreshold
(deprecated)

number

Optional. Only return contexts with vector distance smaller than the threshold.

RagResource

JSON representation
 { 
 "ragCorpus" 
 : 
 string 
 , 
 "ragFileIds" 
 : 
 [ 
 string 
 ] 
 } 
Fields
ragCorpus

string

Optional. RagCorpora resource name. Format: projects/{project}/locations/{location}/ragCorpora/{rag_corpus}

ragFileIds[]

string

Optional. rag_file_id. The files should be in the same rag_corpus set in rag_corpus field.

RagQuery

JSON representation
 { 
 "ragRetrievalConfig" 
 : 
 { 
 object (  RagRetrievalConfig 
 
) 
 } 
 , 
 // Union field query 
can be only one of the following: 
 "text" 
 : 
 string 
 // End of list of possible types for union field query 
. 
 } 
Fields
ragRetrievalConfig

object ( RagRetrievalConfig )

Optional. The retrieval config for the query.

Union field query . The query to retrieve contexts. Currently only text query is supported. query can be only one of the following:
text

string

Optional. The query in text format to get relevant contexts.

RagRetrievalConfig

JSON representation
 { 
 "topK" 
 : 
 integer 
 , 
 "filter" 
 : 
 { 
 object (  Filter 
 
) 
 } 
 , 
 "ranking" 
 : 
 { 
 object (  Ranking 
 
) 
 } 
 } 
Fields
topK

integer

Optional. The number of contexts to retrieve.

filter

object ( Filter )

Optional. Config for filters.

ranking

object ( Ranking )

Optional. Config for ranking and reranking.

Filter

JSON representation
 { 
 "metadataFilter" 
 : 
 string 
 , 
 // Union field vector_db_threshold 
can be only one of the following: 
 "vectorDistanceThreshold" 
 : 
 number 
 , 
 "vectorSimilarityThreshold" 
 : 
 number 
 // End of list of possible types for union field vector_db_threshold 
. 
 } 
Fields
metadataFilter

string

Optional. String for metadata filtering.

Union field vector_db_threshold . Filter contexts retrieved from the vector DB based on either vector distance or vector similarity. vector_db_threshold can be only one of the following:
vectorDistanceThreshold

number

Optional. Only returns contexts with vector distance smaller than the threshold.

vectorSimilarityThreshold

number

Optional. Only returns contexts with vector similarity larger than the threshold.

Ranking

JSON representation
 { 
 // Union field ranking_config 
can be only one of the following: 
 "rankService" 
 : 
 { 
 object (  RankService 
 
) 
 } 
 , 
 "llmRanker" 
 : 
 { 
 object (  LlmRanker 
 
) 
 } 
 // End of list of possible types for union field ranking_config 
. 
 } 
Fields
Union field ranking_config . Config options for ranking. Currently only Rank Service is supported. ranking_config can be only one of the following:
rankService

object ( RankService )

Optional. Config for Rank Service.

llmRanker

object ( LlmRanker )

Optional. Config for LlmRanker.

RankService

JSON representation
 { 
 // Union field _model_name 
can be only one of the following: 
 "modelName" 
 : 
 string 
 // End of list of possible types for union field _model_name 
. 
 } 
Fields

Union field _model_name .

_model_name can be only one of the following:

modelName

string

Optional. The model name of the rank service. Format: semantic-ranker-512@latest

LlmRanker

JSON representation
 { 
 // Union field _model_name 
can be only one of the following: 
 "modelName" 
 : 
 string 
 // End of list of possible types for union field _model_name 
. 
 } 
Fields

Union field _model_name .

_model_name can be only one of the following:

modelName

string

Optional. The model name used for ranking. See Supported models .

Output Schema

Response message for VertexRagService.RetrieveContexts .

RetrieveContextsResponse

JSON representation
 { 
 "contexts" 
 : 
 { 
 object (  RagContexts 
 
) 
 } 
 } 
Fields
contexts

object ( RagContexts )

The contexts of the query.

RagContexts

JSON representation
 { 
 "contexts" 
 : 
 [ 
 { 
 object (  Context 
 
) 
 } 
 ] 
 } 
Fields
contexts[]

object ( Context )

All its contexts.

Context

JSON representation
 { 
 "sourceUri" 
 : 
 string 
 , 
 "sourceDisplayName" 
 : 
 string 
 , 
 "text" 
 : 
 string 
 , 
 "chunk" 
 : 
 { 
 object (  RagChunk 
 
) 
 } 
 , 
 // Union field _score 
can be only one of the following: 
 "score" 
 : 
 number 
 // End of list of possible types for union field _score 
. 
 } 
Fields
sourceUri

string

If the file is imported from Cloud Storage or Google Drive, source_uri will be original file URI in Cloud Storage or Google Drive; if file is uploaded, source_uri will be file display name.

sourceDisplayName

string

The file display name.

text

string

The text chunk.

chunk

object ( RagChunk )

Context of the retrieved chunk.

Union field _score .

_score can be only one of the following:

score

number

According to the underlying Vector DB and the selected metric type, the score can be either the distance or the similarity between the query and the context and its range depends on the metric type.

For example, if the metric type is COSINE_DISTANCE, it represents the distance between the query and the context. The larger the distance, the less relevant the context is to the query. The range is [0, 2], while 0 means the most relevant and 2 means the least relevant.

RagChunk

JSON representation
 { 
 "text" 
 : 
 string 
 , 
 // Union field _page_span 
can be only one of the following: 
 "pageSpan" 
 : 
 { 
 object (  PageSpan 
 
) 
 } 
 // End of list of possible types for union field _page_span 
. 
 } 
Fields
text

string

The content of the chunk.

Union field _page_span .

_page_span can be only one of the following:

pageSpan

object ( PageSpan )

If populated, represents where the chunk starts and ends in the document.

PageSpan

JSON representation
 { 
 "firstPage" 
 : 
 integer 
 , 
 "lastPage" 
 : 
 integer 
 } 
Fields
firstPage

integer

Page where chunk starts in the document. Inclusive. 1-indexed.

lastPage

integer

Page where chunk ends in the document. Inclusive. 1-indexed.

Tool Annotations

Destructive Hint: ❌ | Idempotent Hint: ✅ | Read Only Hint: ✅ | Open World Hint: ❌

Create a Mobile Website
View Site in Mobile | Classic
Share by: