A brand-new javascript library to automate the process of building RAG applications

Introducing MongoDB-RAG: A Fast and Easy Way to Build RAG-Enabled Chatbots and Search Applications

So many developers I talk with want to build Retrieval-Augmented Generation (RAG) applications, but setting up vector search, embedding generation, and index management can be complex.

That’s why I built MongoDB-RAG, an open-source NPM library that simplifies the entire workflow… allowing developers to create AI-powered chatbots, document search, and knowledge retrieval applications in minutes.

This post will guide you through what the library offers and how you can get started.


Why MongoDB-RAG?

Instead of manually setting up a vector search index, embeddings, and a retrieval pipeline, MongoDB-RAG provides a simplified interface that does the hard work for you:

  • Vector Search with MongoDB Atlas – Supports semantic search via Atlas Vector Search
  • Automated Index Management – Creates and verifies vector indexes
  • Multi-Provider Embeddings – Works with OpenAI, Ollama, DeepSeek, and Anthropic
  • Batch Document Ingestion – Convert text, markdown, or PDFs into searchable embeddings
  • Hybrid Search Support – Combine vector similarity with metadata filtering
  • CLI for Rapid Setup – Automate common RAG tasks in seconds

Best of all? You can have a RAG-enabled chatbot up and running in 10 minutes!


What We’ll Build

Using MongoDB-RAG, you can create an AI-powered helpdesk chatbot that retrieves relevant articles based on natural language queries.

This app will include:

  • A React-based UI for querying the chatbot
  • An Express backend API for processing search requests
  • MongoDB Atlas Vector Search for retrieval
  • Embedded knowledge base for instant responses

Quick Start

Install MongoDB-RAG

npm install -g mongodb-rag

Initialize MongoDB-RAG Configuration

Generate a .mongodb-rag.json configuration file:

npx mongodb-rag init

This will create:

{
  "name": "vector_index",
  "type": "vectorSearch",
  "definition": {
    "fields": [{
      "type": "vector",
      "path": "embedding",
      "numDimensions": 1536,
      "similarity": "cosine"
    }]
  }
}

Convert Configuration to Environment Variables

To simplify setup, transfer these settings to a .env file:

npx mongodb-rag create-env

This generates:

MONGODB_URI=mongodb+srv://your_user:your_password@your-cluster.mongodb.net/mongorag
MONGODB_DATABASE=helpdesk
MONGODB_COLLECTION=articles
PORT=4001

# Embedding Configuration
EMBEDDING_PROVIDER=openai
EMBEDDING_API_KEY=your-embedding-api-key
EMBEDDING_MODEL=text-embedding-3-small
EMBEDDING_DIMENSIONS=1536

Create a Vector Search Index

Run this command to automatically create an optimized vector search index:

npx mongodb-rag create-index

Alternatively, configure the index manually in MongoDB Atlas:

{
  "name": "vector_index",
  "type": "vectorSearch",
  "definition": {
    "fields": [{
      "type": "vector",
      "path": "embedding",
      "numDimensions": 1536,
      "similarity": "cosine"
    }]
  }
}


Ingest Helpdesk Articles

Prepare some markdown files with FAQs and troubleshooting guides, then run:

npx mongodb-rag ingest --directory ./helpdesk-docs

MongoDB-RAG will automatically generate embeddings and store them in MongoDB.


Perform a Vector Search

npx mongodb-rag search "wifi not connecting"

or via the API:

const results = await rag.search('AI topics', {
  filter: { 'metadata.source': 'tech-docs' },
  maxResults: 5
});

Your chatbot will now retrieve semantically similar articles from your knowledge base.


Full-Stack Helpdesk Chatbot

MongoDB-RAG lets you scaffold an entire RAG-enabled application in one command:

npx mongodb-rag create-rag-app my-helpdesk cd my-helpdesk npm install npm run dev

This generates:

my-helpdesk/
├── frontend/      # React UI
├── backend/       # Express API
└── .env           # Config settings

The application will be running at:


Advanced Features

MongoDB-RAG is designed for flexibility and scalability:

  • Multi-Database Support – Store embeddings in different collections dynamically
  • Hybrid Search – Combine vector search with metadata filtering
  • Batch Processing – Efficiently ingest large document sets
  • Multiple Embedding Models – Use OpenAI, Ollama, or DeepSeek based on your needs
  • Custom Chunking StrategiesSliding window, recursive, and semantic chunking

Example: Hybrid Search

const results = await rag.search('AI topics', { 
  filter: { 'metadata.source': 'tech-docs' },   
  maxResults: 5 
});

Use Cases

MongoDB-RAG is ideal for: - Helpdesk Chatbots – Intelligent support agents

  • Internal Knowledge Bases – Retrieve enterprise documentation
  • AI-Powered Search – Beyond traditional keyword search
  • Legal & Financial Research – Find documents with semantic meaning

Troubleshooting & Debugging

No Search Results?

  • Ensure your vector index exists
  • Check if your query vector matches the index dimensions

Slow Performance?

  • Adjust numCandidates for faster searches
  • Increase Atlas tier for better indexing performance

Embedding Issues?

  • Check OpenAI API limits
  • Reduce batch size if encountering timeouts

Run this command to test your configuration:

npx mongodb-rag test-connection


Learn More


Let me know what you think…

Are you working on a RAG-enabled chatbot or semantic search app? We’d love to hear about your experience!

  • Have feature requests?
  • Need help debugging?
  • Looking for best practices?

Drop a comment below or contribute to the MongoDB-RAG project on GitHub! :rocket:

Are you a javascript developer and want to help out with this project? Fork, and PR… or hit me up and let me know how you’d like to help. I’m currently wrestling with the testing framework and could use some help.

2 Likes