MongoDB as a Vector Database for AI Agents
说明与用途
构建一个使用 MongoDB Atlas 作为向量数据库、VoyageAI 生成嵌入、Claude 进行生成的食谱助手,并持久化用户记忆。
问题
Build an AI recipe assistant that can answer natural‑language queries and remember user preferences without a separate vector store.
结果
The assistant can semantically search recipes and remember user preferences across sessions using a single MongoDB Atlas cluster, eliminating the need for a separate vector store.
工作流
- Create project directory and virtual environment
- Install langchain, langchain‑anthropic, langchain‑mongodb, langchain‑voyageai, pymongo, requests, python‑dotenv
- Create .gitignore for secrets
- Set up MongoDB Atlas M0 cluster, create user and whitelist IP
- Create .env with MONGODB_URI, VOYAGE_API_KEY, ANTHROPIC_API_KEY
- Create JavaScript script to create recipes and memories collections and attach vector search indexes
- Fetch recipes from TheMealDB and embed with VoyageAI
- Insert embeddings into MongoDB
- Configure LangChain retriever and Claude agent
- Run agent to answer queries and store/retrieve memories
证据
MongoDB is a general‑purpose document database with several modules embedded in its core that turn it into a complete data platform for modern application development.
The agent will answer natural language questions like "what can I make with rice and saffron?" by performing a semantic search over a collection of recipes fetched from TheMealDB, a free, public recipe API that requires no key.
MongoDB handles both structured and semantic workloads without splitting your infrastructure or adding complexity to your software.
- 记录日期: 2026-10-02T09:56:07.098Z