Skip to main content

Overview

The RAG (Retrieval-Augmented Generation) API allows you to upload documents and create knowledge bases that your AI agents can search. Documents are uploaded to Google Cloud Storage and indexed in Vertex AI Search for semantic retrieval.
Workflow: First create a DataStore using POST /rag/datastores, then upload files to that DataStore using POST /rag/upload. Files are indexed asynchronously via background tasks.

Authentication

All RAG endpoints require API key authentication with specific scopes:
Scopes Required: The rag:upload, rag:read, and rag:delete scopes must be explicitly enabled when creating API keys. They are not enabled by default.
Include your API key in the X-API-Key header:
See Authentication for details.

Supported File Types

The following file types can be uploaded to RAG Datastores:
File Limits: Maximum 10MB per file, maximum 10 files per upload request.

Create DataStore

Create a new DataStore to organize uploaded documents.

Endpoint

Request Body

Request Example

cURL
Python
JavaScript

Response

Status Code: 200 OK

Response Fields

Error Responses

409 Conflict - DataStore Already Exists

Upload Files

Upload files to an existing DataStore. Files are encoded as Base64 and indexed asynchronously.

Endpoint

DataStore Required: You must create a DataStore first using POST /rag/datastores. File uploads to non-existent DataStores will fail with a 404 error.

Request Body

Request Example

cURL
Python

Response

Status Code: 200 OK

Response Fields

Error Responses

404 Not Found - DataStore Not Found
400 Bad Request - Unsupported File Type
400 Bad Request - File Too Large
400 Bad Request - Invalid Base64

List DataStores

Retrieve all DataStores in your organization.

Endpoint

Request Example

cURL
Python

Response

Status Code: 200 OK

Response Fields


List Uploads

Retrieve a paginated list of file uploads for your organization.

Endpoint

Query Parameters

Request Example

cURL
Python

Response

Status Code: 200 OK

Upload Status Values

Response Fields


Get Upload Status

Retrieve detailed status of a specific upload.

Endpoint

Path Parameters

Request Example

cURL

Response

Status Code: 200 OK

Response Fields

Error Responses

404 Not Found

List DataStore Files

Retrieve all files in a specific DataStore with their indexing status.

Endpoint

Path Parameters

Request Example

cURL
Python
JavaScript

Response

Status Code: 200 OK

Response Fields

Error Responses

404 Not Found

Delete DataStore

Delete a DataStore and all its contents (files and indexed documents).

Endpoint

Destructive Operation: This permanently deletes all files and indexed documents in the DataStore. This action cannot be undone.

Path Parameters

Query Parameters

Request Example

cURL
Python
JavaScript

Response

Status Code: 200 OK

Response Fields

Error Responses

404 Not Found
409 Conflict - DataStore In Use

Delete File

Delete a single file from a DataStore while preserving the DataStore itself.

Endpoint

Partial Deletion: Only the specified file is removed. The DataStore and other files remain intact.

Path Parameters

Request Example

cURL
Python
JavaScript

Response

Status Code: 200 OK

Response Fields

Error Responses

404 Not Found - DataStore
500 Internal Server Error - File Not Found

Best Practices

When an upload is in processing or indexing status, poll the status endpoint to check for completion:
Upload multiple related files in a single request (up to 10 files):
Create separate DataStores for different topics or document types:
  • By Department: “HR Policies”, “Engineering Docs”, “Sales Materials”
  • By Project: “Project Alpha”, “Project Beta”
  • By Type: “Legal Contracts”, “Technical Specs”, “Meeting Notes”
This helps agents retrieve more relevant information by searching specific DataStores.
For large documents:
  • Split large PDFs into smaller chapters
  • Remove unnecessary images from documents
  • Use text formats (TXT, MD) when formatting isn’t important
  • Compress images before including in documents

Authentication

Learn about API key scopes and authentication

RAG Knowledge Base Guide

User guide for RAG features

Chat Completions

Use RAG in conversations

Error Codes

Full list of error codes and solutions