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

借助这一功能,开发者可以上传私有文档,系统将自动完成文本分块、索引构建以及检索处理。这使得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>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/1385">
<img src="https://img.php.cn/upload/ai_manual/000/000/000/175680265595886.png" alt="纳米搜索">
</a>
<div class="aritcle_card_info">
<a href="/ai/1385">纳米搜索</a>
<p>纳米搜索:360推出的新一代AI搜索引擎</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="纳米搜索">
<span>30</span>
</div>
</div>
<a href="/ai/1385" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="纳米搜索">
</a>
</div>
<h1>使用来源链接支持回答内容</h1><p>grounding = response.candidates[0].grounding_metadata
sources = {c.retrieved_context.title for c in grounding.grounding_chunks}
print('Sources:', *sources)据官方介绍,File Search 工具会自动管理文件存储、内容分块及嵌入向量生成。计费方式为每百万索引词元0.15美元,且仅在执行查询时生成嵌入,有效控制成本。目前支持多种常见文件格式,包括PDF、DOCX、TXT和JSON等。
源码地址:点击下载
以上就是谷歌推出 File Search Tool 文件搜索系统 ,集成至 Gemini API的详细内容,更多请关注php中文网其它相关文章!
谷歌浏览器Google Chrome是一款可让您更快速、轻松且安全地使用网络的浏览器。Google Chrome的设计超级简洁,使用起来得心应手。这里提供了谷歌浏览器纯净安装包,有需要的小伙伴快来保存下载体验吧!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号