12-04 更新 实时
首页/ 模型选型/ 正文

Gemini API 推出文件切片控制功能

模型选型 来源:Google Blog 2026-11-24 00:12 1 阅读 机器翻译
Gemini API 推出文件切片控制功能

查看全部:产品与平台

查看全部:创新与 AI

查看全部:产品与平台

在 Gemini API 中引入文件切片控制

在 Gemini API 中引入文件切片控制

Gemini API 现在具备原生文件切片控制功能,允许开发者指定目标页面、工作表范围和媒体片段,供模型在服务器端加载。这一功能可降低大文件的 Token 成本。

Google DeepMind 高级产品经理

Google DeepMind 首席工程师

你的浏览器不支持音频元素。

今天,我们在 Google AI Studio 和 Gemini 平台的 API 中推出新的文件切片控制功能,同时原生支持上传 Microsoft Office 和 OpenDocument 格式的文件。现在,你可以将 PDF、Office 文件(文档、幻灯片、电子表格)、音频和视频直接传给 Gemini API,并且只请求你需要的页面、电子表格单元格、媒体片段和图层。这样能让上下文聚焦于文件的相关部分,同时只为 Gemini 实际查看的部分计费 Token。

只查看你需要的内容

现实中的知识工作往往存在于信息密集的 PDF、幻灯片、多标签工作簿和长时间录音中。借助服务端切片,你不必再把文件压平成纯文本,也不必一开始就导入整个文件。

一次上传,跨轮次切片:使用 Files API 上传一次文件,即可在多轮对话和工具调用中复用其 URI。

让智能体自主掌控:该 API 允许智能体在函数响应中直接指定要查看文件的哪些部分,从而实现更快、更高效的多轮工作流

先低成本略读,再放大细看:先用提取的文本、低分辨率预览或转录文本快速略读,然后只把高分辨率 Token 花在真正重要的图表、密集版面和画面上。

按范围、图层、分辨率和帧率对文档、电子表格、视频等文件进行切片,以控制 Token 用量。

让你的 harness 支持多模态,且不在本地造成臃肿

当模型 API 只能接收整份文件时,智能体最终不得不在客户端 harness 内运行 LibreOffice、PDF 渲染器和 ffmpeg,来渲染和切分大文件。这会造成内存膨胀、用提取出的帧把本地磁盘塞得杂乱不堪,还迫使企业平台仅仅为了切分文件就要为每个用户维护沙箱。使用 Gemini API 时,只需在用户轮次中或直接在函数响应(function_result)内传入 Files API 的 URI,API 就会在服务端原生地按模型训练时所习惯看到的方式,对每个文件进行切分、渲染和 Token 化。

原生文件切分适用于所有 Gemini 4 模型,现有的文件大小和页数限制仍适用于上传的文件。你可以针对以下媒体类别自定义处理方式:

文档和幻灯片(PDF、Office 和 OpenDocument 格式):可选择页面范围(start_page、end_page),设置分辨率(low、medium 或 high),并选择内容层(page_text 或 page_image)。

电子表格(.xlsx、.xls、.ods):可选择工作表标签页(sheet_index)和单元格范围(visible_cells),设置分辨率(low、medium 或 high),并选择内容层(data、formulas 和 visuals)。

视频:可裁剪时间段(start_offset、end_offset),调整 fps 和分辨率(low、high),并选择内容层(transcript、frames 或 audio)。

音频:可轻松裁剪时间段(start_offset、end_offset)。

当 API 调用中省略处理选项时,文档和幻灯片默认使用保留版式的页面图像,电子表格则包含所有标签页的计算值、公式和工作表名称。

示例:先大致浏览,再深入细节

将 Word 文档上传一次到 Files API,以提取文本的方式低成本地浏览每一页,以定位到正确的章节,然后复用同一 URI 以高分辨率检查单个页面:

from google import genai client = genai.Client() doc = client.files.upload(file="quarterly_report.docx") # 1. 以提取文本的方式低成本地浏览整个文档。 skim = client.interactions.create( model="gemini-4-hydrogen", input=[ { "type": "document", "uri": doc.uri, "mime_type": doc.mime_type, "processing": { "type": "static", "page_options": {"content_layers": ["page_text"]}, }, }, { "type": "text", "text": "哪一页有收入桥接图?", }, ], ) print(skim.output_text) # 2. 以高分辨率深入查看目标页面(复用同一 URI)。 detail = client.interactions.create( model="gemini-4-neon", input=[ { "type": "document", "uri": doc.uri, "mime_type": doc.mime_type, "resolution": "high", "processing": { "type": "static", "page_options": { "start_page": 3, "end_page": 3, "content_layers": ["page_image"], }, }, }, { "type": "text", "text": "阅读第 3 页的收入桥接图和脚注。", }, ], ) print(detail.output_text)

各智能体框架的早期采用

网关和 SDK 合作伙伴在发布前验证了这些控制措施,直接在生产测试框架中削减了提示 Token 开销:

原生文件切片、内容层控制和扩展文件支持现已通过 Google AI Studio 和 Gemini 平台中的 API 提供。查看我们的文档以开始构建。

译文由英文原文机器翻译,术语按行业惯例统一,可在文末展开原文核对。

查看英文原文(Introducing file slicing controls in the Gemini API)

See all in Products & platforms

See all in Innovation & AI

See all in Products & platforms

Introducing file slicing controls in the Gemini API

Introducing file slicing controls in the Gemini API

The Gemini API now features native file slicing controls, allowing developers to specify targeted pages, sheet ranges, and media segments for the model to load server-side. This capability reduces token costs for large files.

Senior Product Manager, Google DeepMind

Principal Engineer, Google DeepMind

Introducing File Slicing Controls

Your browser does not support the audio element.

Today, we're launching new file slicing controls in the API across Google AI Studio and Gemini platform, alongside native file upload support for Microsoft Office and OpenDocument formats. You can now pass PDFs, Office files (docs, slides, spreadsheets), audio, and video directly to the Gemini API and request only the pages, spreadsheet cells, media segments, and layers you need. This keeps context focused on the relevant parts of a file while billing tokens only for the parts Gemini inspects.

Inspect only what you need

Real-world knowledge work lives in dense PDFs, slide decks, multi-tab workbooks, and long recordings. With server-side slicing, you do not have to flatten files to plain text or ingest entire files up front.

Upload once, slice across turns: Upload a file once with the Files API and reuse its URI across turns and tool calls.

Give your agent control: The API lets the agent specify what parts of a file to inspect directly inside a function response for faster and more efficient multi-turn workflows

Skim cheap, then zoom in: Skim first with extracted text, low-res previews, or transcripts, then spend high-resolution tokens only on the charts, dense layouts, and frames that matter.

Slice documents, spreadsheets, and videos and more by range, layer, resolution, and frame rate to control token usage.

Make your harness multimodal without local bloat

When model APIs only ingest whole files, agents end up running LibreOffice, PDF renderers, and ffmpeg inside the client harness to render and slice large files. This bloats memory, clutters local disk with extracted frames, and forces enterprise platforms to maintain per-user sandboxes just to slice files. With the Gemini API, pass a Files API URI on a user turn or directly inside a function response (function_result), and the API natively slices, renders, and tokenizes each file server-side the way the model was trained to see it.

Native file slicing works across all Gemini 4 models, and existing file size and page limits still apply to the uploaded file. You can customize processing across these media categories:

Documents and slides (PDF, Office and OpenDocument formats): Select a page range (start_page, end_page), set resolution (low, medium, or high), and choose content layers (page_text or page_image).

Spreadsheets (.xlsx, .xls, .ods): Select a worksheet tab (sheet_index) and cell range (visible_cells), set resolution (low, medium, or high), and select content layers (data, formulas, and visuals).

Video: Clip time intervals (start_offset, end_offset), adjust fps and resolution (low, high), and choose content layers (transcript, frames, or audio).

Audio: clip time intervals (start_offset, end_offset) with ease.

When processing options are omitted from API calls, documents and slides default to layout-preserving page images, and spreadsheets include evaluated values, formulas, and sheet names across all tabs.

Example: Skim at a high level, zoom in on details

Upload a Word document once to the Files API, skim every page cheaply as extracted text to locate the right section, then reuse the same URI to inspect a single page at high resolution:

from google import genai client = genai.Client() doc = client.files.upload(file="quarterly_report.docx") # 1. Skim the whole document cheaply as extracted text. skim = client.interactions.create( model="gemini-4-hydrogen", input=[ { "type": "document", "uri": doc.uri, "mime_type": doc.mime_type, "processing": { "type": "static", "page_options": {"content_layers": ["page_text"]}, }, }, { "type": "text", "text": "Which page has the revenue bridge chart?", }, ], ) print(skim.output_text) # 2. Zoom into the target page at high resolution (reusing the same URI). detail = client.interactions.create( model="gemini-4-neon", input=[ { "type": "document", "uri": doc.uri, "mime_type": doc.mime_type, "resolution": "high", "processing": { "type": "static", "page_options": { "start_page": 3, "end_page": 3, "content_layers": ["page_image"], }, }, }, { "type": "text", "text": "Read the revenue bridge chart and footnotes on page 3.", }, ], ) print(detail.output_text)

Early adoption across agent frameworks

Gateway and SDK partners validated these controls ahead of launch, cutting prompt token spend directly in production harnesses:

Native file slicing, content-layer controls, and expanded files support are available today via the API in Google AI Studio and the Gemini platform. Check out our docs to start building.

原文为英文,正文由自动抓取并保留原文。

本文由采集器自动同步

原文发布于 Google Blog(Introducing file slicing controls in the Gemini API),标题、摘要与正文由机器翻译,术语按行业惯例统一,未经人工逐句校订。

阅读原文 ↗