You can now build an end-to-end retrieval-augmented generation and document analytics pipeline over complex PDFs and documents in BigQuery using standard SQL. By combining layout-aware document parsing and chunking, background vector maintenance in autonomous embedding tables, and natural-language retrieval, you can turn raw files from Google Cloud Storage into searchable, analytics-ready tables that join directly with your structured business data.
Enterprises store critical knowledge inside millions of unstructured PDFs and documents, including annual financial reports, supplier contracts, clinical protocols, and equipment manuals. Bringing those documents into a retrieval-augmented generation workflow to ground your agent or extract structured metrics usually requires stitching together a complex, multi-system pipeline outside your data warehouse:
Brittle text splitting breaks document context: Simple character or token splitters cut right through multi-column layouts, section headers, and financial tables. Separating table headers from rows or headings from paragraphs degrades vector embedding quality and retrieval accuracy.
Repeated multimodal calls drive up latency and cost: Sending entire 100-page filings to a multimodal model for every analytical question fetches the binary file and bills input tokens repeatedly, while general vision prompts can drop rows on dense tables or lack verifiable bounding-box coordinates for compliance audits.
External pipelines add operational overhead: Extracting layout structure usually requires deploying separate Python workers, managing optical character recognition processors, and orchestrating custom jobs to re-ingest text chunks into your database.
Unstructured chunks become isolated from structured data: Standalone vector databases isolate document passages from core analytical data, making cross-table joins difficult.
To solve these challenges, two native document intelligence functions are now generally available in BigQuery: document chunking(AI.CHUNK_DOCUMENT) and document layout parsing(AI.PARSE_DOCUMENT). Paired with autonomous embedding generation(AI.EMBED) and semantic search (AI.SEARCH), these functions let you parse, chunk, embed, search, and join unstructured documents at scale using GoogleSQL.
Both functions bring the Document AI layout parser directly into BigQuery so you can process unstructured documents based on visual layout and hierarchy rather than raw character counts.
Layout-aware chunking powered by Document AI: The document chunking function analyzes titles, headings, sections, paragraphs, lists, and tables to split files into semantically coherent passages. Instead of cutting text at arbitrary character counts, it preserves context across structural boundaries and records the starting and ending page numbers for every chunk. You can also tune the target maximum chunk size up to 2,000 tokens, with a default of 1,000 tokens.
Fine-grained layout extraction and visual grounding: When you need element-level control before chunking or prompting, the document parsing function extracts every title, heading, paragraph, list item, image, page header, page footer, and table into a native BigQuery JSON structure. It converts complex tables with merged cells into structured HTML and captures the page number and normalized bounding-box coordinates for every block.
Automated processor management with no idle fees: You do not need to manually create, train, or manage Document AI processors. When you run either function, BigQuery automatically provisions a single layout parser processor in your project and reuses it across queries. You only pay standard Document AI per-page processing rates and BigQuery slot usage, with no idle holding fee.
Direct Cloud Storage ingestion with end-user credentials: For rapid prototyping and batch ingestion, you can pass a Cloud Storage URI path or wildcard pattern directly into your query. BigQuery authenticates using your end-user credentials by default, so you can start parsing or chunking files immediately without setting up external connections first.
Built to scale across massive document repositories: As your workload grows from a few dozen PDFs and documents to millions of files, both functions scale with BigQuery's distributed execution engine. They accept Cloud Storage URIs, object tables, standard tables containing object references, or directory listing subqueries, and capture file-level parsing errors per row without failing your entire multi-terabyte query.
Designed to join unstructured and structured data: Because your parsed blocks and document chunks land in standard BigQuery tables alongside Cloud Storage object metadata, you can immediately join extracted document content with your structured business tables in a single query.
Both functions use the same underlying Document AI layout parser, and you can use them independently or together depending on your workload:
Use document chunking for turnkey RAG and semantic search: Reach for the chunking table-valued function when your goal is to split documents into context-rich text passages for vector embedding, semantic retrieval, and question answering in a single step.
Use document layout parsing for pre-filtering, table extraction, visual citations, and redaction: Reach for the scalar parsing function when you want to parse large documents once and filter by page range, section type, or keyword in SQL before paying generative model token costs. It is also ideal when you need to isolate HTML tables for structured extraction, highlight exact bounding boxes in a frontend user interface, or mask sensitive personal information in text blocks before passing them to a language model.
Chain both functions to parse once and chunk later: If you run multiple analytical workflows over the same document corpus, you can materialize the full hierarchical layout tree once with the parsing function and pass that stored column directly into the chunking function later without calling the Document AI processor a second time.
| Capability | AI.CHUNK_DOCUMENT | AI.PARSE_DOCUMENT | | Function type | Table-valued function returning one row per chunk | Scalar function returning one JSON object per document | | Primary use cases | Turnkey RAG ingestion, autonomous embeddings, and semantic search with AI.SEARCH | Parse-once SQL pre-filtering, HTML table extraction, visual bounding-box citations, and PII redaction | | Input sources | Cloud Storage URI, object table, ObjectRef query, or raw-docai output from AI.PARSE_DOCUMENT | Cloud Storage URI or ObjectRef value | | Key output fields | chunk_id, start_page, end_page, content, status, uri, size, updated, ref | metadata.schema, errors, and blocks array containing id, type, content, page_number, and bbox | | Table handling | Keeps table content grouped with surrounding section headings inside text chunks | Emits each table block as structured HTML preserving row and column spans |
Let's walk through how you can build a complete RAG retrieval pipeline over a bucket of PDF annual reports in three SQL statements.
First, create a BigQuery table to store your document chunks and configure an autonomous embedding column. Defining a generated embedding column tells BigQuery to automatically compute and maintain vector embeddings in the background whenever new chunks arrive.
You can use the built-in Gemma embedding model so that your text stays inside BigQuery and embeddings are computed using BigQuery slots, or you can point to a Gemini platform embedding endpoint.
Next, parse your PDFs and insert the layout-aware chunks into your table. By passing a Cloud Storage wildcard URI directly to the chunking function, BigQuery authenticates with your end-user credentials, runs the Document AI layout parser across every matching PDF, and writes the structured chunks into your table.
Filtering for rows with an empty status string keeps only the chunks that parsed cleanly, while BigQuery's background service begins populating the embedding column automatically.
Once your chunks are ingested and embedded, you do not need to write nested embedding subqueries to search them. Pass your table, the source text column name, and a natural-language question directly into the search function.
BigQuery automatically embeds your search query using the same model configured on the table and returns the most relevant document chunks along with their source URI and page boundaries.
Because your PDF chunks and embeddings live inside BigQuery alongside your operational data, you can combine semantic search with relational analytics in one query.
For example, if you have a structured table of company metadata and financial metrics, you can join it directly with your semantic search results to filter or enrich your retrieved PDF passages, or pass the combined context into a generative function to synthesize a grounded answer: When your workflow requires inspecting individual layout blocks, extracting structured rows from dense tables, or surfacing bounding-box coordinates before running downstream analytics, you can use the document parsing function directly.
Instead of sending an entire 200-page filing to a generative model, you can parse the document layout once into a BigQuery table and use standard SQL to isolate specific pages and block types. Each block in the default layout schema includes its sequential identifier, block type, text or HTML table content, page number, and normalized bounding box.
Annual reports, invoices, and clinical trial summaries often contain complex tables with merged cells where general multimodal prompts can misalign columns. Because the layout parser emits each table block as structured HTML that preserves row and column spans, you can filter specifically for table blocks and pass that compact HTML into a generative extraction query to produce typed BigQuery columns with lower token usage:
With native document layout parsing, structure-aware chunking, autonomous embedding generation, and semantic search, you can go from raw PDFs and documents in Cloud Storage to production-scale retrieval and structured analytics in minutes, using the SQL skills your team already has.
Read the AI.CHUNK_DOCUMENT reference documentation and AI.PARSE_DOCUMENT reference documentation to explore all supported input sources, authentication options, and output schemas.
Learn how to configure autonomous embedding generation and query tables with AI.SEARCH.
Follow the step-by-step tutorial on parsing PDFs in a RAG pipeline and learn more about the Document AI layout parser to try it in your own BigQuery project.