Milvus×最新版DeepSeek v3:對標Claude,本地數據五分鐘寫網站

圖片

圖片

前言

就在昨晚,DeepSeek v3推出了新版本V3-0324,再次一夜爆火。

雖然官方表示“這只是一次小升級”“API接口和使用方式不變”,但經過Zilliz的第一時間實測,我們發現無論是邏輯能力,還是編程能力,相較原本的v3,都有了極大提升,甚至可以說,這是目前市面上最頂級的開源非推理模型。

具體來說,改變有以下三點:

參數量上,V3-0324為6850億,較上一版本的6710億略有提升;

上下文窗口上,V3-0324升級到了 128k

能力上,V3-0324的代碼、數學、邏輯等能力有了較大提升。

整個V3的設計依然延用了V2提出的MLA(Multi-head Latent Attention)架構,既多頭潛在注意力機制,通過潛在向量(latent vector)對Key-Value(KV)緩存進行壓縮,從而減少推理時的內存占用和計算開銷。

此外DeepSeek V3將除前三層外的所有 FFN 層替換為 MoE 層,每個 MoE 層包含 1 個共享專家和 256 個路由專家。在路由專家中,每個 token 將激活 評分靠前的幾個專家,以平衡整體的計算量。

另外,圍繞準確率的提升,DeepSeek V3還使用了多token預測(MTP),通過多層級聯預測機制,打破了傳統模型只能一次多預測一個token的限制,讓每個 token同時預測多個未來token,進而提升模型性能和數據效率。

那么DeepSeek v3-0324該如何用?企業場景應該如何部署?如何將它與RAG結合?本篇文章,我們會對DeepSeek v3的亮點進行梳理,并對其RAG搭建流程與效果,做一個簡單的示例。

01

使用Milvus和DeepSeek搭建RAG

接下來,我們將展示如何使用Milvus和DeepSeek構建檢索增強生成(RAG)pipeline。

步驟一:準備

(1)依賴和環境

! pip install --upgrade "pymilvus[model]" openai requests tqdm

如果您使用的是Google Colab,要啟用剛剛安裝的依賴項,您可能需要重啟運行環境(單擊屏幕頂部的“Runtime”菜單,然后從下拉框中選擇“Restart session”)。

(2)準備數據

我們使用Milvus文檔2.4. x中的FAQ頁面作為RAG中的私有知識,這是搭建一個入門RAG pipeline的優質數據源。

首先,下載zip文件并將文檔解壓縮到文件夾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 globtext_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("# ")

(3)準備LLM和embedding模型

OpenRouter是一家提供統一API接口聚合多個主流AI模型(如DeepSeek、Claude等)的服務平臺,讓開發者通過單一接入點調用不同大語言模型。在OpenRouter上免費創建DeepSeek V3的API秘鑰就可以嘗鮮使用DeepSeek V3 0324。(其他平臺操作同理,目前僅OpenRouter上線了最新版V3)

from openai import OpenAIdeepseek_client = OpenAI(api_key="<OPENROUTER_API_KEY>",base_url="https://openrouter.ai/api/v1",
)

選擇一個embedding模型,使用milvus_model來做文本向量化。我們以DefaultEmbeddingFunction模型為例,它是一個預訓練的輕量級embedding模型。

from pymilvus import model as milvus_modelembedding_model = milvus_model.DefaultEmbeddingFunction()

生成測試向量,并輸出向量維度以及測試向量的前幾個元素。

test_embedding = embedding_model.encode_queries(["This is a test"])[0]
embedding_dim = len(test_embedding)
print(embedding_dim)
print(test_embedding[:10])
768
[-0.04836066  0.07163023 -0.01130064 -0.03789345 -0.03320649 -0.01318448-0.03041712 -0.02269499 -0.02317863 -0.00426028]

步驟二:將數據加載到Milvus

創建集合

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

對于MilvusClient需要說明:

  • 將uri設置為本地文件,例如./milvus. db,是最方便的方法,因為它會自動使用Milvus Lite將所有數據存儲在此文件中。

  • 如果你有大規模數據,你可以在docker或kubernetes上設置一個更高性能的Milvus服務器。在此設置中,請使用服務器uri,例如http://localhost:19530,作為你的uri。

  • 如果要使用Milvus的全托管云服務Zilliz Cloud,請調整uri和token,分別對應Zilliz Cloud中的Public Endpoint和Api密鑰。

檢查集合是否已經存在,如果存在則將其刪除。

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

使用指定的參數創建一個新集合。

如果我們不指定任何字段信息,Milvus將自動為主鍵創建一個默認的id字段,并創建一個向量字段來存儲向量數據。保留的JSON字段用于存儲未在schema里定義的標量數據。

milvus_client.create_collection(collection_name=collection_name,dimension=embedding_dim,metric_type="IP",  # Inner product distanceconsistency_level="Strong",  # Strong consistency level
)

插入數據

逐條取出文本數據,創建嵌入,然后將數據插入Milvus。

這里有一個新的字段“text”,它是集合schema中的非定義字段,會自動添加到保留的JSON動態字段中。

from tqdm import tqdmdata = []doc_embeddings = embedding_model.encode_documents(text_lines)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, 1222631.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?"
在集合中搜索問題并檢索語義top-3匹配項。
search_res = milvus_client.search(collection_name=collection_name,data=embedding_model.encode_queries([question]),  # Convert the question to an embedding vectorlimit=3,  # Return top 3 resultssearch_params={"metric_type": "IP", "params": {}},  # Inner product distanceoutput_fields=["text"],  # Return the text field
)

我們來看一下query的搜索結果

import jsonretrieved_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.6572665572166443],["How does Milvus flush data?\n\nMilvus returns success when inserted data are loaded to the message queue. However, the data are not yet flushed to the disk. Then Milvus' data node writes the data in the message queue to persistent storage as incremental logs. If `flush()` is called, the data node is forced to write all data in the message queue to persistent storage immediately.\n\n###",0.6312146186828613],["How does Milvus handle vector data types and precision?\n\nMilvus supports Binary, Float32, Float16, and BFloat16 vector types.\n\n- Binary vectors: Store binary data as sequences of 0s and 1s, used in image processing and information retrieval.\n- Float32 vectors: Default storage with a precision of about 7 decimal digits. Even Float64 values are stored with Float32 precision, leading to potential precision loss upon retrieval.\n- Float16 and BFloat16 vectors: Offer reduced precision and memory usage. Float16 is suitable for applications with limited bandwidth and storage, while BFloat16 balances range and efficiency, commonly used in deep learning to reduce computational requirements without significantly impacting accuracy.\n\n###",0.6115777492523193]
]

使用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>
"""

使用DeepSeek提供的deepseek/deepseek-chat-v3-0324模型根據提示生成響應。

response = deepseek_client.chat.completions.create(model="deepseek/deepseek-chat-v3-0324",messages=[{"role": "system", "content": SYSTEM_PROMPT},{"role": "user", "content": USER_PROMPT},],
)
print(response.choices[0].message.content)
Milvus stores data in two main categories: inserted data and metadata.1. **Inserted Data**:- This includes vector data, scalar data, and collection-specific schema.- The data is stored in persistent storage as incremental logs.- Milvus supports various object storage backends for this purpose, such as MinIO, AWS S3, Google Cloud Storage (GCS), Azure Blob Storage, Alibaba Cloud OSS, and Tencent Cloud Object Storage (COS).2. **Metadata**:- Metadata is generated internally by Milvus and is specific to each module.- This metadata is stored in etcd.For vector data, Milvus supports multiple types including Binary, Float32, Float16, and BFloat16, each with different precision and use cases. The data is initially loaded into a message queue upon insertion and is later written to persistent storage by the data node, either during regular operations or immediately if `flush()` is called.
至此,通過Milvus和DeepSeek構建了一個RAG pipeline的完整流程正式完成。

02

對比:原裝版DeepSeek-V3-0324 ?VS RAG版

在搭建好一個最基本的RAG之后,接下來,我們對原裝版DeepSeek-V3-0324 以及結合了Milvus+DeepSeek-V3-0324的RAG版本做一下效果對比。

對比問題可以選用"write HTML code to create a fancy website about Milvus"。

我們直接在官網的對話框關閉【深度思考】,然后直接提問,效果如下:

下面是集成了Milvus的RAG版本,將上文代碼中的question進行替換

question="write HTML code to create a fancy website about Milvus"

生成的網站如下:

通過對比我們可以看到,在整體審美風格比較接近的情況下,RAG版網站,無論是產品簡介,還是具體的亮點分析,都更加符合實際的Milvus特性。建立在本地文檔所提供的更豐富的語料語料基礎上,給出的整體網站內容也會更加豐富、專業,不空洞。

03

寫在最后

其實不只是代碼能力,在數學推理、長文本閱讀推理等方面,新版V3均有較大程度的提升,幾乎與Claude 3.7 Sonnet 媲美。

另外,我們通過實驗發現,相比前一段時間風很大的推理模型,作為非推理模型的新版V3,雖然不會在回答中給出詳細的推理過程,但其答案生成仍展現了一定的邏輯與思考能力。

與之形成對比,推理模型做RAG與Agent ,效果很好,但卻會對一些簡單的指令判斷,做一大堆分析與反復思考確認,不僅消耗過多token,回答速度還慢。

而新版V3,對于一些成本敏感的場景來說,或許帶來了問題的新解法。

更進一步,這也印證了諸如 OpenAI 的大模型廠商,后續不再區別推理和非推理模型背后的邏輯,模型服務應該自動根據需求判斷是否推理,以節省不必要的 token 開銷

作者介紹

圖片

王舒虹

Zilliz?Social Media Advocate

推薦閱讀

圖片圖片

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/899229.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/899229.shtml
英文地址,請注明出處:http://en.pswp.cn/news/899229.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

6.M-LAG專題

M-LAG 的作用及特點 能不能簡單的描述以下M-LAG的工作原理? 跨設備鏈路聚合&#xff0c;將兩臺物理設備在聚合層面虛擬成一臺設備來實現跨設備鏈路聚合&#xff0c;從而提供設備級冗余保護和流量負載分擔 M-LAG(跨設備鏈路聚合)是基于IEEEP802.1A協議的跨設備鏈路聚合技術。…

每日免費分享之精品wordpress主題系列~DAY16

主題介紹&#xff1a; 今日在網上尋找wordpress主題的時候逛到了大叔的網站&#xff0c;趕腳這個主題蠻不錯的&#xff0c;于是百度一下&#xff0c;果然&#xff0c;這個主題很受歡迎。作為主題下載站追夢者也不甘落后&#xff0c;馬上就發布出來了&#xff0c;希望對你們有用…

LeeCode 383. 贖金信

給你兩個字符串&#xff1a;ransomNote 和 magazine &#xff0c;判斷 ransomNote 能不能由 magazine 里面的字符構成。 如果可以&#xff0c;返回 true &#xff1b;否則返回 false 。 magazine 中的每個字符只能在 ransomNote 中使用一次。 示例 1&#xff1a; 輸入&#…

目標檢測20年(一)

今天看的文獻是《Object Detection in 20 Years: A Survey》&#xff0c;非常經典的一篇目標檢測文獻&#xff0c;希望通過這篇文章學習到目標檢測的基礎方法并提供一些創新思想。 論文鏈接&#xff1a;1905.05055 目錄 一、摘要 1.1 原文 1.2 翻譯 二、介紹 三、目標檢測…

分割 / 合并大文件的簡單 python 代碼

使用方法 分割: python fs.py -n <分割后的文件個數> <要分割的文件> 合并: python fs.py -m <分割文件1> <分割文件2> ... 示例 PS C:\Users\Administrator\Desktop> python fs.py 使用方法: 分割: python fs.py -n <分割后的文件個數> &…

IDEA 快捷鍵ctrl+shift+f 無法全局搜索內容的問題及解決辦法

本篇文章主要講解IDEA、phpStrom、webStrom、pyCharm等jetbrains系列編輯器無法進行全局搜索內容問題的主要原因及解決辦法。 日期&#xff1a;2025年3月22日 作者&#xff1a;任聰聰 現象描述&#xff1a; 1.按下ctrlshiftf 輸入法轉為了繁體。 2.快捷鍵ctrlshiftr 可以全局檢…

樹狀數組【數據結構】

樹狀數組 簡介 1.應用 1.單點修改區間查詢 2.區間修改單點查詢(差分) 3.區間修改區間查詢(差分公式) 總而言之,就是動態維護前綴和。 2.樹狀結構圖 3.lowbit函數 我們知道&#xff0c;任何一個正整數都可以被表示成一個二進制數。如&#xff1a; ( 2 ) 10 ( 10 ) 2 (2)_{10…

pytorch+maskRcnn框架訓練自己的模型以及模型導出ONXX格式供C++部署推理

背景 maskrcnn用作實例分割時&#xff0c;可以較為精準的定位目標物體&#xff0c;相較于yolo只能定位物體的矩形框而言&#xff0c;優勢更大。雖然yolo的計算速度更快。 直接開始從0到1使用maskrCNN訓練自己的模型并并導出給C部署&#xff08;親測可用&#xff09; 數據標注…

PCL配置

1、下載 打開GitHub網站&#xff0c;搜索pcl&#xff0c;選擇第一個結果打開&#xff0c;按照下圖步驟操作 下載PCL預編譯安裝程序PCL-1.13.1-AllInOne-msvc2022-win64.exe 和要安裝的PCL組件&#xff08;例如pcl-1.13.1-pdb-msvc2022-win64.zip&#xff09; 2、安裝 雙擊 P…

大模型tokenizer重構流程

大模型tokenizer層再訓練&#xff08;選取Qwen7B試驗&#xff0c;重構token層&#xff09; 最近公司可能想訓練一個蛋白質大模型&#xff0c;需要了解一下大模型tokenizer重構&#xff0c;之后可能要訓練&#xff0c;這里做了一定的總結。 文章目錄 1. 首先查看Qwen2.5 7B基本…

Android設計模式之單例模式

一、定義&#xff1a;確保一個類只有一個實例&#xff0c;并且自動實例化&#xff0c;并向整個系統提供這個實例。 二、使用場景&#xff1a;避免重復創建對象&#xff0c;過多消耗系統資源。 三、使用方式 3.1餓漢式&#xff1a;類加載時立即初始化&#xff0c;線程安全&…

docker ssh遠程連接

目錄 操作命令&#xff1a; 確保 SSH 配置允許 root 登錄&#xff1a; docker提交&#xff1a; 操作命令&#xff1a; # 進入容器 docker exec -ti lbg04 /bin/bash# 更新包管理并安裝 SSH 服務&#xff08;Ubuntu/Debian 示例&#xff09; apt-get update apt-get install…

關于matlab和python誰快的問題

關于matlab和python誰快的問題&#xff0c;python比matlab在乘法上快10倍&#xff0c;指數計算快4倍&#xff0c;加減運算持平&#xff0c;略慢于matlab。或許matlab只適合求解特征值。 import torch import timen 50000 # 矩陣規模 M torch.rand(n, 31)start_time time.t…

準確--配置服務器文件數

某些系統可能在 /etc/security/limits.d/ 目錄下有額外配置覆蓋全局設置。檢查是否存在沖突文件&#xff1a; ls /etc/security/limits.d/如果有文件&#xff08;如 90-nproc.conf 或 90-nofile.conf&#xff09;&#xff0c;需編輯或刪除這些文件中的沖突配置。 確保系統啟用…

VectorBT:使用PyTorch+LSTM訓練和回測股票模型 進階一

VectorBT&#xff1a;使用PyTorchLSTM訓練和回測股票模型 進階一 本文介紹了如何使用PyTorch和LSTM模型進行股票數據的訓練和回測。涵蓋了數據預處理、特征選擇、LSTM模型構建、模型訓練與驗證、動態閾值策略生成交易信號以及使用VectorBT進行回測和績效分析。 文中內容僅限技術…

mysql中的聚簇索引,什么是聚簇索引和非聚簇索引

文章目錄 1. 什么是聚簇索引2. 非聚簇索引3. 聚簇索引的優缺點4. 聚簇索引的使用場景5. 聚簇索引和主鍵索引的異同前言: 在繼續講解專欄內容之前,先學習幾個概念,以便更好了解: 什么是聚簇索引什么是回表這篇文章詳細分析 聚簇索引。回表的理解可以進入這篇文章:什么是回表…

MantisBT在Windows10上安裝部署詳細步驟

MantisBT 是一款基于 Web 的開源缺陷跟蹤系統&#xff0c;以下是在 Windows 10 上安裝部署 MantisBT 的詳細步驟&#xff1a; 1. 安裝必要的環境 MantisBT 是一個基于 PHP 的 Web 應用程序&#xff0c;因此需要安裝 Web 服務器&#xff08;如 Apache&#xff09;、PHP 和數據…

深入理解K8s與Docker的關系:容器化技術的雙雄

友情提示&#xff1a;本文內容由銀河易創&#xff08;https://ai.eaigx.com&#xff09;AI創作平臺gpt-4-turbo模型生成&#xff0c;僅供參考。 在現代云計算及微服務架構的發展中&#xff0c;Docker與Kubernetes&#xff08;K8s&#xff09;作為兩大核心技術&#xff0c;被廣泛…

藍橋與力扣刷題(藍橋 藍橋騎士)

題目&#xff1a;小明是藍橋王國的騎士&#xff0c;他喜歡不斷突破自我。 這天藍橋國王給他安排了 N 個對手&#xff0c;他們的戰力值分別為 a1,a2,...,an&#xff0c;且按順序阻擋在小明的前方。對于這些對手小明可以選擇挑戰&#xff0c;也可以選擇避戰。 身為高傲的騎士&a…

如何查看window電腦的GPU信息

GPU&#xff08;圖形處理器&#xff0c;Graphics Processing Unit&#xff09;和顯卡是兩個密切相關但不同的概念 概念 1. ?基本概念? ?GPU?&#xff1a;是專門用于處理圖像和視頻信息的微處理器&#xff0c;擁有強大的并行計算能力&#xff0c;主要負責圖形渲染、數值分…