Milvus와 Phidata 통합
Phidata는 지능형 에이전트 및 워크플로를 구축하기 위한 강력한 프레임워크입니다. 이를 통해 텍스트, 이미지, 오디오 및 비디오를 이해하고 다양한 도구와 지식 소스를 활용하여 복잡한 작업을 수행할 수 있는 멀티모달 에이전트를 만들 수 있습니다. Phidata는 멀티 에이전트 오케스트레이션을 지원하여 여러 에이전트 팀이 함께 협업하고 문제를 해결할 수 있도록 합니다. 또한 에이전트와의 상호 작용을 위한 멋진 에이전트 UI를 제공합니다.
Milvus 벡터 데이터베이스를 사용하면 정보를 임베딩으로 효율적으로 저장하고 검색할 수 있습니다. Milvus와 Phidata를 사용하면 지식을 상담원 워크플로우에 쉽게 통합할 수 있습니다. 이 문서는 Milvus와 Phidata 통합을 사용하는 방법에 대한 기본 안내서입니다.
준비 단계
필요한 종속성을 설치합니다:
$ pip install --upgrade phidata pymilvus openai
Google Colab을 사용하는 경우 방금 설치한 종속성을 사용하려면 런타임을 다시 시작해야 할 수 있습니다(화면 상단의 "런타임" 메뉴를 클릭하고 드롭다운 메뉴에서 "세션 다시 시작"을 선택).
이 예제에서는 OpenAI를 LLM으로 사용하겠습니다. 환경 변수로 OPENAI_API_KEY
API 키를 준비해야 합니다.
import os
os.environ["OPENAI_API_KEY"] = "sk-***********"
Milvus 초기화
패키지를 가져와서 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",
)
Milvus 서버의 컬렉션 이름과 uri 및 토큰(옵션)을 지정합니다.
URL과 토큰을 설정하는 방법은 다음과 같습니다:
소규모 데이터나 프로토타이핑을 위한 로컬 벡터 데이터베이스만 필요한 경우, Uri를 로컬 파일(예:
./milvus.db
)로 설정하는 것이 가장 편리한 방법이며, 이 파일에 모든 데이터를 저장하기 위해 Milvus Lite를 자동으로 활용하기 때문입니다.백만 개 이상의 벡터와 같이 대규모 데이터가 있는 경우, Docker 또는 Kubernetes에서 더 성능이 뛰어난 Milvus 서버를 설정할 수 있습니다. 이 설정에서는 서버 주소와 포트를 URI로 사용하세요(예:
http://localhost:19530
). Milvus에서 인증 기능을 활성화하는 경우 토큰으로 "<사용자 이름>:<사용자 비밀번호>"를 사용하고, 그렇지 않은 경우 토큰을 설정하지 마세요.밀버스의 완전 관리형 클라우드 서비스인 질리즈 클라우드를 사용하는 경우, 질리즈 클라우드의 퍼블릭 엔드포인트와 API 키에 해당하는
uri
와token
를 조정합니다.
데이터 로드
PDF URL 지식베이스 인스턴스를 생성하고 해당 인스턴스에 데이터를 로드합니다. 여기서는 공개 레시피 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 컬렉션 생성하기
INFO 지식창고 불러오기
INFO 읽기 중: https: //phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf
정보 지식창고에 문서 0개 추가됨
상담원을 사용하여 질문에 응답하기
지식창고를 에이전트에 통합하면 에이전트에게 질문하고 답변을 받을 수 있습니다.
# 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! ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
축하드립니다. Phidata에서 Milvus 사용의 기본 사항을 배웠습니다. Phidata 사용 방법에 대해 더 자세히 알고 싶으시면 공식 문서를 참조하세요.