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], )
Parameter | 필요성 | 설명 | |
|---|---|---|---|
| 필수 사항 | MongoDB 인스턴스 의 연결 문자열 . 연결 문자열 찾는 방법에 대해 자세히 학습하려면 드라이버를 통해 클러스터에 연결하기를 참조하세요. 참고로컬 배포서버 의 경우 연결 문자열 다음 형식을 사용해야 합니다. 연결 문자열에 대해 자세히 학습 연결 문자열을 참조하세요. | |
| 필수 사항 | MongoDB database 의 이름입니다. | |
| 필수 사항 | MongoDB 컬렉션 의 이름입니다. | |
| 옵션 | 벡터 검색 쿼리 사용자 지정하기 위한 | |
| 옵션 | 벡터 임베딩을 생성하는 데 사용되는 OpenAI 임베딩 모델입니다. 기본값은 | |
| 옵션 | MongoDB Vector Search 인덱스 의 이름입니다. 기본값은 | |
| 옵션 | 텍스트 콘텐츠가 포함된 문서 필드 . 기본값은 | |
| 옵션 | 벡터 임베딩이 저장되는 문서 필드 . 기본값은 | |
| 옵션 | 벡터 임베딩을 위한 차원 수입니다. 기본값은 |
Parameter | 필요성 | 설명 |
|---|---|---|
| 옵션 | 반환할 문서의 최대 개수. 기본값은 |
| 옵션 | 벡터 검색 전에 문서를 필터하다 하는 MongoDB |
| 옵션 | 벡터 검색 후 적용 할 MongoDB 집계 단계 목록입니다. |
| 옵션 | 검색 중에 고려되는 후보 수( |
| 부울 | 참이면 각 결과의 벡터 임베딩이 출력에 포함됩니다. 기본값은 |
팁
방법
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>")
Parameter | 필요성 | 설명 |
|---|---|---|
| 필수 사항 | 임베딩 벡터의 차원 수입니다. |
| 옵션 | 유사성 메트릭입니다. |
| 옵션 | 인덱스 준비될 때까지 기다리는 시간(초)입니다. 기본값은 |
벡터 검색 인덱스에 대해 자세히 학습하려면 벡터 검색을 위해 필드를 인덱싱하는 방법을 참조하세요.