Registry / ai-ml / mongodb-rag

mongodb-rag

JSON →
library0.83.0jsnpmunverified

MongoDB RAG v0.83.0 is a JavaScript/TypeScript library that simplifies Retrieval Augmented Generation (RAG) using MongoDB Atlas Vector Search. It provides vector search, batch processing, index management, in-memory caching, and advanced chunking strategies (sliding window, semantic, recursive). Includes a CLI for scaffolding RAG apps and configuration. Released under Apache-2.0, updated regularly with minor releases every few weeks. Key differentiator: tight integration with MongoDB Atlas, built-in chunking, and CLI tooling compared to generic vector search libraries.

npm install mongodb-rag
INSTALL
IMPORT
SIG · MONGODB-RAG
M
mongodb-rag
ai-mljavascriptv0.83.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MongoRAG
import { MongoRAG } from 'mongodb-rag'
import MongoRAG from 'mongodb-rag'
MongoRAG is a named export, not default. Use named import syntax.
ChunkingStrategy
import { ChunkingStrategy } from 'mongodb-rag'
const ChunkingStrategy = require('mongodb-rag').ChunkingStrategy
CommonJS require works but TypeScript/ESM prefer named import.

Shows environment setup, MongoRAG initialization with OpenAI embeddings, document ingestion, and vector search query.

import { MongoRAG } from 'mongodb-rag'; import dotenv from 'dotenv'; dotenv.config(); const rag = new MongoRAG({ mongoUrl: process.env.MONGODB_URI ?? 'mongodb://localhost:27017', database: 'my_rag_db', collection: 'documents', embedding: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY ?? '', model: 'text-embedding-3-small', dimensions: 1536 } }); async function main() { // Ingest documents const docs = [ { title: 'MongoDB Atlas', content: 'A fully managed cloud database for modern applications.' }, { title: 'Vector Search', content: 'Enables semantic similarity search on vector embeddings.' } ]; await rag.ingest(docs); // Query const results = await rag.search({ query: 'cloud database', topK: 3 }); console.log(results); } main().catch(console.error);
Debug
Known issues
gotchaEmbedding provider 'openai' requires a valid API key. The library does not validate the key until runtime.
fix
Ensure process.env.OPENAI_API_KEY is set before instantiating MongoRAG.
affects: >=0.0.0
gotchaThe default collection 'documents' must exist or be created with the correct vector index. MongoRAG does not auto-create indexes.
fix
Use npx mongodb-rag create-index to set up the required vector index.
affects: >=0.0.0
deprecatedThe 'provider' field in embedding config is case-sensitive. 'openai' works but 'OpenAI' does not.
fix
Use lowercase provider names: 'openai', 'ollama', 'huggingface', etc.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'mongodb-rag'
Package not installed or not in node_modules.
fix
Run 'npm install mongodb-rag' in your project directory.
TypeError: MongoRAG is not a constructor
Incorrect import: imported default instead of named export.
fix
Change 'import MongoRAG from...' to 'import { MongoRAG } from...'
Upgrade
Version history
0.83.0latest on npm
Audit
Dependencies
mongodbrequiredRequired to connect to MongoDB Atlas for storing embeddings and documents.
dotenvoptionalCommonly used for loading environment variables; CLI generates .env files.
Agent activity
11 hits · last 30 days
node
10
Resources
mongodb-rag — npm install mongodb-rag · libregistry