MongoDB와 CrewAI 를 통합하여 특수한 역할, 도구 및 작업을 통해 자율적인 AI 에이전트와 멀티 에이전트 애플리케이션을 빌드 할 수 있습니다. 구체적으로, CrewAI를 위한 MongoDB 벡터 검색 도구를 활용하여 팀원 의 AI 에이전트가 데이터에서 관련 정보를 조회하여 작업을 완료하도록 활성화할 수 있습니다.
시작하기
CrewAI 및 MongoDB 사용하여 튜토리얼을 완료하려면 CrewAI 및 MongoDB 사용하여 에이전트적 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 toolprint(tool.run(query="<test-query>"))
# To use the tool in an agentrag_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 configurationquery_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 toolprint(tool.run(query="<test-query>"))
# To use the tool in an agentrag_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 osfrom 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 foldertexts = []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 storetool.add_texts(texts)
# Method to create the vector search indextool.create_vector_search_index(dimensions=<number-of-dimensions>)
# Method to test the tool by running a vector search querytool.run(query="<search-query>")