Milvus
Zilliz
  • Home
  • Blog
  • Gemini 3 Pro + Milvus:利用高级推理和多模态功能打造更强大的 RAG

Gemini 3 Pro + Milvus:利用高级推理和多模态功能打造更强大的 RAG

  • Tutorial
November 20, 2025
Lumina Wang

谷歌的 Gemini 3 Pro 发布了一个罕见的版本,它真正改变了开发者的期望--不仅仅是炒作,而是实质性地扩展了自然语言界面的功能。它将 "描述你想要的应用 "变成了一个可执行的工作流程:动态工具路由、多步骤规划、API 协调和交互式用户体验生成,所有这些都无缝地拼接在一起。这是目前最接近让振动编码感觉可行的模型。

数据也证明了这一点。双子座 3 Pro 在几乎所有主要基准测试中都取得了优异成绩:

  • Humanity's Last Exam:37.5% 不使用工具,45.8% 使用工具--最接近的竞争对手为 26.5%。

  • MathArena Apex:23.4%,而大多数模型都未能突破 2%。

  • ScreenSpot-Pro:准确率为 72.7%,几乎是次席 36.2% 的两倍。

  • Vending-Bench 2:平均净值为 5478.16 美元,比第二名高出约1.4 倍

查看下表,了解更多基准结果。

深度推理、强大的工具使用能力和多模态流畅性的完美结合,让 Gemini 3 Pro 成为检索增强型生成(RAG)的不二之选。将它与专为十亿规模语义搜索而构建的高性能开源向量数据库Milvus 搭配使用,您就能获得一个响应可靠、扩展简洁、即使在繁重的工作负载下也能保持生产可靠性的检索层。

在这篇文章中,我们将介绍 Gemini 3 Pro 的新功能、它提升 RAG 工作流程的原因,以及如何使用 Milvus 作为检索骨干构建简洁、高效的 RAG 管道。

双子座 3 Pro 的主要升级

Gemini 3 Pro 引入了一系列重大升级,重塑了模型的推理、创建、任务执行以及与用户交互的方式。这些改进分为四大能力领域:

多模式理解和推理

Gemini 3 Pro 在重要的多模态基准方面创造了新纪录,包括视觉推理的 ARC-AGI-2、跨模态理解的 MMMU-Pro 以及视频理解和知识获取的 Video-MMMU。该模型还引入了 "深度思考"(Deep Think)这一扩展推理模式,实现了结构化、多步骤逻辑处理。这使得传统的思维链模型往往无法解决的复杂问题的准确性大大提高。

代码生成

该模型将代码生成提升到了一个新的水平。Gemini 3 Pro 可以生成交互式 SVG、完整的网络应用程序、三维场景,甚至功能性游戏(包括类似 Minecraft 的环境和基于浏览器的台球),所有这些都只需一个自然语言提示。前端开发尤其受益匪浅:该模型可以高保真地重新创建现有的用户界面设计,或将截图直接转化为生产就绪的代码,使用户界面的迭代工作大大加快。

人工智能代理和工具使用

在用户许可的情况下,Gemini 3 Pro 可以从用户的谷歌设备中获取数据,执行远景、多步骤任务,如计划行程或预订租车。Gemini 3 Pro 在Vending-Bench 2 上的出色表现就体现了这种代理能力,Vending-Bench 2 是一项专门用于对远程工具使用进行压力测试的基准测试。该模型还支持专业级 Agents 工作流程,包括执行终端命令和通过定义明确的 API 与外部工具交互。

生成式用户界面

Gemini 3 Pro摒弃了传统的一问一答模型,引入了生成式用户界面(Generative UI),该模型可以动态构建整个交互体验。它不再返回静态文本,而是根据用户指令直接生成完全定制的界面,例如,一个丰富的、可调整的旅行计划器。这将 LLM 从被动的响应者转变为主动的界面生成者。

测试双子座 3 Pro

除了基准测试结果,我们还进行了一系列实际操作测试,以了解 Gemini 3 Pro 在实际工作流程中的表现。测试结果凸显了 Gemini 3 Pro 的多模态推理、生成能力和长远规划如何为开发人员带来实际价值。

多模态理解

Gemini 3 Pro 在文本、图像、视频和代码方面的多功能性令人印象深刻。在测试中,我们直接从 YouTube 上传了一段 Zilliz 视频。该模型处理整个片段(包括旁白、转场和屏幕文本)的时间大约为40 秒,这对于长篇多模态内容来说是异常快速的。

谷歌的内部评估也显示了类似的表现:Gemini 3 Pro 处理了多种语言的手写食谱,转录并翻译了每一份食谱,并将其编译成一本可共享的家庭食谱。

零镜头任务

Gemini 3 Pro 可以生成完全交互式的网络用户界面,而无需事先提供示例或脚手架。当被要求创建一个精致的、复古未来主义的3D 飞船网页游戏时,该模型生成了一个完整的交互式场景:霓虹紫色网格、赛博朋克风格的飞船、发光粒子效果和流畅的相机控制--所有这一切都在一次零镜头响应中完成。

复杂的任务规划

与许多同类产品相比,该模型还表现出更强的远距离任务规划能力。在我们的收件箱整理测试中,Gemini 3 Pro 的表现就像一位人工智能行政助理:将杂乱无章的电子邮件归类到项目桶中,起草可执行的建议(回复、跟进、存档),并提交一份简洁、有条理的摘要。有了模型的计划布局,只需点击确认,整个收件箱就能被清理干净。

如何使用 Gemini 3 Pro 和 Milvus 建立 RAG 系统

Gemini 3 Pro 的升级推理、多模态理解和强大的工具使用功能使其成为高性能 RAG 系统的绝佳基础。

如果与Milvus(为大规模语义搜索而构建的高性能开源向量数据库)搭配使用,就能实现明确的职责分工:Gemini 3 Pro 负责解释、推理和生成,而 Milvus 则提供快速、可扩展的检索层,使响应与企业数据保持一致。这种搭配非常适合生产级应用,如内部知识库、文档助手、客户支持协理和特定领域的专家系统。

前提条件

在构建 RAG 管道之前,请确保已安装这些核心 Python 库或将其升级到最新版本:

  • pymilvus- Milvus 官方 Python SDK

  • google-generativeai- 双子座 3 Pro 客户端库

  • requests- 用于在需要时处理 HTTP 调用

  • tqdm- 用于数据集摄取过程中的进度条

! pip install --upgrade pymilvus google-generativeai requests tqdm

接下来,登录Google AI Studio获取 API 密钥。

import os
os.environ["GEMINI_API_KEY"] = "**********"

准备数据集

在本教程中,我们将使用 Milvus 2.4.x 文档中的常见问题部分作为 RAG 系统的私有知识库。

下载文档压缩包并解压到名为milvus_docs 的文件夹中。

! wget https://github.com/milvus-io/milvus-docs/releases/download/v2.4.6-preview/milvus_docs_2.4.x_en.zip
! unzip -q milvus_docs_2.4.x_en.zip -d milvus_docs

milvus_docs/en/faq 路径加载所有 Markdown 文件。对于每个文档,我们根据# 标题进行简单拆分,以大致区分每个 Markdown 文件中的主要部分。

from glob import glob
text_lines = []
for file_path in glob("milvus_docs/en/faq/*.md", recursive=True):
    with open(file_path, "r") as file:
        file_text = file.read()
    text_lines += file_text.split("# ")

LLM 和 Embeddings 模型设置

在本教程中,我们将使用gemini-3-pro-preview 作为 LLM,使用text-embedding-004 作为嵌入模型。

import google.generativeai as genai
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
gemini_model = genai.GenerativeModel("gemini-3-pro-preview")
response = gemini_model.generate_content("who are you")
print(response.text)

模型回复:我是 Gemini,一个由 Google 构建的大型语言模型。

您可以通过生成一个测试嵌入并打印其维度以及前几个值来进行快速检查:

test_embeddings = genai.embed_content(
    model="models/text-embedding-004", content=["This is a test1", "This is a test2"]
)["embedding"]
embedding_dim = len(test_embeddings[0])
print(embedding_dim)
print(test_embeddings[0][:10])

测试向量输出:

768

[0.013588584, -0.004361838, -0.08481652, -0.039724775, 0.04723794, -0.0051557426, 0.026071774, 0.045514572, -0.016867816, 0.039378334]

将数据载入 Milvus

创建 Collections

from pymilvus import MilvusClient
milvus_client = MilvusClient(uri="./milvus_demo.db")
collection_name = "my_rag_collection"

创建MilvusClient 时,您可以根据规模和环境选择三种配置选项:

  • 本地模式(Milvus Lite):将 URI 设置为本地文件路径(如./milvus.db )。这是最简单的入门方式--Milvus Lite会自动将所有数据存储到该文件中。

  • 自托管 Milvus(Docker 或 Kubernetes):对于较大的数据集或生产工作负载,可在 Docker 或 Kubernetes 上运行 Milvus。将 URI 设置为你的 Milvus 服务器端点,如http://localhost:19530

  • Zilliz Cloud(完全托管的 Milvus 服务):如果您更喜欢托管解决方案,请使用 Zilliz Cloud。将 URI 设置为公共端点,并提供 API 密钥作为身份验证令牌。

在创建新的 Collections 之前,首先要检查它是否已经存在。如果已经存在,请将其删除并重新创建,以确保设置无误。

if milvus_client.has_collection(collection_name):
    milvus_client.drop_collection(collection_name)

使用指定参数创建新 Collections。

如果没有提供 Schema,Milvus 会自动生成一个默认 ID 字段作为主键,并生成一个向量字段用于存储 Embeddings。它还提供了一个保留的 JSON 动态字段,用于捕捉模式中未定义的任何其他字段。

milvus_client.create_collection(
    collection_name=collection_name,
    dimension=embedding_dim,
    metric_type="COSINE",
    consistency_level="Strong",  # Strong consistency level
)

插入数据

遍历每个文本条目,生成其嵌入向量,并将数据插入 Milvus。 在本例中,我们包含了一个名为text 的额外字段。由于该字段未在 Schema 中预定义,因此 Milvus 会使用动态 JSON 字段自动存储该字段,无需额外设置。

from tqdm import tqdm
data = []
doc_embeddings = genai.embed_content(
    model="models/text-embedding-004", content=text_lines
)["embedding"]
for i, line in enumerate(tqdm(text_lines, desc="Creating embeddings")):
    data.append({"id": i, "vector": doc_embeddings[i], "text": line})
milvus_client.insert(collection_name=collection_name, data=data)

输出示例:

Creating embeddings: 100%|█████████████████████████| 72/72 [00:00<00:00, 431414.13it/s]
{'insert_count': 72, 'ids': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71], 'cost': 0}

构建 RAG 工作流程

检索相关数据

为了测试检索,我们提出一个有关 Milvus 的常见问题。

question = "How is data stored in milvus?"

在 Collections 中搜索查询,并返回前 3 个最相关的结果。

question_embedding = genai.embed_content(
    model="models/text-embedding-004", content=question
)["embedding"]
search_res = milvus_client.search(
    collection_name=collection_name,
    data=[question_embedding],
    limit=3,  # Return top 3 results
    search_params={"metric_type": "COSINE", "params": {}},  # Inner product distance
    output_fields=["text"],  # Return the text field
)
import json
retrieved_lines_with_distances = [
    (res["entity"]["text"], res["distance"]) for res in search_res[0]
]
print(json.dumps(retrieved_lines_with_distances, indent=4))

结果按相似度从最近到最不相似的顺序返回。

[
    [
        " Where does Milvus store data?\n\nMilvus deals with two types of data, inserted data and metadata. \n\nInserted data, including vector data, scalar data, and collection-specific schema, are stored in persistent storage as incremental log. Milvus supports multiple object storage backends, including [MinIO](
https://min.io/
), [AWS S3](
https://aws.amazon.com/s3/?nc1=h_ls
), [Google Cloud Storage](
https://cloud.google.com/storage?hl=en#object-storage-for-companies-of-all-sizes
) (GCS), [Azure Blob Storage](
https://azure.microsoft.com/en-us/products/storage/blobs
), [Alibaba Cloud OSS](
https://www.alibabacloud.com/product/object-storage-service
), and [Tencent Cloud Object Storage](
https://www.tencentcloud.com/products/cos
) (COS).\n\nMetadata are generated within Milvus. Each Milvus module has its own metadata that are stored in etcd.\n\n###",
        0.8048489093780518
    ],
    [
        "Does the query perform in memory? What are incremental data and historical data?\n\nYes. When a query request comes, Milvus searches both incremental data and historical data by loading them into memory. Incremental data are in the growing segments, which are buffered in memory before they reach the threshold to be persisted in storage engine, while historical data are from the sealed segments that are stored in the object storage. Incremental data and historical data together constitute the whole dataset to search.\n\n###",
        0.757495105266571
    ],
    [
        "What is the maximum dataset size Milvus can handle?\n\n  \nTheoretically, the maximum dataset size Milvus can handle is determined by the hardware it is run on, specifically system memory and storage:\n\n- Milvus loads all specified collections and partitions into memory before running queries. Therefore, memory size determines the maximum amount of data Milvus can query.\n- When new entities and and collection-related schema (currently only MinIO is supported for data persistence) are added to Milvus, system storage determines the maximum allowable size of inserted data.\n\n###",
        0.7453694343566895
    ]
]

使用 LLM 生成 RAG 响应

检索文档后,将其转换为字符串格式

context = "\n".join(
    [line_with_distance[0] for line_with_distance in retrieved_lines_with_distances]
)

为 LLM 提供一个系统提示和一个用户提示,这两个提示都是根据从 Milvus 获取的文档构建的。

SYSTEM_PROMPT = """
Human: You are an AI assistant. You are able to find answers to the questions from the contextual passage snippets provided.
"""
USER_PROMPT = f"""
Use the following pieces of information enclosed in <context> tags to provide an answer to the question enclosed in <question> tags.
<context>
{context}
</context>
<question>
{question}
</question>
"""

使用gemini-3-pro-preview 模型和这些提示生成最终回复。

gemini_model = genai.GenerativeModel(
    "gemini-3-pro-preview", system_instruction=SYSTEM_PROMPT
)
response = gemini_model.generate_content(USER_PROMPT)
print(response.text)

从输出结果可以看出,Gemini 3 Pro 根据检索到的信息生成了清晰、结构良好的答案。

Based on the provided documents, Milvus stores data in the following ways:
*   **Inserted Data:** Vector data, scalar data, and collection-specific schema are stored in persistent storage as an incremental log. Milvus supports multiple object storage backends for this purpose, including:
    *   MinIO
    *   AWS S3
    *   Google Cloud Storage (GCS)
    *   Azure Blob Storage
    *   Alibaba Cloud OSS
    *   Tencent Cloud Object Storage (COS)
*   **Metadata:** Metadata generated within Milvus modules is stored in **etcd**.
*   **Memory Buffering:** Incremental data (growing segments) are buffered in memory before being persisted, while historical data (sealed segments) resides in object storage but is loaded into memory for querying.

注意:Gemini 3 Pro 目前不适用于免费用户。点击此处了解更多详情。

您可以通过OpenRouter访问它:

from openai import OpenAI
client = OpenAI(
  base_url="https://openrouter.ai/api/v1",
  api_key="<OPENROUTER_API_KEY>",
)
response2 = client.chat.completions.create(
  model="google/gemini-3-pro-preview",
  messages=[
        {
            "role": "system",
            "content": SYSTEM_PROMPT
        },
        {
            "role": "user", 
            "content": USER_PROMPT
        }
    ],
  extra_body={"reasoning": {"enabled": True}}
)
response_message = response2.choices[0].message
print(response_message.content)

还有一件事:使用 Google Antigravity 进行 Vibe 编码

除了 Gemini 3 Pro,Google 还推出了Google Antigravity,这是一个可与编辑器、终端和浏览器自主交互的视频编码平台。与处理一次性指令的早期人工智能辅助工具不同,Antigravity 在面向任务的层面上进行操作--允许开发人员指定他们想要构建的内容,而系统则管理如何构建,端到端协调整个工作流程。

传统的人工智能编码工作流程通常会生成孤立的片段,开发人员仍需对其进行审查、集成、调试和手动运行。反重力技术改变了这一动态。您只需描述一项任务,例如"创建一个简单的宠物互动游戏",系统就会分解请求、生成代码、执行终端命令、打开浏览器测试结果,并反复运行,直到成功为止。它将人工智能从一个被动的自动完成引擎提升为一个主动的工程合作伙伴--它可以学习你的偏好,并随着时间的推移适应你的个人开发风格。

展望未来,Agent 直接与数据库协调的想法并不遥远。通过MCP进行工具调用,人工智能最终可以从Milvus数据库中读取数据,组建知识库,甚至自主维护自己的检索管道。在许多方面,这种转变甚至比模型升级本身更有意义:一旦人工智能能够获取产品层面的描述,并将其转换为一系列可执行的任务,人类的努力就会自然而然地转向定义目标、约束条件以及 "正确性 "是什么样子--真正推动产品开发的高层次思维。

准备好构建了吗?

如果您已经准备好尝试,请按照我们的教程逐步操作,今天就使用Gemini 3 Pro + Milvus构建一个 RAG 系统。

有问题或想深入了解任何功能?加入我们的 Discord 频道或在 GitHub 上提交问题。您还可以通过 Milvus Office Hours 预订 20 分钟的一对一课程,以获得见解、指导和问题解答。

    Try Managed Milvus for Free

    Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

    Get Started

    Like the article? Spread the word

    扩展阅读