Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs Menu
Docs Home
/
Atlas
/ /

MongoDB 와 CrewAI 통합

MongoDB CrewAI 와 통합하여 특수한 역할, 도구 및 작업을 통해 자율 AI 에이전트 및 멀티 에이전트 애플리케이션을 빌드 할 수 있습니다. 구체적으로, CrewAI용 MongoDB 벡터 검색 도구를 활용하여 팀원의 AI 에이전트가 데이터에서 관련 정보를 조회 작업을 완료하도록 활성화 수 있습니다.

CrewAI 및 MongoDB 사용하여 튜토리얼을 완료하려면 CrewAI 및 MongoDB 사용하여 Agentic RAG 애플리케이션 빌드하기를 참조하세요.

CrewAI용 MongoDB 벡터 검색 도구를 설치하려면 Python 패키지 관리자에 따라 다음 명령 중 하나를 실행 .

pip install 'crewai-tools[mongodb]'
uv add crewai-tools --extra mongodb

참고

Python 버전 호환성은 CrewAI의 공식 문서와 다를 수 있습니다. 작성 시점에서 crewai-tools 패키지 embedchain에 종속되며, 이를 위해서는 3.9 에서 3.13.2 사이의 Python 버전이 필요합니다. (포함).

MongoDB 벡터 검색 도구를 사용하려면 초기화한 다음 에이전트 에 전달합니다.

도구를 초기화하려면 다음을 지정해야 합니다.

from crewai_tools import MongoDBVectorSearchTool
tool = MongoDBVectorSearchTool(
connection_string="<connection-string>",
database_name="<database-name>",
collection_name="<collection-name>",
# Other optional parameters...
)
# To test the tool
print(tool.run(query="<test-query>"))
# To use the tool in an agent
rag_agent = Agent(
name="rag_agent",
role="You are a helpful assistant that can answer questions with the help of the MongoDBVectorSearchTool.",
goal="...",
backstory="...",
tools=[tool],
)

선택적으로 도구의 생성자에 MongoDBVectorSearchConfig 인스턴스 를 지정하여 도구에 대한 벡터 검색 쿼리 사용자 지정할 수 있습니다.

벡터 검색 쿼리에 대해 자세히 알아보려면 벡터 검색 쿼리 실행을 참조하세요.

from crewai_tools import MongoDBVectorSearchConfig, MongoDBVectorSearchTool
# Custom query configuration
query_config = MongoDBVectorSearchConfig(
limit = 10,
oversampling_factor = 2,
)
tool = MongoDBVectorSearchTool(
database_name="example_database",
collection_name="example_collection",
connection_string="<connection_string>",
query_config=query_config,
# Other optional parameters...
)
# To test the tool
print(tool.run(query="<test-query>"))
# To use the tool in an agent
rag_agent = Agent(
name="rag_agent",
role="You are a helpful assistant that can answer questions with the help of the MongoDBVectorSearchTool.",
goal="...",
backstory="...",
tools=[tool],
)

MongoDBVectorSearchTool 클래스는 다음 메서드를 제공합니다.

  • add_texts(): 지정된 MongoDB 컬렉션 에 텍스트 문서를 추가합니다.

  • create_vector_search_index(): 컬렉션 에 벡터 검색 인덱스 만듭니다.

  • run(): 데이터에 대해 벡터 검색 쿼리 실행합니다.

import os
from crewai_tools import MongoDBVectorSearchTool
tool = MongoDBVectorSearchTool(
connection_string="<connection-string>",
database_name="<database-name>",
collection_name="<collection-name>"
)
# Example of loading text content from a local folder
texts = []
for fname in os.listdir("knowledge"):
path = os.path.join("knowledge", fname)
if os.path.isfile(path):
with open(path, "r", encoding="utf-8") as f:
texts.append(f.read())
# Method to add documents to the vector store
tool.add_texts(texts)
# Method to create the vector search index
tool.create_vector_search_index(dimensions=<number-of-dimensions>)
# Method to test the tool by running a vector search query
tool.run(query="<search-query>")

돌아가기

AI 에이전트 빌드

이 페이지의 내용