BLOGAtlas Vector Search voted most loved vector database in 2024 Retool State of AI report — Read more >>


Build AI smart agents with MongoDB, Fireworks AI, and Langchain

How to combine large language models with the advanced retrieval strategies to unlock AI-powered app development using the Langhcain framework, Fireworks AI platform and MongoDB Atlas.
Start Free
An illustration featuring hands typing on a laptop in the foreground, with a crane holding a document in the background.
  • Use cases: Gen AI, Customer Experience
  • Industries: Retail, E-Commerce
  • Products: MongoDB Atlas, Atlas Vector Search
  • Partners: Fireworks AI, Langchain
Solution Overview

The integration of Fireworks' Firefunction LLM introduces a groundbreaking function-calling model to the smart agent architecture. This model excels in routing single-turn requests to specific functions, enhancing the efficiency of extracting structured information. Key attributes include:

  • Performance and speed: Boasts GPT-4 comparable performance with 4X faster inference speeds on the Fireworks platform.
  • Function-calling flexibility: Supports a dynamic 'any' parameter for versatile use case applications.
  • Seamless API integration: Ensures easy incorporation into existing systems with OpenAPI function-calling compatibility.

This advancement enables the development of applications that leverage multi-agent scenarios, facilitating the identification and execution of agent-directed action graphs (DAGs) with unmatched performance and adaptability.

Leveraging Langchain for generative AI applications

Langchain is a pivotal framework for creating generative AI applications, utilizing large language models (LLMs) across various hosting services. It simplifies the development process, offering a toolkit for:

  • Streamlined LLM integration: Interfaces for uniform interaction across LLM providers.
  • Enhanced data preprocessing: Tools for parsing and segmenting extensive datasets into manageable, retrievable units.
  • Dynamic embedding and retrieval: Simplifies embedding model integration and efficient data retrieval, underpinned by MongoDB Atlas's vector search capabilities.
  • Modular application design: Facilitates the construction of applications with complex decision-making and natural language processing features.

Langchain's abstraction layers empower developers to harness the full potential of LLMs, accelerating the development of sophisticated gen AI applications.

Reference Architectures
With MongoDB:

The smart agent architecture benefits immensely from MongoDB Atlas, particularly in executing autonomous, flexible pre-filter stages for vector search queries. This integration involves:

  • Dynamic data ingestion: Demonstrating the process of embedding textual data as vectors within MongoDB Atlas.
  • Agent-based application construction: Outlines the tools necessary for schema fetching, embedding generation, and MongoDB query execution, streamlining the development of agent-based applications.
Reference architecture with MongoDB illustration.
Building the Solution

This section provides a detailed guide on integrating the Fireworks Fire function LLM and Langchain to deploy custom agent tools.

Step 1:

Download the products dataset from this link and add the documents to the collection in MongoDB Atlas. We will also be embedding the raw product texts as vectors before adding them in MongoDB. You can find the same code here.

Step 2:

Integrate the fireworks fire function LLM and Langchain to deploy custom agent tools for:

  • Schema retrieval: Designed to fetch database schemas and identify fields to filter on.
  • Query embedding: Designed to generate user query embeddings.
  • MongoDB Atlas query execution: Facilitates the execution of queries, combining filters and vector embeddings for precise data retrieval.

Sample code can be found here.

The instructions offer a practical roadmap for harnessing the capabilities of MongoDB Atlas and Fireworks LLM in crafting agent-driven applications. The full cookbook to run the agents example with MongoDB can be found here.



Technologies and Products Used
MongoDB developer data platform:
  • Atlas Database
  • Atlas Vector Search
Partner technologies:
  • Fireworks AI
  • Langchain
Key Learnings

The synergy between MongoDB, Fireworks AI, and Langchain marks a significant leap forward in smart agent architecture. By providing a detailed guide to the integration and utilization of these technologies, this overview not only showcases the technical prowess of the solution but also invites developers to explore its potential in creating advanced, AI-powered applications. The emphasis on performance, flexibility, and ease of integration underscores the solution's value in fostering innovation within the realm of generative AI.

  • Ashwin Gangadhar, MongoDB
Related resources

GitHub Repository: [Fireworks X MongoDB Cookbook]

Create this demo for yourself by following the instructions and associated models in this solution’s repository.


AI Resource Hub

Get full access to our library of articles, analyst reports, case studies, white papers, and more.


Interactive RAG with MongoDB Atlas + Function Calling API

Tutorial to build an interactive RAG agent.

Get started with Atlas today

Get started in seconds. Our free clusters come with 512 MB of storage so you can experiment with sample data and get familiar with our platform.
Try FreeContact sales
Illustration of hands typing on a laptop in the foreground and a superimposed desktop window and coffee cup in the background.