Agent Retrieval 中新增的托管数据摄取和 SearchDocuments 功能的指南,用于在不编写摄取管道的情况下搜索 PDF、Office 文件和视频。
在代理能够回答关于您的 PDF 文件的问题之前,必须有人构建管道:解析每个文件,将其拆分为块,对每个块进行嵌入,将块写入向量数据库,然后学习该数据库的模式以进行查询。对于视频则更加复杂:转码文件,将其切割成片段,嵌入帧,并跟踪每个片段来自哪个视频的哪一秒。
此前:管道的每一步都是您需要单独为文档和视频编写和维护的自定义代码。
这些代码中的大部分与您的应用程序无关。最近添加到 Agent Retrieval(前身为 Vector Search 2.0)的两个功能现已进入公开预览阶段,从而减轻了您的工作负担。托管数据摄取(Managed Ingestion)为您构建管道:将数据存储指向 Cloud Storage 中的文件,该服务会使用 Gemini Embedding 2 对其进行解析、分段和嵌入。第二个新功能 SearchDocuments 随后通过一次 API 调用搜索数据存储,并返回带有页码或时间戳的匹配段落。在我们的测试中,18 份 Alphabet 投资者 PDF 文件从公共 Cloud Storage 存储桶变为可搜索且引用页码的结果,耗时约 9 分钟;而 19 分钟的视频通过视觉和语音音频实现可搜索性,每次查询仅需 0.3 到 0.5 秒,无需任何解析、分块、转录或嵌入代码。
本指南涵盖如何创建数据存储、导入文档和视频,以及使用过滤器、重排序和音频感知视频搜索功能进行搜索。
托管数据摄取和 SearchDocuments 带来的能力
此后:为文档(UNSTRUCTURED)和视频(VIDEO)创建单独的数据存储,将每个存储指向 Cloud Storage,并通过一次 SearchDocuments 调用进行搜索,返回带有引用来源的结果。
将托管数据摄取与 SearchDocuments 结合使用可带来多项即时优势:
无需摄取管道:直接从 Cloud Storage 导入 PDF、DOCX、PPTX、XLSX 和 TXT 文件,或 MP4、MOV、WebM、MKV 和其他视频格式。解析、分段、嵌入以及向量集合(Collection)及其模式均由系统处理。
带引用的答案:每个结果都包含其源文件 URI 以及文档的页码范围或视频的起止时间,以便您的代理可以准确引用答案的来源。
一次调用即可搜索:SearchDocuments 接受数据存储和文本查询作为参数。您无需传递集合名称、向量字段、任务类型或输出字段,且混合搜索(语义 + 全文)会自动为文档运行。
搜索视频中所说的内容:开启音频嵌入后,当说话者提到某个主题时,即使画面显示的是其他内容,查询也能匹配到该时刻。无需转录文本或字幕。
基线:通常文档搜索所需的工作量
Agent Retrieval 集合已经为您的自定义数据对象提供语义、文本和混合搜索功能。但是,您需要自行生成这些数据对象,并且为了查询它们,您需要了解它们的存储方式。以下是让数据存储代为处理工作后发生的变化:
底层集合仍然是常规的 Agent Retrieval 集合,因此您可以在需要完全控制权时直接查询它。
步骤 1:创建数据存储
数据存储保存您的文件以及控制如何解析和分段文件的配置。数据存储和 SearchDocuments API 目前通过 REST 在 v1beta 版本提供服务,因此示例使用了来自 google-auth 的授权会话:
import google.auth
from google.auth.transport.requests import AuthorizedSession
credentials, _ = google.auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
session = AuthorizedSession(credentials)
PARENT = "https://vectorsearch.googleapis.com/v1beta/projects/PROJECT_ID/locations/us-east4"
session.post(
f"{PARENT}/dataStores",
params={"data_store_id": "investor-reports"},
json={
"document_type": "UNSTRUCTURED",
"processing_config": {
"unstructured_processing_config": {
"segmentation_config": {"page_segmentation_config": {}},
"parsing_config": {"digital_parsing_config": {}},
}
},
"document_metadata_schema": {
"schema": {
"type": "object",
"properties": {
"doc_type": {"type": "string"},
"year": {"type": "integer"},
},
}
},
},
)
JSON
有两种分段模式可用。块分段(默认)将文本拆分为 100 到 500 个 token 的块,并与布局解析配合使用,后者还能检测表格和标题。页面分段则每页生成一个片段。对于分页文档(如 PDF),两种模式都会记录页码(startPage 和 endPage),以便您引用特定页面或按页码范围过滤:页面分段为每个片段返回单页,而块分段则返回该块所跨越的页码范围。
第 2 步:导入文件
通过 URI 模式(如 gs://my-bucket/reports/*.pdf )指向您的文件,或者在需要设置自定义文档 ID 并附加元数据时使用 JSONL 清单:
{"name": "projects/PROJECT_ID/locations/us-east4/dataStores/investor-reports/documents/2023-q4-earnings-release", "content": {"gcsUri": "gs://my-bucket/reports/2023q4-earnings-release.pdf"}, "metadata": {"value": {"doc_type": "earnings_release", "year": 2023}}}
JSON
session.post(
f"{PARENT}/dataStores/investor-reports:importDocuments",
json={
"gcs_source": {
"input_uris": ["gs://my-bucket/manifests/docs.jsonl"],
"source_format": "SOURCE_FORMAT_DOCUMENT_JSON",
},
"import_output_config": {"error_gcs_prefix": "gs://my-bucket/import-errors/run-1/"},
},
)
JSON
导入操作作为长期运行的操作执行。重新导入相同的文件会更新现有文档,而不是重复创建;内容未更改的文件将被跳过。
第 3 步:通过一次调用进行搜索
SearchDocuments 仅需提供数据存储和文本查询即可:
response = session.post(
f"{PARENT}/dataStores/investor-reports/documents:search",
json={
"text_query": {"text": "Google Cloud 收入增长了多少?"},
"top_k": 5,
},
).json()
JSON
每个结果都是文档的一个片段,包含文本、页码和源文件:
{
"document": {
"name": ".../dataStores/investor-reports/documents/2022-annual-report",
"content": {"gcsUri": "gs://.../2022_alphabet_annual_report.pdf"}
},
"unstructuredDetails": {
"contentSnippet": "... Google Cloud 收入从 2021 年到 2022 年增加了 71 亿美元 ...",
"pageRange": {"startPage": "68", "endPage": "68"}
}
}
JSON
实际工作原理
混合检索:SearchDocuments 在底层 Collection 上运行语义搜索和全文搜索,并融合两个结果列表,因此无论是 paraphrased(改写)的问题还是精确术语都能匹配。
片段级结果:结果是页面或块,而不是整个文件。多个结果可能来自同一文档,每个结果都有其各自的页码范围。
可选重排序:启用重排序后,SearchDocuments 会检索比 top_k 更多的候选项,并使用 Ranking API 对其进行重新排序,该 API 使用与 Agent Retrieval 的 VertexRanker 相同的 semantic-ranker-fast@latest 模型。
通过过滤器缩小结果范围
传递 filter 参数以仅搜索匹配的片段,使用您在结果中读取回的相同路径:
您还可以传递 document_ids 以仅在特定文件内进行搜索,并使用 output_fields.metadata 将每个文档的元数据与其结果一起返回。在我们的测试中,使用 page-1 过滤器搜索“CEO 对 AI 说了什么?”时,返回了来自五个不同财报发布 headlines 页面的 CEO 引用内容。
通过一个开关实现更好的排序
"ranking_spec": {"reranking_spec": {"enabled": True}}
JSON
对于“Alphabet 有多少名员工?”这一问题,普通的混合搜索在前五个结果中返回了两张资产负债表页面,这些页面根本未提及员工人数。开启重排序后,每个顶级结果都报告了员工人数:年报中的“Alphabet 拥有 190,234 名员工”以及季度补充表格中的“员工人数”行。
在视频中搜索
视频的处理方式相同:使用 document_type: VIDEO 创建数据存储,导入文件并调用 SearchDocuments。该服务会对每个视频进行转码,将其分割为固定窗口,并对每个窗口进行嵌入:
"document_type": "VIDEO",
"processing_config": {
"video_processing_config": {
"segmentation_config": {"fixed_window_config": {"segment_duration": "20s"}},
"embedding_config": {"audio_mode": "ENABLED"},
}
},
JSON
每个结果都带有其匹配的时间点:
"videoDetails": {"startOffset": "60s", "endOffset": "80s"}
JSON
我们导入了五个 Google 示例视频(总共约 19 分钟),并使用场景描述对它们进行搜索。“机器分拣黄瓜”这一搜索返回了机器学习视频中 03:20-03:40 的片段,其中展示了农场的分拣机对黄瓜进行分级,没有任何标签或字幕。搜索结果在 0.3 到 0.5 秒内返回。
抱歉,您的浏览器不支持此视频的回放
使用音频模式搜索语音内容
默认情况下(audio_mode: DISABLED),仅嵌入帧,因此查询匹配的是显示的内容。启用 ENABLED 后,第一个音轨将与帧一起嵌入。我们将相同的视频导入到两个数据存储中,并询问两者关于主题演讲中的陈述,当时画面显示的是演讲者:
只有启用了音频的数据存储找到了正确的时刻。
生产环境注意事项
为查询选择分段时长:短窗口(10 到 20 秒)可提供特定时刻的精确时间戳;长窗口(长达 80 秒)可为主题查询提供每个分段的更多上下文。默认值为 30 秒。
规划导入时间:视频导入会对每个分段进行转码和嵌入。将我们的五个视频导入两个数据存储耗时 20 到 45 分钟。每个数据存储一次只运行一个导入;不同的数据存储可以并行导入。就成本规划而言,在公共预览期间,托管摄入本身不会产生单独的费用(将在 GA 阶段开始计费),而底层 Collection 将根据标准的 Agent Retrieval 定价进行计费。
清理底层 Collection:使用 force=true 和 backing_collection_deleted=true 删除数据存储,否则其 Collection 将遗留下来。删除操作在后台运行,在我们的测试中耗时约 20 分钟。
重排序仅适用于文档:reranking_spec 不支持 VIDEO 数据存储。
架构摘要:选择正确的设置
经验法则:如果您的数据是文件,让数据存储摄入它们并使用 SearchDocuments 进行搜索。仅在您需要控制数据存储无法提供的功能时,才降级到 Collection。
结论
托管摄入并未改变良好检索所需的内容:良好的分段内容、优质的嵌入以及正确的过滤器。发生变化的是构建者。您无需维护解析器、分块器、嵌入作业和模式,只需将数据存储指向一个存储桶,即可获得准备好引用的分段。
对于智能体而言,这意味着通过一次 API 调用返回每个答案来源的检索工具,无论是 PDF 中的一页还是视频中的某一时刻。
亲自试一试:文档笔记本会摄取 18 份 Alphabet 投资者 PDF,并逐步演示过滤和重排序过程;视频笔记本则使用内联播放器搜索五个示例视频,并比较音频模式。
要求与后续步骤
区域:在公共预览期间,仅限 us-east4 或 europe-west4
API:通过 REST 调用 v1beta 版本的 Data store 和 SearchDocuments API(计划支持 Python SDK)
权限:向 Agent Retrieval 服务代理授予 roles/vectorsearch.serviceAgent 角色,以便其能够读取您的文件
参考资料
A guide to the new managed ingestion and SearchDocuments features in Agent Retrieval , for searching PDFs, Office files, and videos without writing an ingestion pipeline.
Before an agent can answer a question about your PDFs, someone has to build the pipeline: parse every file, split it into chunks, embed each chunk, write the chunks to a vector database, and then learn that database's schema to query it. For video it gets harder: transcode the files, cut them into clips, embed the frames, and keep track of which second of which video each clip came from.
Before: every step of the pipeline is custom code you write and maintain, separately for documents and for videos.
Most of that code has nothing to do with your application. Two features recently added to Agent Retrieval (formerly Vector Search 2.0), now in Public Preview, take that work off your hands. Managed ingestion builds the pipeline for you: point a data store at files in Cloud Storage , and the service parses, segments, and embeds them with Gemini Embedding 2 . SearchDocuments, the second new feature, then searches the data store with one API call and returns the matching passages with their page numbers or timestamps. In our tests, 18 Alphabet investor PDFs went from a public Cloud Storage bucket to searchable, page cited results in about 9 minutes, and 19 minutes of video became searchable by both visuals and spoken audio in 0.3 to 0.5 seconds per query, with no parsing, chunking, transcription, or embedding code.
This guide covers how to create a data store, import documents and videos, and search them with filters, reranking, and audio-aware video search.
What Managed Ingestion and SearchDocuments Enable
After: create separate data stores for documents (UNSTRUCTURED) and videos (VIDEO), point each at Cloud Storage, and search each with one SearchDocuments call that returns cited results.
Pairing managed ingestion with SearchDocuments gives you several immediate benefits:
No Ingestion Pipeline: Import PDF, DOCX, PPTX, XLSX, and TXT files, or MP4, MOV, WebM, MKV, and other video formats, straight from Cloud Storage. Parsing, segmentation, embedding, and the vector Collection and its schema are handled for you.
Answers With Citations: Every result carries its source file URI and a page range for documents, or a start and end time for videos, so your agent can cite exactly where an answer came from.
One Call to Search: SearchDocuments takes a data store and a text query. You don't pass a Collection name, a vector field, a task type, or output fields, and hybrid search (semantic + full-text) runs automatically for documents.
Search What Was Said in Videos: Turn on audio embedding and a query matches the moment a speaker mentions a topic, even when the picture shows something else. No transcript or captions required.
The Baseline: What Document Search Usually Takes
Agent Retrieval Collections already give you semantic, text, and hybrid search over your own data objects. But you have to produce those data objects yourself, and to query them you need to know how they are stored. Here is what changes when you let a data store do the work:
The backing Collection is still a regular Agent Retrieval Collection, so you can query it directly whenever you need full control.
Step 1: Create a Data Store
A data store holds your files and the configuration that controls how they are parsed and segmented. The data store and SearchDocuments APIs are currently served over REST at v1beta, so the examples use an authorized session from google-auth :
import google.auth
from google.auth.transport.requests import AuthorizedSession
credentials, _ = google.auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
session = AuthorizedSession(credentials)
PARENT = "https://vectorsearch.googleapis.com/v1beta/projects/PROJECT_ID/locations/us-east4"
session.post(
f"{PARENT}/dataStores",
params={"data_store_id": "investor-reports"},
json={
"document_type": "UNSTRUCTURED",
"processing_config": {
"unstructured_processing_config": {
"segmentation_config": {"page_segmentation_config": {}},
"parsing_config": {"digital_parsing_config": {}},
}
},
"document_metadata_schema": {
"schema": {
"type": "object",
"properties": {
"doc_type": {"type": "string"},
"year": {"type": "integer"},
},
}
},
},
)
JSON
Two segmentation modes are available. Chunk segmentation (the default) splits text into chunks of 100 to 500 tokens and works with layout parsing, which also detects tables and headings. Page segmentation produces one segment per page. For paginated documents such as PDFs, both modes record page numbers (startPage and endPage) so you can cite pages or filter by page range: page segmentation returns a single page per segment, while chunk segmentation returns the page range each chunk spans.
Step 2: Import Your Files
Point an import at your files with URI patterns such as gs://my-bucket/reports/*.pdf , or with a JSONL manifest when you want to set your own document IDs and attach metadata:
{"name": "projects/PROJECT_ID/locations/us-east4/dataStores/investor-reports/documents/2023-q4-earnings-release", "content": {"gcsUri": "gs://my-bucket/reports/2023q4-earnings-release.pdf"}, "metadata": {"value": {"doc_type": "earnings_release", "year": 2023}}}
JSON
session.post(
f"{PARENT}/dataStores/investor-reports:importDocuments",
json={
"gcs_source": {
"input_uris": ["gs://my-bucket/manifests/docs.jsonl"],
"source_format": "SOURCE_FORMAT_DOCUMENT_JSON",
},
"import_output_config": {"error_gcs_prefix": "gs://my-bucket/import-errors/run-1/"},
},
)
JSON
The import runs as a long-running operation. Re-importing the same files updates existing documents instead of duplicating them, and files whose content didn't change are skipped.
Step 3: Search With One Call
SearchDocuments needs only the data store and a text query:
response = session.post(
f"{PARENT}/dataStores/investor-reports/documents:search",
json={
"text_query": {"text": "How much did Google Cloud revenue grow?"},
"top_k": 5,
},
).json()
JSON
Each result is a segment of a document, with the text, the page, and the source file:
{
"document": {
"name": ".../dataStores/investor-reports/documents/2022-annual-report",
"content": {"gcsUri": "gs://.../2022_alphabet_annual_report.pdf"}
},
"unstructuredDetails": {
"contentSnippet": "... Google Cloud revenues increased $7.1 billion from 2021 to 2022 ...",
"pageRange": {"startPage": "68", "endPage": "68"}
}
}
JSON
How It Works in Practice
Hybrid Retrieval: SearchDocuments runs a semantic search and a full-text search over the backing Collection and fuses the two result lists, so both paraphrased questions and exact terms match.
Segment-Level Results: Results are pages or chunks, not whole files. Several results can come from the same document, each with its own page range.
Optional Reranking: With reranking on, SearchDocuments retrieves more candidates than top_k and reorders them with the Ranking API , using the same semantic-ranker-fast@latest model as Agent Retrieval's VertexRanker .
Narrowing Results With Filters
Pass filter to search only the segments that match, using the same paths you read back in results:
You can also pass document_ids to search only inside specific files, and output_fields.metadata to return each document's metadata with its results. In our test, searching "What did the CEO say about AI?" with the page-1 filter returned the CEO quotes from the headline page of five different earnings releases.
Better Ranking With One Toggle
"ranking_spec": {"reranking_spec": {"enabled": True}}
JSON
For "How many employees does Alphabet have?", plain hybrid search returned two balance sheet pages among the top five, which don't mention employees at all. With reranking on, every top result reported the headcount: the annual report's "Alphabet had 190,234 employees" and the "Number of employees" row of the quarterly supplemental tables.
Searching Inside Videos
Video works the same way: create a data store with document_type: VIDEO , import the files, and call SearchDocuments. The service transcodes each video, splits it into fixed windows, and embeds each window:
"document_type": "VIDEO",
"processing_config": {
"video_processing_config": {
"segmentation_config": {"fixed_window_config": {"segment_duration": "20s"}},
"embedding_config": {"audio_mode": "ENABLED"},
}
},
JSON
Each result carries the moment it matched:
"videoDetails": {"startOffset": "60s", "endOffset": "80s"}
JSON
We imported five Google sample videos (about 19 minutes in total) and searched them with scene descriptions. "Cucumbers being sorted by a machine" returned 03:20-03:40 of the machine learning video, where a farm's sorting machine grades cucumbers, without any tags or captions. Searches returned in 0.3 to 0.5 seconds.
Sorry, your browser doesn't support playback for this video
Search What Was Said With Audio Mode
By default ( audio_mode: DISABLED ), only the frames are embedded, so a query matches what is shown. With ENABLED , the first audio track is embedded together with the frames. We imported the same videos into two data stores and asked both about statements from a keynote, spoken while the picture shows the speaker:
Only the audio-enabled data store found the right moments.
Production Considerations
Choose the Segment Duration for Your Queries: Short windows (10 to 20 seconds) give precise timestamps for specific moments; long windows (up to 80 seconds) give each segment more context for thematic queries. The default is 30 seconds.
Plan for Import Time: Video imports transcode and embed every segment. Importing our five videos into two data stores took 20 to 45 minutes. Run one import at a time per data store; different data stores import in parallel. For cost planning, managed ingestion itself incurs no separate charge during Public Preview (billing will start at GA), while the backing Collection is billed under standard Agent Retrieval pricing .
Clean Up the Backing Collection: Delete a data store with force=true and backing_collection_deleted=true , or its Collection is left behind. Deletion runs in the background and took about 20 minutes in our tests.
Reranking Is for Documents: reranking_spec is not supported on VIDEO data stores.
Architecture Summary: Choosing the Right Setup
The rule of thumb: If your data is files, let a data store ingest them and search with SearchDocuments. Drop down to the Collection only when you need control the data store doesn't give you.
Conclusion
Managed ingestion doesn't change what good retrieval needs: well-segmented content, good embeddings, and the right filters. What changes is who builds it. Instead of maintaining parsers, chunkers, embedding jobs, and a schema, you point a data store at a bucket and get back segments that are ready to cite.
For agents, that means a retrieval tool that returns where each answer came from, a page in a PDF or a moment in a video, with one API call.
Try it yourself: the document notebook ingests 18 Alphabet investor PDFs and walks through filters and reranking, and the video notebook searches five sample videos with an inline player and compares audio modes.
Requirements & Next Steps
Regions: During Public Preview, only us-east4 or europe-west4
API: Data store and SearchDocuments APIs at v1beta, called over REST (Python SDK support is planned)
Permissions: Grant roles/vectorsearch.serviceAgent to the Agent Retrieval service agent so it can read your files
References
| 刊期 | 得分 | 排名 | 结果 |
|---|---|---|---|
| 2026-12-03 | 8.4 | 45 | 入选 |
| 2026-11-25 | 8.4 | 33 | 入选 |