← Technology, Science & Infrastructure ▣ Distilled locally

Process your PDFs for scalable search and analytics with BigQuery document AI

By Xiaoqiu Huang
December 1, 2026  ·  Google Cloud Blog ↗
Process your PDFs for scalable search and analytics with BigQuery document AI

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.

Why PDF and document parsing is the bottleneck for enterprise RAG

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:

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.

What BigQuery document intelligence functions do and why they stand out

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.

When to use document chunking vs. document layout parsing

Both functions use the same underlying Document AI layout parser, and you can use them independently or together depending on your workload:

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

Build a serverless RAG pipeline in three SQL steps

Let's walk through how you can build a complete RAG retrieval pipeline over a bucket of PDF annual reports in three SQL statements.

Step 1: Create an autonomous embedding table

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.

code_block <ListValue: [StructValue([('code', "CREATE SCHEMA IF NOT EXISTS rag_demo;\r\n\r\n\r\nCREATE TABLE rag_demo.doc_chunks (\r\n uri STRING, -- source PDF in Cloud Storage\r\n chunk_id INT64,\r\n start_page INT64,\r\n end_page INT64,\r\n content STRING, -- extracted chunk text\r\n -- BigQuery fills in and maintains this column in the background\r\n content_embedding STRUCT<result ARRAY<FLOAT64>, status STRING>\r\n GENERATED ALWAYS AS (\r\n AI.EMBED(content, model => 'embeddinggemma-300m')\r\n -- Or use a Gemini platform endpoint:\r\n -- AI.EMBED(content, connection_id => 'us.my_connection',\r\n -- endpoint => 'text-embedding-005')\r\n ) STORED OPTIONS (asynchronous = TRUE)\r\n);"), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7f3e65ed5550>)])]>

Step 2: Ingest PDF chunks with AI.CHUNK_DOCUMENT and EUC

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.

code_block <ListValue: [StructValue([('code', "INSERT INTO rag_demo.doc_chunks (uri, chunk_id, start_page, end_page, content)\r\nSELECT uri, chunk_id, start_page, end_page, content\r\nFROM AI.CHUNK_DOCUMENT(\r\n 'gs://my-bucket/annual-reports/*.pdf',\r\n chunk_size => 500 -- optional; default is 1000 tokens\r\n)\r\nWHERE status = ''; -- keep only chunks that parsed without errors"), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7f3e65ed6250>)])]>

Step 3: Fetch related chunks with AI.SEARCH

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.

code_block <ListValue: [StructValue([('code', "SELECT\r\n base.uri,\r\n base.start_page,\r\n base.end_page,\r\n base.content,\r\n distance\r\nFROM AI.SEARCH(\r\n TABLE rag_demo.doc_chunks,\r\n 'content', -- column that has a generated embedding\r\n 'What were the main drivers of revenue growth in 2025?',\r\n top_k => 5\r\n)\r\nORDER BY distance;"), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7f3e65ed6310>)])]>

Bonus: Join unstructured document chunks with structured tables

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:

code_block <ListValue: [StructValue([('code', "SELECT\r\n f.company_name,\r\n f.ticker,\r\n f.fiscal_year_revenue_usd,\r\n search_results.base.uri,\r\n search_results.base.start_page,\r\n search_results.base.end_page,\r\n search_results.base.content,\r\n search_results.distance\r\nFROM AI.SEARCH(\r\n TABLE rag_demo.doc_chunks,\r\n 'content',\r\n 'What were the main drivers of revenue growth in 2025?',\r\n top_k => 10\r\n) AS search_results\r\nJOIN rag_demo.company_financials AS f\r\n ON search_results.base.uri = f.report_gcs_uri\r\nWHERE f.sector = 'Technology'\r\nORDER BY search_results.distance;"), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7f3e65ed7110>)])]>

Go further: Parse document layout, extract tables, and reuse parsed output

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.

Filter layout blocks by page and element type

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.

code_block <ListValue: [StructValue([('code', "-- Parse PDFs into structured JSON and filter for headings and tables on pages 1 to 5\r\nWITH parsed_docs AS (\r\n SELECT\r\n uri,\r\n AI.PARSE_DOCUMENT(ref) AS parsed_doc\r\n FROM\r\n OBJ.LIST('gs://my-bucket/annual-reports/*.pdf')\r\n)\r\nSELECT\r\n uri,\r\n INT64(block.id) AS block_id,\r\n INT64(block.page_number) AS page_num,\r\n STRING(block.type) AS block_type,\r\n STRING(block.content) AS block_content,\r\n block.bbox AS bounding_box\r\nFROM\r\n parsed_docs,\r\n UNNEST(JSON_QUERY_ARRAY(parsed_doc.blocks)) AS block\r\nWHERE\r\n STRING(block.type) IN ('heading', 'table')\r\n AND INT64(block.page_number) BETWEEN 1 AND 5;"), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7f3e65ed7090>)])]>

Extract structured columns from parsed HTML tables

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:

code_block <ListValue: [StructValue([('code', "-- Isolate parsed HTML tables and extract strongly typed financial columns\r\nWITH parsed_financial_reports AS (\r\n SELECT\r\n uri,\r\n AI.PARSE_DOCUMENT(ref) AS parsed_doc\r\n FROM\r\n OBJ.LIST('gs://my-bucket/financial-reports/*.pdf')\r\n),\r\ntable_blocks AS (\r\n SELECT\r\n uri,\r\n INT64(block.page_number) AS page_num,\r\n STRING(block.content) AS table_html\r\n FROM\r\n parsed_financial_reports,\r\n UNNEST(JSON_QUERY_ARRAY(parsed_doc.blocks)) AS block\r\n WHERE\r\n STRING(block.type) = 'table'\r\n)\r\nSELECT\r\n uri,\r\n page_num,\r\n AI.GENERATE(\r\n CONCAT('Extract quarterly revenue figures from this HTML table: ', table_html),\r\n output_schema => 'fiscal_quarter STRING, revenue_millions FLOAT64, yoy_growth_pct FLOAT64'\r\n ).* EXCEPT (full_response, status)\r\nFROM\r\n table_blocks;"), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7f3e65d9be50>)])]>

Get started today

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.

Originally published by Google Cloud Blog ↗ · rebuilt here from its own full-text RSS feed · all rights remain with the publisher, please read and support them there.