This page introduces the Document AI layout parser and how it's
used with RAG Engine. Document AI is a document-processing and
document-understanding
platform that takes
unstructured data from documents and transforms that unstructured data into
fields that are suitable for storage in a database. Structured data leads to
data that you can understand, analyze, and consume. Document AI is built on top of products within Vertex AI
with generative AI to help you create scalable, end-to-end, cloud-based document
processing applications. No specialized machine-learning expertise is required
to use these products. The layout parser extracts content elements from the document, such as text,
tables, and lists. The layout parser then creates context-aware chunks that
facilitate information retrieval in generative AI and discovery applications. When it's used for retrieval and LLM generation, the document's layout is
considered during the chunking process, which improves semantic coherence and
reduces noise in the content. All text in a chunk comes from the same layout
entity, such as the heading, subheading, or list. For file types used by layout detection, see Layout detection per file
type. To use the layout parser in Vertex AI RAG Engine, you must create
a corpus. To create a corpus, do the following: In the Google Cloud console, go to the RAG Engine page. Select Create corpus. In the Region field, select your region. In the Corpus name field, enter your corpus name. In the Description field, enter a description. In the Data section, select where you want to upload your data. Expand the Advanced options section. In the Chunking strategy section, the following default sizes are
recommended: In the Layout parser section, select the LLM parser option, which
has the highest accuracy for documents with images or charts. From the Model field, select your model. Optional: In the Maximum parsing requests per min field, enter your
maximum parsing requests. Optional: In the Custom parsing prompt field, enter your parsing
prompt. Click Continue. From the Configure vector store page, do the following: In the Embedding model field, select your embedding model. In the Vector database section, select your database. Click Create corpus. The The Document AI quotas and
pricing apply. You must enable the Document AI API for your project. For more information on enabling APIs, see the
Service Usage documentation.
Enable the Document AI API.
To turn on Layout Parser, follow these steps: Create a Layout Parser by following the instructions in
Creating and managing processors. The processor type name is Enable Layout Parser by following the instructions in
Enable a processor. If you don't have a RAG corpus, then create a RAG corpus. For example, see
Create a RAG corpus example. If you already have a RAG corpus, existing files that were imported without a
layout parser won't be re-imported when you Import files using Layout
Parser.
If you want to use a layout parser with your files, delete the files first. For
example, see Delete a RAG file
example. Files and folders from various sources can be imported using the layout parser. To learn how to install or update the Vertex AI SDK for Python,
see Install the Vertex AI SDK for Python. For more information, see the Python API reference
documentation. Replace the following variables used in the code sample: The code sample shows how to import Cloud Storage files using the layout
parser. For more configuration options, including importing files from another
source, refer to the Before using any of the request data, replace the following variables used in
the code sample: Request JSON body: To send your request, choose one of these options: Save the request body in a file named request.json, and run the
following command: Save the request body in a file named request.json, and run the following
command: When a user asks a question or provides a prompt, the retrieval component in RAG
searches through its knowledge base to find information that is relevant to the
query. For an example of retrieving RAG files from a corpus based on a query
text, see Retrieval
query. The prediction generates a grounded response using the retrieved contexts. For
an example, see
Generation.Document AI
Document AI layout parser
Use the layout parser in Vertex AI RAG Engine
Limitations
ImportRagFiles
API supports the layout parser, however, the following
limitations apply:
Enable the Document AI API
Turn on your layout parser
LAYOUT_PARSER_PROCESSOR
.Your RAG knowledge base (corpus)
Importing files using layout parser
Python
"gs://my-bucket1"
, "gs://my-bucket2"
."projects/{project}/locations/{location}/processors/{processor_id}"
.from vertexai import rag
import vertexai
PROJECT_ID = YOUR_PROJECT_ID
corpus_name = "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}"
paths = ["https://drive.google.com/file/123", "gs://my_bucket/my_files_dir"] # Supports Cloud Storage and Google Drive.
# Initialize Vertex AI API once per session
vertexai.init(project=PROJECT_ID, location="us-central1")
response = rag.import_files(
corpus_name=corpus_name,
paths=paths,
transformation_config=rag.TransformationConfig(
rag.ChunkingConfig(chunk_size=1024, chunk_overlap=256)
),
import_result_sink="gs://sample-existing-folder/sample_import_result_unique.ndjson", # Optional: This must be an existing storage bucket folder, and the filename must be unique (non-existent).
llm_parser=rag.LlmParserConfig(
model_name="gemini-2.5-pro-preview-05-06",
max_parsing_requests_per_min=100,
), # Optional
max_embedding_requests_per_min=900, # Optional
)
print(f"Imported {response.imported_rag_files} files.")
REST
ImportRagFilesConfig
reference.
"gs://my-bucket1"
, "gs://my-bucket2"
."projects/{project}/locations/{location}/processors/{processor_id}"
.POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import
{
"import_rag_files_config": {
"gcs_source": {
"uris": "GCS_URIS"
},
"rag_file_parsing_config": {
"layout_parser": {
"processor_name": "LAYOUT_PARSER_PROCESSOR_NAME"
}
},
"rag_file_transformation_config": {
"rag_file_chunking_config": {
"fixed_length_chunking": {
"chunk_size": CHUNK_SIZE
}
}
},
}
}
curl
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import"
Powershell
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import" | Select-Object -Expand Content
Retrieval query
Prediction
What's next
Use Document AI layout parser with Vertex AI RAG Engine
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-23 UTC.