Pavel Duchovny
Workflows by Pavel Duchovny
Travel planning assistant with MongoDB Atlas, Gemini LLM and vector search
Building agentic AI workflows often requires multiple moving parts: memory management, document retrieval, vector similarity, and orchestration. Until now, these pieces had to be custom-wired. But with the new native n8n nodes for MongoDB Atlas, we reduce that overhead dramatically. With just a few clicks: - Store and recall long-term memory from MongoDB - Query vector embeddings stored in Atlas Vector Search - Use these results in your LLM chains and automation logic In this example we present an ingestion and AI Agent flows that focus around Travel Planning. The different interest points that we want the agent to know about can be ingested into the vector store. The AI Agent will use the vector store tool to get relevant context about those points of interest if it needs to. ### Prerequisites - [MongoDB Atlas project and Cluster](https://www.mongodb.com/docs/atlas/tutorial/create-new-cluster/) - OpenAI Valid API Key for embeddings (can be other provider) - Gemini API Key for the LLM (can be other provider) ### How it works: There are 2 main flows. 1. One is ingesting flow: - Gets a document from a webhook and use MongoDB Vector Atlas to embed the document `title` and `description` into `points_of_interest` collection. - Embeddings are stored in a field named `embedding` - Embeddings used are OpenAI's but it can be any type of supported embedders. 2. Second flow is an AI Agent node with Chat Memory Stored in MongoDB Atlas and a Vector Search node as a tool: - **Chat Message Trigger**: Chatting with the AI Agent will trigger the conversation store in the MongoDB Chat Memory node. - When data is necessary like a location search or details it will go to the "Vector Search" tool. - **Vector Search Tool** - uses Atlas Vector Search index created on the `points_of_interest` collection: ``` // index name : "vector_index" // If you change an embedding provider make sure the numDimensions correspond to the model. { "fields": [ { "type": "vector", "path": "embedding", "numDimensions": 1536, "similarity": "cosine" } ] } ``` **Additional Resources** - [MongoDB Atlas Vector Search](https://www.mongodb.com/docs/atlas/atlas-vector-search/tutorials/vector-search-quick-start/?utm=n8n.io) - [n8n Atlas Vector Search docs](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstoremongodbatlas?utm=n8n.io)
MongoDB AI agent - intelligent movie recommendations
## Who is this for? This workflow is designed for: - Database administrators and developers working with MongoDB - Content managers handling movie databases - Organizations looking to implement AI-powered search and recommendation systems - Developers interested in combining LangChain, OpenAI, and MongoDB capabilities ## What problem does this workflow solve? Traditional database queries can be complex and require specific MongoDB syntax knowledge. This workflow addresses: - The complexity of writing MongoDB aggregation pipelines - The need for natural language interaction with movie databases - The challenge of maintaining user preferences and favorites - The gap between AI language models and database operations ## What this workflow does This workflow creates an intelligent agent that: 1. Accepts natural language queries about movies 2. Translates user requests into MongoDB aggregation pipelines 3. Queries a movie database containing detailed information including: - Plot summaries - Genre classifications - Cast and director information - Runtime and release dates - Ratings and awards 4. Provides contextual responses using OpenAI's language model 5. Allows users to save favorite movies to the database 6. Maintains conversation context using a window buffer memory ## Setup 1. **Required Credentials**: - OpenAI API credentials - MongoDB connection details 2. **Node Configuration**: - Configure the MongoDB connection in the MongoDBAggregate node - Set up the OpenAI Chat Model with your API key - Ensure the webhook trigger is properly configured for receiving chat messages 3. **Database Requirements**: - A MongoDB collection named "movies" with the specified document structure - Proper indexes for efficient querying - Appropriate user permissions for read/write operations ## How to customize this workflow 1. **Modify the Document Structure**: - Update the tool description in the MongoDBAggregate node to match your collection schema - Adjust the aggregation pipeline templates for your specific use case 2. **Enhance the AI Agent**: - Customize the prompt in the "AI Agent - Movie Recommendation" node - Modify the window buffer memory size based on your context needs - Add additional tools for more functionality 3. **Extend Functionality**: - Add more MongoDB operations beyond aggregation - Implement additional workflows for different types of queries - Create custom error handling and validation - Add user authentication and rate limiting 4. **Integration Options**: - Connect to external APIs for additional movie data - Add webhook endpoints for different platforms - Implement caching mechanisms for frequent queries - Add data transformation nodes for specific output formats This workflow serves as a foundation that can be adapted to various use cases beyond movie recommendations, such as e-commerce product search, content management systems, or any scenario requiring intelligent database interaction.