🚀 免費嘗試 Zilliz Cloud,完全托管的 Milvus,體驗速度提升 10 倍!立即嘗試

milvus-logo
LFAI
主頁
  • 整合
    • 代理商

與 Milvus 整合的 MemGPT

MemGPT可讓您輕鬆建立和部署有狀 LLM 代理。透過 Milvus 整合,您可以建立與外部資料來源 (RAG) 連結的代理。

在本範例中,我們要使用 MemGPT 與儲存於 Milvus 的自訂資料來源聊天。

設定

要執行 MemGPT,您必須確定 Python 版本 >= 3.10。

要啟用 Milvus 後端,請確認安裝所需的相依性:

$ pip install 'pymemgpt[milvus]'

您可以透過命令設定 Milvus 連線。

$ memgpt configure
...
? Select storage backend for archival data: milvus
? Enter the Milvus connection URI (Default: ~/.memgpt/milvus.db): ~/.memgpt/milvus.db

您只需將 URI 設定為本機檔案路徑,例如~/.memgpt/milvus.db ,這將自動透過 Milvus Lite 啟用本機的 Milvus 服務實體。

如果您有大規模的資料,例如超過一百萬份的文件,我們建議您在docker 或 kubenetes 上架設效能更高的 Milvus 伺服器。 在這種情況下,您的 URI 應該是伺服器的 URI,例如http://localhost:19530

建立外部資料來源

要將外部資料饋送至 MemGPT 聊天機,我們首先需要建立資料來源。

要下載 MemGPT 研究論文,我們會使用curl (您也可以直接從瀏覽器下載 PDF):

# we're saving the file as "memgpt_research_paper.pdf"
$ curl -L -o memgpt_research_paper.pdf https://arxiv.org/pdf/2310.08560.pdf

現在我們已經下載了論文,可以使用memgpt load 建立 MemGPT 資料來源:

$ memgpt load directory --name memgpt_research_paper --input-files=memgpt_research_paper.pdf
Loading files: 100%|███████████████████████████████████| 1/1 [00:00<00:00,  3.94file/s]
Loaded 74 passages and 13 documents from memgpt_research_paper

將資料來源附加到 MemGPT 代理

既然我們已經建立了這個資料來源,就可以隨時將它附加到 MemGPT 聊天機上。

讓我們使用memgpt_doc 角色(但您也可以使用任何角色)建立一個新的聊天機器人:

# reminder: `memgpt run --persona memgpt_doc` will create a new MemGPT agent using the `memgpt_doc` persona
$ memgpt run --persona memgpt_doc

與代理聊天後,我們就可以將資料來源「附加」到代理的存檔記憶體:

? Would you like to select an existing agent? No

🧬 Creating new agent...
->  🤖 Using persona profile: 'sam_pov'
->  🧑 Using human profile: 'basic'
🎉 Created new agent 'PoliteButterfly' (id=d26e1981-ff36-4095-97a0-61a1601dfb5d)

Hit enter to begin (will request first MemGPT message)

💭 Interesting, I've got a first-time user. Time to present myself and get to understand the user's needs. I wonder what brings Chad here today.
🤖 Greetings Chad! I'm MemGPT. How may I assist you today?

> Enter your message: /attach
? Select data source memgpt_research_paper
100%|███████████████████████████████████| 1/1 [00:00<00:00,  4.81it/s]

測試我們的新聊天機器人

既然資料已經載入聊天機器人的記憶體,我們就可以開始詢問相關問題了:

> Enter your message: The paper I loaded into your archival memory is called MemGPT. Can you tell me more about it?

💭 It seems Chad would like to know more about the paper titled 'MemGPT' that's stored in my archival memory. It's time to search the archival memory for details and background data to provide a comprehensive
understanding of the paper. Let's remember to page through results until I've gathered enough information to answer Chad's enquiry.
⚡🧠 [function] searching memory with archival_memory_search
💭 Based on the found results, MemGPT is an AI system designed for tasks like extended conversations and document analysis. It efficiently manages different tiers of storage to provide extended context within
the LLM’s limited cap. Also, noteworthy from my findings is that MemGPT performs impressively in deep memory retrieval (DMR) and document QA tasks. Let's prepare a comprehensive response for Chad.
🤖 Certainly, Chad. MemGPT, or MemoryGPT, is a system specially designed for tasks like extended conversations and document analysis which are traditionally hindered by the limited context windows of modern 
Large Language Models (LLMs). It uses a technique inspired by hierarchical memory systems in traditional operating systems, called virtual context management. This technique allows for an effective provision 
of extended context within an LLM’s limited context window by intelligently managing different storage tiers, much like paging between physical memory and disk. Notably, MemGPT outperforms the fixed-context 
baselines in deep memory retrieval and it's able to analyze large documents with precision.

免費嘗試托管的 Milvus

Zilliz Cloud 無縫接入,由 Milvus 提供動力,速度提升 10 倍。

開始使用
反饋

這個頁面有幫助嗎?