Milvus
Zilliz
  • Home
  • Blog
  • Gemini 3 Pro + Milvus:以先進的推理能力和多模態功能打造更強大的 RAG

Gemini 3 Pro + Milvus:以先進的推理能力和多模態功能打造更強大的 RAG

  • Tutorial
November 20, 2025
Lumina Wang

Google 的 Gemini 3 Pro 發表了罕見的版本,真正改變了開發人員的期望 - 不只是炒作,而是實質擴展自然語言介面的功能。它將「描述您想要的應用程式」轉化為可執行的工作流程:動態工具路由、多步驟規劃、API 協調,以及互動式 UX 產生,全都無縫地拼接在一起。這是最接近讓 vibe coding 感覺生產可行的模式。

而數字也證明了這一說法。Gemini 3 Pro 在幾乎所有主要基準上都有傑出的表現:

  • 人類最後一次考試:37.5% 不使用工具,45.8% 使用工具 - 最接近的競爭對手為 26.5%。

  • MathArena Apex:23.4%,而大多數機型都無法突破 2%。

  • ScreenSpot-Pro:72.7% 的準確度,幾乎是次佳的 36.2% 的兩倍。

  • Vending-Bench 2:平均淨值為$5,478.16,比第二名高出約1.4 倍

查看下表,瞭解更多基準結果。

深度推理、強大的工具運用能力,以及多模式流暢性的結合,讓 Gemini 3 Pro 成為檢索增強世代 (RAG) 的天作之合。再搭配專為十億規模語意搜尋所打造的高效能開放原始碼向量資料庫Milvus,您就能得到一個能依據回應、簡單擴充、即使在繁重工作負載下仍能保持生產可靠性的檢索層。

在這篇文章中,我們將介紹 Gemini 3 Pro 的新功能、提升 RAG 工作流程的原因,以及如何使用 Milvus 作為您的檢索骨幹,建立乾淨、有效率的 RAG 管線。

Gemini 3 Pro 的主要升級

Gemini 3 Pro 引入了一系列重大升級,重塑了模型推理、創建、執行任務以及與用戶互動的方式。這些改進分為四大能力領域:

多模式理解與推理

Gemini 3 Pro 在重要的多模態基準上創下新記錄,包括視覺推理的 ARC-AGI-2、跨模態理解的 MMMU-Pro,以及視訊理解和知識獲取的 Video-MMMU。該模型還引入了深度思考 (Deep Think),這是一種擴展推理模式,能夠進行結構化、多步驟邏輯處理。這可大幅提高處理複雜問題的準確度,而傳統的思考鏈模型往往會在這些問題上失敗。

代碼產生

該模型將代碼生成提升到了一個新的層次。Gemini 3 Pro 可以生成互動 SVG、完整的 Web 應用程式、3D 場景,甚至是功能性遊戲 - 包括類似 Minecraft 的環境和基於瀏覽器的桌球 - 所有這些都只需要單一的自然語言提示。前端開發的好處尤其多:模型可以高保真地重新製作現有的 UI 設計,或是直接將螢幕截圖轉換成可供生產的程式碼,讓 UI 的迭代工作大幅提昇速度。

AI 代理與工具使用

在使用者允許的情況下,Gemini 3 Pro 可以從使用者的 Google 裝置存取資料,以執行長距離、多步驟的工作,例如規劃行程或預約租車。這種代理能力反映在其在Vending-Bench 2 上的強勁表現,Vending-Bench 2 是專為長距離工具使用壓力測試而設計的基準。此模型也支援專業級的代理工作流程,包括執行終端指令,以及透過定義良好的 API 與外部工具互動。

創造性的使用者介面

Gemini 3 Pro 擺脫了傳統的一問一答模式,引入了生成式使用者介面 (Generative UI),模型可以動態建立整個互動體驗。Gemini 3 Pro 不會回傳靜態文字,而是可以直接回應使用者的指示,產生完全客製化的介面,例如豐富、可調整的旅遊計畫。這讓 LLM 從被動的回應者轉變為主動的介面產生者。

測試 Gemini 3 Pro

除了基準測試結果之外,我們還進行了一系列實作測試,以瞭解 Gemini 3 Pro 在實際工作流程中的表現。測試結果突顯了其多模式推理、產生能力和長遠規劃如何為開發人員轉化為實際價值。

多模式理解

Gemini 3 Pro 在文字、圖像、視訊和程式碼方面的多樣性令人印象深刻。在測試中,我們直接從 YouTube 上傳了一段 Zilliz 視訊。模型處理整個片段 - 包括旁白、轉場和螢幕文字 - 大約只花了40 秒,對於長格式的多模式內容來說,這是異乎尋常的快速。

Google 的內部評估也顯示出類似的表現:Gemini 3 Pro 能處理多國語言的手寫食譜,轉錄並翻譯每一份食譜,並將它們編輯成可分享的家庭食譜集。

零拍攝任務

Gemini 3 Pro 可以生成完全互動的 Web UI,而無需事先提供範例或支架。當被要求製作一個精緻、復古、前衛的3D 太空船網頁遊戲時,模型產生了一個完整的互動式場景:霓虹紫色的網格、賽博朋克風格的船艦、發光的粒子效果,以及流暢的攝影機控制 - 所有這些都在單次零拍攝的回應中完成。

複雜的任務規劃

與許多同級產品相比,該模型還展現了更強大的長遠任務規劃能力。在我們的收件匣整理測試中,Gemini 3 Pro 的表現很像 AI 行政助理:將雜亂的電子郵件歸類為專案桶、草擬可執行的建議 (回覆、跟進、歸檔),並提出乾淨、有條理的摘要。有了模型的計畫,只要按一下確認,就能清除整個收件匣。

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

Gemini 3 Pro 的升級推理、多模態理解以及強大的工具使用能力,使其成為高效能 RAG 系統的絕佳基礎。

搭配Milvus(專為大規模語義搜尋而建的高效能開放原始碼向量資料庫)使用時,您將獲得明確的職責分工:Gemini 3 Pro 負責詮釋、推理和產生,而 Milvus 則提供快速、可擴充的檢索層,讓回應以您的企業資料為基礎。這種搭配非常適合生產級應用程式,例如內部知識庫、文件助理、客戶支援協同駕駛員,以及特定領域的專家系統。

先決條件

在建立您的 RAG 管道之前,請確認已安裝這些核心 Python 函式庫或升級至最新版本:

  • pymilvus- 官方 Milvus Python SDK

  • google-generativeai- Gemini 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 文件中的常見問題(FAQ)部分作為 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 與嵌入模型設定

在本教程中,我們將以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 建立的大型語言模型。

您可以透過產生測試 embedding 並列印其維度以及前幾個值來進行快速檢查:

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

建立資料集

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 金鑰作為驗證標記。

在建立新的集合之前,請先檢查它是否已經存在。如果已經存在,請將其刪除並重 新建立,以確保設定乾淨。

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

使用指定的參數建立新的集合。

如果沒有提供模式,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 的額外欄位。由於它沒有在模式中預先定義,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?"

在資料集中搜尋該查詢,並傳回前 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,這是一個可自主與編輯器、終端和瀏覽器互動的視頻編碼平台。與早期處理一次性指令的 AI 輔助工具不同,Antigravity 是在以任務為導向的層級上運作 - 開發人員可以指定他們想要建立什麼,而系統可以管理如何建立,並協調完整的端對端工作流程。

傳統的 AI 編碼工作流程通常會產生孤立的片段,開發人員仍需檢閱、整合、除錯並手動執行。Antigravity 改變了這種動態。您只需描述任務,例如「建立一個簡單的寵物互動遊戲」,系統就會分解請求、產生程式碼、執行終端指令、開啟瀏覽器測試結果,並反覆執行,直到成功為止。它將人工智能從一個被動的自動完成引擎提升為一個主動的工程夥伴 - 它可以學習您的喜好,並隨著時間的推移適應您的個人開發風格。

展望未來,代理程式直接與資料庫協調的想法並不遙遠。透過 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

    繼續閱讀