Use Document AI layout parser with Vertex AI RAG Engine Stay organized with collections Save and categorize content based on your preferences.
TheVPC-SC security controls and CMEK are supported by Vertex AI RAG Engine. Data residency and AXT security controls aren't supported.
This page introduces the Document AI layout parser and how it'sused with RAG Engine.
Document AI
Document AI is adocument-processing anddocument-understandingplatform that takesunstructured data from documents and transforms that unstructured data intofields that are suitable for storage in a database. Structured data leads todata that you can understand, analyze, and consume.
Document AI is built on top of products within Vertex AIwith generative AI to help you create scalable, end-to-end, cloud-based documentprocessing applications. No specialized machine-learning expertise is requiredto use these products.
Document AI layout parser
The layout parser extracts content elements from the document, such as text,tables, and lists. The layout parser then creates context-aware chunks thatfacilitate information retrieval in generative AI and discovery applications.
When it's used for retrieval and LLM generation, the document's layout isconsidered during the chunking process, which improves semantic coherence andreduces noise in the content. All text in a chunk comes from the same layoutentity, such as the heading, subheading, or list.
For file types used by layout detection, seeLayout detection per filetype.
Use the layout parser in Vertex AI RAG Engine
To use the layout parser in Vertex AI RAG Engine, you must createa corpus. To create a corpus, do the following:
In the Google Cloud console, go to theRAG Engine page.
SelectCreate corpus.
In theRegion field, select your region.
In theCorpus name field, enter your corpus name.
In theDescription field, enter a description.
In theData section, select where you want to upload your data.
Expand theAdvanced options section.
In theChunking strategy section, the following default sizes arerecommended:
- Chunking size: 1024
- Chunk overlap: 256
In theLayout parser section, select theDocument AI layout parser option, whichhas the highest accuracy for documents with images or charts.
From theModel field, select your model.
Optional: In theMaximum parsing requests per min field, enter yourmaximum parsing requests.
Optional: In theCustom parsing prompt field, enter your parsingprompt.
ClickContinue.
From theConfigure vector store page, do the following:
In theEmbedding model field, select your embedding model.
In theVector database section, select your database.
ClickCreate corpus.
Limitations
TheImportRagFiles API supports the layout parser, however, the followinglimitations apply:
- Input the file size maximum of 20 MB for all file types.
- There is a maximum of 500 pages per PDF file.
The Document AIquotas andpricing apply.
Enable the Document AI API
You must enable the Document AI API for your project. For more information on enabling APIs, see theService Usage documentation.
Enable the Document AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.
Turn on your layout parser
To turn on Layout Parser, follow these steps:
Create a Layout Parser by following the instructions inCreating and managing processors.
The processor type name is
LAYOUT_PARSER_PROCESSOR.Enable Layout Parser by following the instructions inEnable a processor.
Your RAG knowledge base (corpus)
If you don't have a RAG corpus, then create a RAG corpus. For example, seeCreate a RAG corpus example.
If you already have a RAG corpus, existing files that were imported without alayout parser won't be re-imported when youImport files using LayoutParser.If you want to use a layout parser with your files, delete the files first. Forexample, seeDelete a RAG fileexample.
Importing files using layout parser
Files and folders from various sources can be imported using the layout parser.
Python
To learn how to install or update the Vertex AI SDK for Python,seeInstall the Vertex AI SDK for Python. For more information, see thePython API referencedocumentation.
Replace the following variables used in the code sample:
- PROJECT_ID: Your project ID.
- LOCATION: The region to process the request.
- RAG_CORPUS_ID: The ID of the RAG corpus resource.
- GCS_URIS: A list of Cloud Storage locations. Forexample:
"gs://my-bucket1","gs://my-bucket2". - LAYOUT_PARSER_PROCESSOR_NAME: The resource path to thelayout parser processor that was created. For example:
"projects/{project}/locations/{location}/processors/{processor_id}". - CHUNK_SIZE: Optional: The number of tokens each chunkshould have.
fromvertexaiimportragimportvertexaiPROJECT_ID=YOUR_PROJECT_IDcorpus_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 sessionvertexai.init(project=PROJECT_ID,location="LOCATION")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).layout_parser=rag.LayoutParserConfig(processor_name="projects/{PROJECT_ID}/locations/us/processors/{processor_id}/processorVersions/{processor_version_id}",max_parsing_requests_per_min=120,),max_embedding_requests_per_min=900,# Optional)print(f"Import response:{response}")REST
The code sample shows how to import Cloud Storage files using the layoutparser. For more configuration options, including importing files from anothersource, refer to theImportRagFilesConfigreference.
Before using any of the request data, replace the following variables used inthe code sample:
- PROJECT_ID: Your project ID.
- LOCATION: The region to process the request.
- RAG_CORPUS_ID: The ID of the RAG corpus resource.
- GCS_URIS: A list of Cloud Storage locations. Forexample:
"gs://my-bucket1","gs://my-bucket2". - LAYOUT_PARSER_PROCESSOR_NAME: The resource path to thelayout parser processor that was created. For example:
"projects/{project}/locations/{location}/processors/{processor_id}". - CHUNK_SIZE: Optional: The number of tokens each chunkshould have.
POSThttps://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:importRequest JSON body:
{"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}}},}}To send your request, choose one of these options:
curl
Note: The following command assumes that you have signed in to theGoogle Cloud CLI CLI with your user account by runninggcloud CLIinit or gcloud CLIauth login, orby using Cloud Shell, which automatically signs you into thegcloud CLI CLI . You can check the active account by runninggcloud CLIauth list.Save the request body in a file named request.json, and run thefollowing command:
curl-XPOST\-H"Authorization: Bearer$(gcloudauthprint-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
Note: The following command assumes that you have signed in to thegcloud CLI CLI with your user account by runninggcloud CLIinit or gcloud CLIauth login. Youcan check the active account by running gcloud CLIauthlist.Save the request body in a file named request.json, and run the followingcommand:
$cred=gcloudauthprint-access-token$headers=@{"Authorization"="Bearer$cred"}Invoke-WebRequest`-MethodPOST`-Headers$headers`-ContentType:"application/json; charset=utf-8"`-InFilerequest.json`-Uri"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/ragCorpora/RAG_CORPUS_ID/ragFiles:import"|Select-Object-ExpandContentRetrieval query
When a user asks a question or provides a prompt, the retrieval component in RAGsearches through its knowledge base to find information that is relevant to thequery.
For an example of retrieving RAG files from a corpus based on a querytext, seeRetrievalquery.
Prediction
The prediction generates a grounded response using the retrieved contexts. Foran example, seeGeneration.
What's next
- Vector database choices in Vertex AI RAG Engine
- To learn how to import RAG files, see theImport RAG files example.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.