---
title: "POST /v1/{+parent}:retrieveContexts"
method: POST
path: "/v1/{+parent}:retrieveContexts"
tags: ["projects"]
---

# POST /v1/{+parent}:retrieveContexts

`POST /v1/{+parent}:retrieveContexts`

Retrieves relevant contexts for a query.

## Path parameters

- `parent` string, required

## Request body

- GoogleCloudAiplatformV1RetrieveContextsRequest — Request message for VertexRagService.RetrieveContexts.
  - `query` GoogleCloudAiplatformV1RagQuery — A query to retrieve relevant contexts.
    - `text` string — Optional. The query in text format to get relevant contexts.
    - `ragRetrievalConfig` GoogleCloudAiplatformV1RagRetrievalConfig — Specifies the context retrieval config.
      - `topK` integer — Optional. The number of contexts to retrieve.
      - `filter` GoogleCloudAiplatformV1RagRetrievalConfigFilter — Config for filters.
        - `vectorDistanceThreshold` number, double — Optional. Only returns contexts with vector distance smaller than the threshold.
        - `vectorSimilarityThreshold` number, double — Optional. Only returns contexts with vector similarity larger than the threshold.
        - `metadataFilter` string — Optional. String for metadata filtering.
      - `ranking` GoogleCloudAiplatformV1RagRetrievalConfigRanking — Config for ranking and reranking.
        - `llmRanker` GoogleCloudAiplatformV1RagRetrievalConfigRankingLlmRanker — Config for LlmRanker.
          - `modelName` string — Optional. The model name used for ranking. See [Supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#supported-models).
        - `rankService` GoogleCloudAiplatformV1RagRetrievalConfigRankingRankService — Config for Rank Service.
          - `modelName` string — Optional. The model name of the rank service. Format: `semantic-ranker-512@latest`
  - `vertexRagStore` GoogleCloudAiplatformV1RetrieveContextsRequestVertexRagStore — The data source for Vertex RagStore.
    - `ragResources` GoogleCloudAiplatformV1RetrieveContextsRequestVertexRagStoreRagResource[] — 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.
      - `ragFileIds` string[] — Optional. rag_file_id. The files should be in the same rag_corpus set in rag_corpus field.
      - `ragCorpus` string — Optional. RagCorpora resource name. Format: `projects/{project}/locations/{location}/ragCorpora/{rag_corpus}`
    - `vectorDistanceThreshold` number, double — Optional. Only return contexts with vector distance smaller than the threshold.

## Response `200`

Successful response

---

[API](https://skmtc.net/google/apis/aiplatform.md) · [All operations](https://skmtc.net/google/apis/aiplatform/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/google/aiplatform/versions/b608d71b91f0/schema)
