How document ingestion works in AI Drive

AI Drive processes tens of millions of pages every month. This is how one uploaded file becomes pages an agent can read, charts it can inspect and passages it can search.

Overview

Ingestion is everything AI Drive does to a file between upload and the moment an agent can use it. An upload on its own is only a stored file. To answer from it, an agent has to open a specific page, see a chart as it was drawn and find a passage by what it means.

For each file version, ingestion extracts the contents and saves text with page numbers so the agent can read and cite a specific page, images of each page so it can see charts and tables in their original layout, and an index of passages so it can find one by meaning without knowing the page number. It also fills in the title, document type and description that identify the file in a folder.

This matters anywhere an agent answers from your documents. It can find the right clause in a long contract and cite its page, read figures from a chart that the text only mentions, and answer a question that uses different words from the document.

Production figures in this article cover the 30 days to December 3, 2026. In that time, ingestion extracted roughly 50 million pages.

Figure 1

From an upload to a file the agent can use

AI Drive
CLOUD STORAGEGKE SPOTBrowseruploads the fileUploaded filenew version per uploadsigned URL uploadnotification: file path + generationUpload queuePub/SubSubscribers2–5 pods · claim filespullsFile statusnot setIN_PROGRESSSUCCESSIN_PROGRESS → SUCCESSclaimsExtraction service3–25 podstext from every file type · OCRfile pathPage images.images.feather · JPEGPage text.json · numbered pages1 saves3 renders4 sets SUCCESS2 publishes jobfor this file versionEnrichment queuePub/SubEnrichment worker3–15 podsmetadata first, then the indexpullsreadsMetadatatitle · authors · typeSearch indexpassages + vectorswriteswritesQwen3.5-9Bself-hosted · fine-tunedEmbedding modelthe owner’s active modelfirst 10 pagespassagesAgent toolsread_file_pages · zoom_page_region · search_file_semantic · grep_toolread by the agentUpload queue pathEnrichment queue path
Upload queue · Pub/SubUpload notificationCloud Storage reports the new file and its version.
Extraction serviceExtract the textEvery supported file type becomes numbered pages.
SavedNumbered page textFrom here on, the agent can read and cite a page.
Publish an enrichment job for this file version
Extraction service continues
  1. Render page imagesPDF, Word and PowerPoint pages are saved as images.
  2. Record SUCCESSMarks the file version that was processed.

Upload queue · The notification is acknowledged.

Enrichment queue · Enrichment worker
  1. Check the file versionA job for a replaced file stops here.
  2. Generate metadataTitle, authors, document type and description.
  3. Build the search indexPassages and their vectors, for search by meaning.

Enrichment queue · The job is acknowledged.

From upload to the first worker

Ingestion starts when a file lands in storage. Before any text is extracted, two things have to be settled: only one worker picks up the file, and that worker knows exactly which version of the file it is working on.

The browser uploads the file directly to Cloud Storage using a signed URL. Cloud Storage then sends a Pub/Sub notification with the file’s path and generation number, which identifies the exact version that was uploaded. A subscriber reads the notification, filters out paths that are not eligible for ingestion and claims the file. It then passes the file to the extraction service, which does the work in the next section.

The claim uses optimistic locking. A subscriber does not hold a lock while it works. It reads the file’s metageneration, a counter that Cloud Storage increases every time the file’s metadata changes, and writes the in-progress marker on the condition that the counter has not moved since it was read.

Suppose two subscribers read the same file at metageneration 7. Each asks storage to mark the file in progress only if the counter is still 7. The first write succeeds and moves it to 8. The second is rejected, and that subscriber sees the file is already taken. The claim lives on the file itself, so no separate lock service is needed.

The claim only marks the file as taken. When extraction starts, the extraction service pins the attempt to the version currently at that path and verifies it again after download, so the text it saves belongs to one known version.

In production, a file waited a median of 0.34 seconds in the queue before extraction started, and 90 percent of files started within 1.4 seconds.

Extracting text and page images

The extraction service saves two things for a file: its text, and a picture of each page.

Text

Every supported file is turned into the same thing: text split into numbered pages. What counts as a page depends on the file type.

A PDF with a text layer keeps its original page numbers. Word and PowerPoint files are converted to PDF first, so extraction works against rendered pages. Spreadsheets and CSV files have no pages, so the service groups numbered rows into logical pages and keeps the sheet name. Text, markup and calendar files are split into readable segments. An email is read as a message. An image is analyzed, and that analysis becomes one page of text.

Whatever the source, a tool can then ask for a page range and get back a specific part of the file.

A scanned PDF has no text to save until it has been through OCR. When a PDF has pages but no usable text, the service runs OCR on it and writes a searchable PDF back to the same path. That replacement is a new version of the file, and the rest of ingestion continues with it.

The service saves or reuses a JSON file containing the full text and its numbered pages. When it creates the JSON, it also records the page count.

This is where the work branches. Ingestion runs on two queues. The upload queue carries the Cloud Storage notifications to the extraction service. The enrichment queue carries one job per extracted file to a second worker, the enrichment worker, which generates the metadata and builds the search index. Extraction publishes that job as soon as the text is saved, so enrichment can start before the page images are ready.

Page images

Text extraction can recover every label on a chart and still lose which line rises. So after the text is saved, the service also keeps a picture of each page for PDF, Word and PowerPoint files.

PDFs are rendered directly. Word and PowerPoint files are rendered from the PDF created for them during extraction. Spreadsheets, text, email and calendar files have no page layout to preserve, so they get no page images. A standalone image is already a picture, so the service only stores a smaller copy when it is wider or taller than 3,072 pixels.

Each page is drawn the way a PDF viewer would show it, including values typed into form fields. The render is scaled so the longer side stays within 3,072 pixels, then saved as a JPEG. A long document is split into batches of 100 pages that render in parallel.

All pages of a file go into one .images.feather file, written one page at a time so a large document never sits fully in memory. The file is tagged with the version it was rendered from. If current images already exist for that version, the service reuses them and skips rendering.

Each image keeps the same page number as the text, so the two can be read together. Rendering runs after the enrichment job is published, so it never holds up metadata or the search index, and the file can be read by page while its images are still being rendered.

Extraction time in production

This is how long the extraction service spent on one uploaded file in production. The p90 column is the time that 90 percent of files finished within, and p95 is the same for 95 percent.

File typeMedianp90p95
Text, Markdown, CSV and HTML0.65 s0.90 s1.07 s
PDF0.96 s3.93 s7.94 s
Spreadsheets0.81 s2.37 s6.81 s

For a typical PDF, reading the text itself takes a few hundredths of a second. The rest of the time goes to downloading the file and saving the results.

Generating metadata

Metadata is the short record that identifies a file without opening it: a title, the authors, a document type and a description of a few sentences. It is what fills in beside the filename in a folder. The enrichment worker generates it from the extracted text.

Production walkthrough · Folder view

Metadata appearing after an upload

AI Drive

Two PDFs are uploaded to a folder. Each filename shows immediately, the page count follows once the text is extracted, and the title, author, document type and description fill in once metadata is generated. Opening a file shows the full record, here for the 48-page NIST AI Risk Management Framework.

Before it starts, the worker checks that the file version still matches the job and that the extracted text exists. A job for a replaced file stops here.

The worker sends the model up to the first ten pages of text, along with the images of those pages. In our internal research, the first ten pages alone were enough to produce proper metadata for more than 95 percent of files. If the text is too long for the model, the worker trims it from the end and keeps the beginning.

The request goes to a self-hosted Qwen3.5-9B model that AI Drive fine-tuned for this task. The worker checks the returned model identity, completion reason and JSON schema before accepting the answer.

Building the search index

The search index is what lets an agent find text by meaning. Metadata describes the file as a whole, and the index describes each part of it. The same enrichment worker builds it once metadata is done.

The worker first splits the extracted text into short passages. Neighbouring passages overlap slightly, so a sentence that falls on a boundary still appears whole in one of them. Spreadsheets are split without overlap, after the repeated header text is removed.

It then turns each passage into a vector, a list of numbers that represents its meaning, using the owner’s active embedding model. Passages with similar meaning get vectors that are close together. A question is later converted with the same model and compared against them, which is why the model has to match. The worker reuses a cached vector when it has already embedded the same passage with the same model.

The vectors are saved together with the passage text in one index file per embedding model. Each passage keeps the page references found in its text, so a search result can point back to a page. Before saving, the worker checks the file and text versions again, so an older job cannot overwrite a replacement’s results.

In production, the enrichment worker embedded 85 million passages over the 30-day period. Embedding and saving one file took a median of 0.6 seconds, and 90 percent of files finished within 1.6 seconds.

Tracking completion

A file becomes ready in stages, and each stage records its result on the file itself. That makes it possible to see exactly how far any file has progressed.

Extraction sets ingestionStatus on the file. The value is IN_PROGRESS while a worker holds the file, SUCCESS once the numbered text is saved, or FAILED with an error code, such as a password-protected PDF or a file with no text. The success write is conditional on the file’s generation, so it can only mark the version that was actually processed. At SUCCESS the file can already be read by page, while metadata and the search index are still being prepared.

Enrichment shows its progress through its results: the metadata fields on the file and the index saved for it. When an index cannot be built, the worker records the reason on the file, so it is always clear why a file is not in search.

A typical file in production was searchable 6.6 seconds after upload. This is measured from the upload request to the moment the file’s search index is saved, and it includes extraction, metadata and embedding. Most of that time is the enrichment step, where metadata is generated before the index is built.

Handling duplicates and retries

The upload queue and the enrichment queue both use Pub/Sub’s exactly-once delivery, so a message that a worker has acknowledged is not delivered again. A message can still come back before it is acknowledged, for example when a worker is interrupted mid-job or returns it for a retry. The pipeline is built so that repeating a step is safe: results are tied to a file version and checked against it before they are saved.

When a worker receives a message, it chooses between three outcomes. It acknowledges the message when nothing is left to do, leaves it for redelivery when the work can still succeed, or stops when retrying cannot help.

Figure 2

Three messages and what the worker does with each

AI Drive
CLOUD STORAGEWORKERSUpload queuePub/SubDUPLICATEA duplicate messageFile 1deliverschecksackSUCCESSfor a file that is already savedchecking the fileduplicate · nothing to redomessage 1acked · removedRETRYA message that hits a timeoutFile 2deliverssavesacknot ackedacknot setIN_PROGRESSSUCCESSwaiting in the queueattempt 1 · storage timeoutleft for redeliveryattempt 2 · storage timeoutleft for redeliveryattempt 3 · savingsaved on the third attemptmessage 2acked · removedshort waitlonger waitNO RETRYA message for a locked PDFFile 3deliversrecordsacknot setIN_PROGRESSFAILEDwaiting in the queuepassword-protected · cannot be readreason recorded · not retriedmessage 3acked · removed1a queue message2a message returned for another attempt1112222222333

A duplicate is a message for work that is already done or already under way, and it usually comes from a redelivery. The worker decides what to do by looking at the file, not the message. If that version has already succeeded, it acknowledges the message and does nothing. If another worker holds a recent claim on the file, it leaves the message alone and lets that worker finish. If the file was replaced while the message waited, it acknowledges the old message and skips it, because the replacement has its own generation and its own message.

A message is retried after a temporary failure, such as a storage timeout, a write conflict or a rate-limited model call. Pub/Sub redelivers with exponential backoff, so each retry waits longer than the last and a struggling dependency gets time to recover. A retry does not start from zero. If a worker is interrupted partway through indexing, the next attempt reuses the batches already saved when the default embedding model is in use.

A message is not retried when the input itself is the cause. A password-protected PDF or a deleted source file gives the same result every time. The worker records the outcome on the file and acknowledges the message, which keeps the queue clear for work that can succeed. Uploading an unlocked or corrected file creates a new version and new work.

Three timers keep a long-running worker and a duplicate delivery apart. Pub/Sub keeps renewing the delivery lease while a worker holds the message. The in-progress marker on the file expires after five minutes by default, after which another worker may try to claim it. Each stage also reserves the file version for up to 30 minutes, and a second run cannot start while that reservation is active.

In production, 99.2 percent of uploaded files were extracted successfully. Leaving out files that cannot be read, such as invalid PDFs and files deleted before processing, the figure is 99.8 percent. Extraction succeeded on the first attempt, with no retry, for 97.8 percent of files.

Scaling the workers

The three parts of the pipeline are sized separately. The subscribers receive the upload notifications. They only filter, claim and pass files on, so a few are enough: they scale between 2 and 5 pods on the depth of the upload queue.

The extraction service scales between 3 and 25 pods. An autoscaler checks the upload queue every five seconds and adds pods as the backlog grows. It also scales on CPU use, so heavy files add capacity even when the queue is short.

The enrichment worker scales between 3 and 15 pods, on the depth of the enrichment queue. Because the two queues are measured separately, a burst of uploads adds extraction capacity first, and enrichment capacity follows as the extracted files arrive.

Scaling down is gradual. At most half of the pods are removed in one step, and extraction waits for the load to stay low for a few minutes before it shrinks, so a short lull does not remove capacity the next burst will need.

Running on Spot instances

The whole pipeline runs on GKE Spot instances: the subscribers, the extraction service and the enrichment worker. Spot capacity costs less than standard capacity, with one condition. Google can reclaim an instance at short notice.

The saving is the reason to accept that condition. Google prices Spot capacity up to 91 percent below the on-demand price, and ingestion is compute-heavy work: converting Office files, running OCR and rendering every page as an image. The autoscaling from the previous section adds to it. Each service shrinks back to its minimum when its queue is empty, so the capacity for a burst is paid for only while the burst lasts.

Ingestion suits that trade well. Its work arrives as queue messages, each message covers one file version, and the results that matter are saved to storage as each step completes. Losing a pod delays some files. It does not lose them.

When an instance is reclaimed, Kubernetes sends each of its pods a SIGTERM and gives it up to 25 seconds to stop. On SIGTERM, a worker stops pulling from the queue at once. A message it has received but not yet started is handed back to Pub/Sub with a negative acknowledgement, so Pub/Sub redelivers it to another pod. A message already in progress keeps its delivery lease and is allowed to finish. If it ends without a result, it is handed back the same way.

If the 25 seconds run out first, the pod is stopped with a SIGKILL and nothing is sent at all. The delivery lease covers that case. The worker is no longer renewing it, so the lease expires and Pub/Sub redelivers the message on its own. Either way, no message depends on a worker shutting down cleanly.

Figure 3

Three files on an instance that is reclaimed

AI Drive
CLOUD STORAGESIGTERM25 seconds to stopSIGKILLSIGKILLUpload queuePub/Subfile 3: delivery lease expiresSPOT INSTANCE AExtraction podfile 1file 2file 3in progressfinished · ackedreceived, not startedhanded backin progresscut offrunningreclaimedstoppedSPOT INSTANCE BrunningExtraction podfile 2in progressfinished · ackedfile 3in progressfinished · ackedpullsnackredeliverssavessavessavesFile 1savedFile 2savedFile 3saved1the queue message for one file123221233

The safeguards from the earlier sections then do the rest. The new worker checks the file’s version and status before it starts, the claim left by the interrupted worker expires, and an indexing job reuses the batches that were already saved. Extraction pods are also spread across different machines where possible, so one reclaimed instance takes only a small part of the capacity with it.

How the agent uses the file

Everything ingestion saves is there for the agent’s tools. Each tool reads one or more of the outputs described above.

ToolWhat it doesBuilt on
read_file_pagesReads a page range and returns the numbered text with its citation. It can include the page images for a visual question.Page text and page images
zoom_page_regionCrops and magnifies part of a page, for small print or a detail in a chart.Page images
search_file_semantic
search_folder_semantic
Finds passages by meaning, in one file or across a folder.Search index
search_file_lexical_bm25
search_folder_lexical_bm25
Finds passages by keyword and ranks them by relevance, in one file or across a folder.Passages in the search index
grep_toolFinds an exact word or pattern.Extracted text
list_folder_contents
get_drive_object_metadata
Lists files and shows the title, document type and description of each.Metadata

When the agent knows the page, it reads it directly with read_file_pages. The tool checks read access first. Page reads work as soon as the text is saved, even while the search index is still being built.

When the agent does not know the page, it searches. Semantic search converts the question to a vector with the same model used for the file, compares it with the stored passage vectors and returns the closest matches first. That is how a question can find the right passage even when the document uses different words. Keyword search and grep_tool cover the opposite case, where the exact term matters, such as a name, a clause number or an amount. Each result carries the passage text, a citation link and the page numbers found in the passage.

A single question often uses several tools. The agent searches to find the passage, reads the page around it for context, and zooms in when the answer sits in a chart or a table.

Production walkthrough · Single-file search

A question answered with a citation

AI Drive

The agent is asked how much notice is required before renewal. It searches GitLab’s Subscription Agreement, finds the 30-day requirement and cites it in the answer. Clicking the citation opens the PDF at section 4.2 on page 5, where the clause appears.

Summary

Ingestion turns one upload into four saved results: numbered page text, page images, metadata and a search index. Each one is tied to the file version it was made from, so the agent reads, sees and searches the same document.

Three choices hold the pipeline together. Work moves through two queues, so extraction and enrichment scale separately. Every step is safe to repeat, so a redelivered message or a reclaimed instance delays a file and does not lose it. The text is saved first, so a file can be read while its images, metadata and index are still being prepared.

Together they let AI Drive process tens of millions of pages every month on Spot capacity, and give the agent a file it can read by page, inspect as an image and search by meaning.