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

CrewAI 및 MongoDB 사용하여 에이전트적 RAG 애플리케이션 구축

이 튜토리얼에서는 MongoDB Vector Search 도구를 사용하여 PDF 문서를 분석 할 수 있는 AI 에이전트 가 포함된팀 를 빌드 .

MongoDB CrewAI 통합에 대해 자세히 학습 CrewAI와 MongoDB 통합을 참조하세요.

이 튜토리얼을 완료하려면 다음 조건을 충족해야 합니다.

  • CrewAI가 설치되었습니다.자세한 학습 은 설치를 참조하세요.

  • 다음 중 하나입니다.

    • MongoDB 버전 6.0.11 을 실행 Atlas cluster , 7.0.2 이상입니다. IP 주소 가 Atlas 프로젝트의 액세스 목록에 포함되어 있는지 확인하세요.

    • Atlas CLI 사용하여 생성된 로컬 Atlas 배포서버 입니다. 자세히 학습 로컬 Atlas 클러스터 배포를 참조하세요.

  • OpenAI API 키입니다. API 요청에 사용할 수 있는 크레딧이 있는 OpenAI 계정이 있어야 합니다. OpenAI 계정 등록에 대해 자세히 학습 OpenAI API 웹사이트 참조하세요.

참고

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

다음 단계를 완료하여 팀을 빌드 하고 실행 .

1
  1. 터미널에서 다음 명령을 실행하여 crewai-mongodb-project 라는 새 디렉토리 만들고 필요한 종속성을 설치합니다.

    mkdir crewai-mongodb-project
    cd crewai-mongodb-project
    pip install 'crewai-tools[mongodb]' python-dotenv langchain-community
  2. 프로젝트 에서 .env 파일 만들고 다음 줄을 추가합니다.

    OPENAI_API_KEY="<openai-api-key>"
    MONGODB_URI="<connection-string>"

    참고

    <connection-string> 을(를 ) Atlas cluster 또는 로컬 Atlas 배포서버 대한 연결 문자열 로 바꿉니다.

    연결 문자열은 다음 형식을 사용해야 합니다.

    mongodb+srv://<db_username>:<db_password>@<clusterName>.<hostname>.mongodb.net

    자세한 학습 은 드라이버를 통해 클러스터에 연결을 참조하세요.

    연결 문자열은 다음 형식을 사용해야 합니다.

    mongodb://localhost:<port-number>/?directConnection=true

    학습 내용은 연결 문자열을 참조하세요.

2

프로젝트 에 main.py 라는 파일 만들고 다음 코드를 붙여넣습니다.

from crewai import Agent, Task, Crew, Process, LLM
from crewai_tools import MongoDBVectorSearchTool, MongoDBVectorSearchConfig
from langchain_community.document_loaders import PyPDFLoader
from dotenv import load_dotenv
import os, time
load_dotenv()
def rag_agent():
"""
An agent that uses RAG to analyze recent MongoDB announcements.
"""
# Configure the vector search tool
tool = MongoDBVectorSearchTool(
connection_string = os.environ.get("MONGODB_URI"),
database_name = "crewai_db",
collection_name = "test"
)
# Connect to MongoDB collection and delete all documents
coll = tool._coll
coll.delete_many({})
# Load PDF from URL and insert documents into MongoDB
print("Loading MongoDB AI announcements PDF...")
loader = PyPDFLoader("https://investors.mongodb.com/node/13556/pdf")
tool.add_texts([i.page_content for i in loader.load()])
# Create the vector search index
print("Creating vector search index...")
if not any([ix["name"] == "vector_index" for ix in coll.list_search_indexes()]):
tool.create_vector_search_index(dimensions=1536, auto_index_timeout=60)
# Wait for index initial sync to complete
n_docs = coll.count_documents({})
start = time.monotonic()
while time.monotonic() - start <= 60:
if len(tool._run("test query")) == n_docs:
print("Index is ready for queries")
break
else:
time.sleep(1)
# Specify a custom vector search query (optional)
tool.query_config = MongoDBVectorSearchConfig(
limit=3, score_threshold=0.75
)
# Test the tool
print("Testing the tool...")
print(tool.run(query="AI announcements"))
# Assemble a crew by specifying an agent and its task
researcher = Agent(
role="MongoDB Announcement Researcher",
goal="Find and extract key information about MongoDB's recent announcements and developments",
backstory="You're specialized in analyzing business and technology announcements",
verbose=False,
tools=[tool],
llm=LLM(model="gpt-4o"), # Customize to your LLM of choice
)
research_task = Task(
description="Research MongoDB's recent AI announcements and developments",
expected_output="A summary of MongoDB's latest AI initiatives, partnerships, and features",
agent=researcher,
)
crew = Crew(
agents=[researcher],
tasks=[research_task],
process=Process.sequential,
verbose=False
)
# Get the results and print the analysis
print("Running the crew...")
result = crew.kickoff()
print("\n" + "="*50 + "\nMONGODB AI ANNOUNCEMENTS ANALYSIS:\n" + "="*50)
print(result.raw)
return result
if __name__ == "__main__":
rag_agent()

이 스크립트 다음을 수행합니다.

3

다음 명령을 실행하여 스크립트 실행합니다.

uv run main.py
Loading MongoDB AI announcements PDF...
Creating vector search index...
Testing the tool...
Using Tool: MongoDBVectorSearchTool
[{"_id": {"$oid": "689baa5e6907244d329d0586"}, "text": "MongoDB Strengthens Foundation for AI Applications with Product Innovations and Expanded\nPartner Ecosystem\nAugust 11, 2025\nNew Voyage AI models introduce context awareness and set new accuracy benchmarks\u2014at industry-leading price-performance\nMongoDB's AI ecosystem expands AI framework, agentic evaluation, and agentic workflow orchestration capabilities\nApproximately 8,000 startups, including Laurel and Mercor, have chosen MongoDB to help build their AI projects ... (truncated)
Running the crew...
==================================================
MONGODB AI ANNOUNCEMENTS ANALYSIS:
==================================================
**MongoDB Strengthens Foundation for AI Applications with Product Innovations and Expanded Partner Ecosystem**
**August 11, 2025**
MongoDB announced a range of product innovations and AI partner ecosystem expansions at Ai4 2025 to make it faster and easier for customers to build accurate, trustworthy, and reliable AI applications at scale. The company is providing industry-leading embedding models and a fully integrated, AI-ready data platform, alongside assembling a world-class ecosystem of AI partners to deliver reliable and cost-effective AI solutions.
**Key Highlights from AI Initiatives:**
### AI Innovations:
- **Voyage AI Models**:
- MongoDB introduced context-aware embedding models, achieving better retrieval accuracy without requiring metadata hacks or pipeline gymnastics.
- New model variants, such as **voyage-context-3**, **voyage-3.5**, and **voyage-3.5-lite**, deliver groundbreaking retrieval accuracy at competitive price-performance metrics.
- **Instruction-following reranking models** like `rerank-2.5` and `rerank-2.5-lite` enable developers to improve retrieval accuracy further.
- **MongoDB MCP Server**:
- Launched as a public preview, the MongoDB Model Context Protocol (MCP) Server enables direct integration with popular tools like GitHub CoPilot in Visual Studio Code, Anthropic's Claude, Cursor, and Windsurf.
- Thousands of users have been actively building applications leveraging this new protocol.
### Partnerships:
MongoDB expanded its AI partner ecosystem to provide customers with streamlined workflows and reliable AI applications:
- **Galileo**:
- A reliability and observability platform for AI applications that offers continuous evaluations and monitoring for MongoDB-based projects.
- **Temporal**:
- A Durable Execution platform that empowers developers to orchestrate scalable, resilient AI use cases like retrieval-augmented generation (RAG) systems and context engineering pipelines. Temporal ensures that AI solutions can operate smoothly across distinct failures and interactions.
- **LangChain**:
- MongoDB's partnership with LangChain has facilitated advancements like natural language querying, agent-based system creation, and **GraphRAG** for enhanced LLM transparency. Developers can build sophisticated AI systems deploying real-time, proprietary MongoDB data.
### Developer Engagement:
- MongoDB has seen substantial adoption among both startups and enterprises:
- Approximately 8,000 startups selected MongoDB for AI projects, including Laurel (timekeeping startup) and Mercor (AI-based talent matching).
- Large enterprises like Vonage, LGU+, and The Financial Times also rely on MongoDB for scalable AI infrastructure.
### Thought Leadership:
Andrew Davidson, SVP of Products at MongoDB, emphasized the importance of robust database systems in the era of AI:
- "Modern AI applications require a database combining advanced capabilities such as integrated vector search and embedding models. By consolidating the AI stack, MongoDB is empowering developers to deliver innovative AI solutions faster than ever."
Fred Roma, SVP of Engineering, further highlighted the challenge of scaling AI due to complexity in fine-tuning models, high expenses, and integration barriers:
- "MongoDB's focus remains on designing models that achieve better functionality, reliability, and affordability for developers leveraging AI applications."
### About MongoDB:
MongoDB, headquartered in New York, provides a unified database platform powering next-gen applications across industries. Its comprehensive platform integrates operational data, search, real-time analytics, and AI-powered retrieval, supporting millions of developers globally. MongoDB boasts over 50,000 customers and supports a growing AI application ecosystem.
For more information on MongoDB's AI endeavors, visit [mongodb.com](https://www.mongodb.com).
### Sources:
Original announcement and additional multimedia available at [PRNewswire](https://www.prnewswire.com/news-releases/mongodb-strengthens-foundation-for-ai-applications-with-product-innovations-and-expanded-partner-ecosystem-302526003.html).
Contact: **press@mongodb.com** for press inquiries.

돌아가기

CrewAI

이 페이지의 내용