登录
首页 >  科技周边 >  业界新闻

谷歌FileSearchTool上线,集成GeminiAPI功能

时间:2025-11-30 15:06:36 348浏览 收藏

在IT行业这个发展更新速度很快的行业,只有不停止的学习,才不会被行业所淘汰。如果你是科技周边学习者,那么本文《谷歌推出 File Search Tool,集成 Gemini API》就很适合你!本篇内容主要包括##content_title##,希望对大家的知识积累有所帮助,助力实战开发!

谷歌近日宣布,其Gemini API正式推出File Search Tool(文件搜索系统)。该工具是一项完全托管的检索增强生成(RAG)服务,旨在为开发者提供一种简单、集成且可扩展的方法,利用自有数据对Gemini模型进行“锚定”,从而提升生成内容的相关性与准确性。

谷歌推出 File Search Tool 文件搜索系统 ,集成至 Gemini API

借助这一功能,开发者可以上传私有文档,系统将自动完成文本分块、索引构建以及检索处理。这使得Gemini模型在响应查询时,能够基于用户提供的文件内容生成更具上下文感知能力的回答。

使用示例代码如下:

from google import genai
from google.genai import types
<p>client = genai.Client()
store = client.file_search_stores.create()</p><p>upload_op = client.file_search_stores.upload_to_file_search_store(
file_search_store_name=store.name,
file='path/to/your/document.pdf'
)</p><p>while not upload_op.done:
time.sleep(5)
upload_ops = client.operations.get(upload_op)</p><h1>在生成请求中将文件搜索存储作为工具使用</h1><p>response = client.models.generate_content(
model='gemini-2.5-flash',
contents='What does the research say about ...',
config=types.GenerateContentConfig(
tools=[types.Tool(
file_search=types.FileSearch(
file_search_store_names=[store.name]
)
)]
)
)</p><p>print(response.text)</p><h1>使用来源链接支持回答内容</h1><p>grounding = response.candidates[0].grounding_metadata
sources = {c.retrieved_context.title for c in grounding.grounding_chunks}
print('Sources:', *sources)</p>

据官方介绍,File Search 工具会自动管理文件存储、内容分块及嵌入向量生成。计费方式为每百万索引词元0.15美元,且仅在执行查询时生成嵌入,有效控制成本。目前支持多种常见文件格式,包括PDF、DOCX、TXT和JSON等。

源码地址:点击下载

今天带大家了解了的相关知识,希望对你有所帮助;关于科技周边的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

相关阅读
更多>
最新阅读
更多>
课程推荐
更多>