milvus-logo
LFAI
Home
  • Integrações
    • Agentes

MemGPT com Integração Milvus

O MemGPT facilita a criação e a implantação de agentes LLM com estado. Com a integração do Milvus, é possível criar agentes com conexões a fontes de dados externas (RAG).

Neste exemplo, vamos usar o MemGPT para conversar com uma fonte de dados personalizada que está armazenada no Milvus.

Configuração

Para executar o MemGPT, deve certificar-se de que a versão do Python é >= 3.10.

Para ativar o backend do Milvus, certifique-se de que instala as dependências necessárias:

$ pip install 'pymemgpt[milvus]'

Pode configurar a ligação ao Milvus através do comando

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

Basta definir o URI para o caminho do ficheiro local, por exemplo, ~/.memgpt/milvus.db, que invocará automaticamente a instância local do serviço Milvus através do Milvus Lite.

Se tiver uma grande escala de dados, como mais de um milhão de documentos, recomendamos a configuração de um servidor Milvus de maior desempenho no docker ou kubenetes. E, neste caso, o seu URI deve ser o URI do servidor, por exemplo, http://localhost:19530.

Criando uma fonte de dados externa

Para alimentar um chatbot MemGPT com dados externos, precisamos primeiro de criar uma fonte de dados.

Para descarregar o documento de investigação do MemGPT, vamos utilizar curl (também pode simplesmente descarregar o PDF a partir do seu browser):

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

Agora que temos o documento descarregado, podemos criar uma fonte de dados MemGPT utilizando memgpt load:

$ 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

Anexar a fonte de dados a um agente MemGPT

Agora que criámos esta fonte de dados, podemos anexá-la a um chatbot MemGPT em qualquer altura.

Vamos criar um novo chatbot usando a persona memgpt_doc (mas você pode usar qualquer persona que desejar):

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

Quando estivermos a conversar com o agente, podemos "anexar" a fonte de dados à memória de arquivo do agente:

? 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]

Testar o nosso novo chatbot

Agora que os dados foram carregados na memória do chatbot, podemos começar a fazer perguntas sobre eles:

> 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.

Traduzido porDeepLogo

Try Zilliz Cloud for Free

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

Get Started
Feedback

Esta página foi útil?