🚀 Prova Zilliz Cloud, la versione completamente gestita di Milvus, gratuitamente—sperimenta prestazioni 10 volte più veloci! Prova Ora>>

Milvus
Zilliz
Casa
  • Integrazioni
    • Agenti

Integrare Milvus con Phidata

Phidata è un potente framework per la creazione di agenti e flussi di lavoro intelligenti. Consente di creare agenti multimodali in grado di comprendere testo, immagini, audio e video e di sfruttare vari strumenti e fonti di conoscenza per svolgere compiti complessi. Phidata supporta l'orchestrazione multi-agente, consentendo a team di agenti di collaborare e risolvere problemi insieme. Fornisce inoltre una bella interfaccia utente per interagire con gli agenti.

Il database vettoriale Milvus consente di memorizzare e recuperare in modo efficiente le informazioni sotto forma di embeddings. Con Milvus e Phidata, è possibile integrare facilmente le conoscenze nei flussi di lavoro degli agenti. Questo documento è una guida di base su come utilizzare l'integrazione di Milvus con Phidata.

Preparazione

Installare le dipendenze necessarie:

$ pip install --upgrade phidata pymilvus openai

Se si utilizza Google Colab, per abilitare le dipendenze appena installate, potrebbe essere necessario riavviare il runtime (fare clic sul menu "Runtime" nella parte superiore dello schermo e selezionare "Riavvia sessione" dal menu a discesa).

In questo esempio utilizzeremo OpenAI come LLM. È necessario preparare la chiave api OPENAI_API_KEY come variabile d'ambiente.

import os

os.environ["OPENAI_API_KEY"] = "sk-***********"

Inizializzare Milvus

Importare i pacchetti e inizializzare l'istanza del database vettoriale Milvus.

from phi.agent import Agent
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.milvus import Milvus

# Initialize Milvus
vector_db = Milvus(
    collection="recipes",
    uri="./milvus.db",
)

Specificare il nome della collezione, l'uri e il token (opzionale) per il server Milvus.

Ecco come impostare l'uri e il token:

  • Se si ha bisogno di un database vettoriale locale solo per dati su piccola scala o per la prototipazione, impostare l'uri come un file locale, ad esempio./milvus.db, è il metodo più conveniente, in quanto utilizza automaticamente Milvus Lite per memorizzare tutti i dati in questo file.

  • Se si dispone di una grande quantità di dati, ad esempio più di un milione di vettori, è possibile configurare un server Milvus più performante su Docker o Kubernetes. In questa configurazione, utilizzare l'indirizzo e la porta del server come uri, ad esempiohttp://localhost:19530. Se si attiva la funzione di autenticazione su Milvus, utilizzare "<nome_utente>:<password>" come token, altrimenti non impostare il token.

  • Se si utilizza Zilliz Cloud, il servizio cloud completamente gestito per Milvus, impostare uri e token, che corrispondono all'endpoint pubblico e alla chiave API di Zilliz Cloud.

Caricare i dati

Creare un'istanza di base di PDF url knowledage e caricare i dati nell'istanza. Utilizziamo come esempio i dati di una ricetta pubblica in formato pdf.

# Create knowledge base
knowledge_base = PDFUrlKnowledgeBase(
    urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
    vector_db=vector_db,
)

knowledge_base.load(recreate=False)  # Comment out after first run
INFO  Creazione della raccolta
INFO  Caricamento della base di conoscenza
INFO  Lettura: https: //phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf
INFO  Aggiunti 0 documenti alla base di conoscenza

Utilizzare un agente per rispondere a una domanda

Integrare la base di conoscenza in un agente, per poi porgli una domanda e ottenere una risposta.

# Create and use the agent
agent = Agent(knowledge_base=knowledge_base, use_tools=True, show_tool_calls=True)

# Query the agent
agent.print_response("How to make Tom Kha Gai", markdown=True)
Output()

    ┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
    ┃                                                                                                       ┃
    ┃ How to make Tom Kha Gai                                                                               ┃
    ┃                                                                                                       ┃
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    ┏━ Response (6.9s) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
    ┃                                                                                                       ┃
    ┃ Running:                                                                                              ┃
    ┃                                                                                                       ┃
    ┃  • search_knowledge_base(query=Tom Kha Gai recipe)                                                    ┃
    ┃                                                                                                       ┃
    ┃ Here's a recipe for Tom Kha Gai, a delicious Thai chicken and galangal soup made with coconut milk:   ┃
    ┃                                                                                                       ┃
    ┃ Ingredients (One serving):                                                                            ┃
    ┃                                                                                                       ┃
    ┃  • 150 grams chicken, cut into bite-size pieces                                                       ┃
    ┃  • 50 grams sliced young galangal                                                                     ┃
    ┃  • 100 grams lightly crushed lemongrass, julienned                                                    ┃
    ┃  • 100 grams straw mushrooms                                                                          ┃
    ┃  • 250 grams coconut milk                                                                             ┃
    ┃  • 100 grams chicken stock                                                                            ┃
    ┃  • 3 tbsp lime juice                                                                                  ┃
    ┃  • 3 tbsp fish sauce                                                                                  ┃
    ┃  • 2 leaves kaffir lime, shredded                                                                     ┃
    ┃  • 1-2 bird’s eye chilies, pounded                                                                    ┃
    ┃  • 3 leaves coriander                                                                                 ┃
    ┃                                                                                                       ┃
    ┃ Directions:                                                                                           ┃
    ┃                                                                                                       ┃
    ┃  1 Bring the chicken stock and coconut milk to a slow boil.                                           ┃
    ┃  2 Add galangal, lemongrass, chicken, and mushrooms. Once the soup returns to a boil, season it with f┃
    ┃  3 Wait until the chicken is cooked, then add the kaffir lime leaves and bird’s eye chilies.          ┃
    ┃  4 Remove the pot from heat and add lime juice.                                                       ┃
    ┃  5 Garnish with coriander leaves.                                                                     ┃
    ┃                                                                                                       ┃
    ┃ Tips:                                                                                                 ┃
    ┃                                                                                                       ┃
    ┃  • Keep the heat low throughout the cooking process to prevent the oil in the coconut milk from separ ┃
    ┃  • If using mature galangal, reduce the amount.                                                       ┃
    ┃  • Adding lime juice after removing the pot from heat makes it more aromatic.                         ┃
    ┃  • Reduce the number of chilies for a milder taste.                                                   ┃
    ┃                                                                                                       ┃
    ┃ Enjoy making and savoring this flavorful Thai soup!                                                   ┃
    ┃                                                                                                       ┃
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Congratulazioni, avete imparato le basi dell'uso di Milvus in Phidata. Se volete saperne di più sull'uso di Phidata, consultate la documentazione ufficiale.

Try Managed Milvus for Free

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

Get Started
Feedback

Questa pagina è stata utile?