{"id":40019657,"url":"https://github.com/mongodb-developer/mongodb-rag","last_synced_at":"2026-01-19T03:08:16.682Z","repository":{"id":276998283,"uuid":"930927237","full_name":"mongodb-developer/mongodb-rag","owner":"mongodb-developer","description":"A Powerful Retrieval Augmented Generation Tool for MongoDB Vector Search","archived":false,"fork":false,"pushed_at":"2025-03-12T15:18:05.000Z","size":15582,"stargazers_count":8,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-22T14:22:49.751Z","etag":null,"topics":["ai","cli","javascript","mongodb","retrieval-augmented-generation"],"latest_commit_sha":null,"homepage":"https://mongodb-developer.github.io/mongodb-rag/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mongodb-developer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-11T12:49:35.000Z","updated_at":"2025-07-25T21:26:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"efc5f737-3df6-42a1-a66a-8b28ecc1a5d4","html_url":"https://github.com/mongodb-developer/mongodb-rag","commit_stats":null,"previous_names":["mongodb-developer/mongodb-rag"],"tags_count":79,"template":false,"template_full_name":null,"purl":"pkg:github/mongodb-developer/mongodb-rag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fmongodb-rag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fmongodb-rag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fmongodb-rag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fmongodb-rag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mongodb-developer","download_url":"https://codeload.github.com/mongodb-developer/mongodb-rag/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fmongodb-rag/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28559383,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T00:46:33.223Z","status":"online","status_checked_at":"2026-01-19T02:00:08.049Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","cli","javascript","mongodb","retrieval-augmented-generation"],"created_at":"2026-01-19T03:08:16.620Z","updated_at":"2026-01-19T03:08:16.676Z","avatar_url":"https://github.com/mongodb-developer.png","language":"JavaScript","readme":"---\n\n![MongoDB RAG Logo](static/mongodb-rag-logo.png)\n\n# MongoDB-RAG\n\n![NPM Version](https://img.shields.io/npm/v/mongodb-rag?color=blue\u0026label=npm)\n![License](https://img.shields.io/github/license/mongodb-developer/mongodb-rag)\n![Issues](https://img.shields.io/github/issues/mongodb-developer/mongodb-rag)\n![Pull Requests](https://img.shields.io/github/issues-pr/mongodb-developer/mongodb-rag)\n![Downloads](https://img.shields.io/npm/dt/mongodb-rag)\n![MongoDB-RAG](https://img.shields.io/badge/MongoDB--RAG-Enabled-brightgreen?style=flat\u0026logo=https://raw.githubusercontent.com/mongodb-developer/mongodb-rag/main/static/logo-square.png)\n\n## Overview\nMongoDB-RAG (Retrieval Augmented Generation) is an NPM module that simplifies vector search using MongoDB Atlas. This library enables developers to efficiently perform similarity search, caching, batch processing, and indexing for fast and accurate retrieval of relevant data.\n\n## 🚀 Features\n- **Vector Search**: Efficiently retrieves similar documents using MongoDB's Atlas Vector Search.\n- **Dynamic Database \u0026 Collection Selection**: Supports flexible selection of multiple databases and collections.\n- **Batch Processing**: Handles bulk processing of documents with retry mechanisms.\n- **Index Management**: Ensures necessary indexes are available and optimized.\n- **Caching Mechanism**: Provides in-memory caching for frequently accessed data.\n- **Advanced Chunking**: Supports **sliding window**, **semantic**, and **recursive** chunking strategies.\n- **CLI for Scaffolding RAG Apps**\n\n---\n\n## **🚀 Getting Started**\n\n### **1️⃣ Install the Package**\n```sh\nnpm install mongodb-rag dotenv\n```\n\n### **2️⃣ Set Up MongoDB Atlas**\n1. **Initialize Your App** using the CLI:\n   ```sh\n   npx mongodb-rag init\n   ```\n   This will guide you through setting up your MongoDB connection and save the configuration to `.mongodb-rag.json`. Make sure to add `.mongodb-rag.json` to your `.gitignore` file to keep your credentials secure.\n\n```bash\n   % npx mongodb-rag init\n✔ Enter your MongoDB connection string: · mongodb+srv://\u003cusername\u003e:\u003cpassword\u003e@cluster0.mongodb.net/\n✔ Enter the database name: · mongodb-rag\n✔ Enter the collection name: · documents\n✔ Select an embedding provider: · openai\n✔ Enter your API key (skip if using Ollama): · your-embedding-api-key\n✔ Enter the model name: · text-embedding-3-small\n✔ Enter the embedding dimensions: · 1536\n✅ Configuration saved to .mongodb-rag.json\n\n🔍 Next steps:\n1. Run `npx mongodb-rag test-connection` to verify your setup\n2. Run `npx mongodb-rag create-index` to create your vector search index\n```\n\n2. **Create a MongoDB Atlas Cluster** ([MongoDB Atlas](https://www.mongodb.com/atlas))\n\n3. **Enable Vector Search** under Indexes:\n   ```json\n   {\n     \"definition\": {\n       \"fields\": [\n         { \"path\": \"embedding\", \"type\": \"vector\", \"numDimensions\": 1536, \"similarity\": \"cosine\" }\n       ]\n     }\n   }\n   ```\nor, use the CLI to create the index:\n   ```sh\n   npx mongodb-rag create-index\n   ```\n4. **Create a `.env` File** using:\n   ```sh\n   npx mongodb-rag create-env\n   ```\n   This command reads the `.mongodb-rag.json` file and generates a `.env` file with the necessary environment variables.\n\n### **3️⃣ Quick Start with CLI**\nYou can generate a fully working RAG-enabled app with **MongoDB Atlas Vector Search** using:\n\n```sh\nnpx mongodb-rag create-rag-app my-rag-app\n```\n\nThis will:\n- Scaffold a new **CRUD RAG app** with Express and MongoDB Atlas.\n- Set up **environment variables** for **embedding providers**.\n- Create API routes for **ingestion, search, and deletion**.\n\nThen, navigate into your project and run:\n\n```sh\ncd my-rag-app\nnpm install\nnpm run dev\n```\n\n### **4️⃣ Initialize MongoRAG**\n```javascript\nimport { MongoRAG } from 'mongodb-rag';\nimport dotenv from 'dotenv';\ndotenv.config();\n\nconst rag = new MongoRAG({\n    mongoUrl: process.env.MONGODB_URI,\n    database: 'my_rag_db',  // Default database\n    collection: 'documents', // Default collection\n    embedding: {\n        provider: process.env.EMBEDDING_PROVIDER,\n        apiKey: process.env.EMBEDDING_API_KEY,\n        model: process.env.EMBEDDING_MODEL,\n        dimensions: 1536\n    }\n});\nawait rag.connect();\n```\n\n### **5️⃣ Ingest Documents**\n```javascript\nconst documents = [\n    { id: 'doc1', content: 'MongoDB is a NoSQL database.', metadata: { source: 'docs' } },\n    { id: 'doc2', content: 'Vector search is useful for semantic search.', metadata: { source: 'ai' } }\n];\n\nawait rag.ingestBatch(documents, { database: 'dynamic_db', collection: 'dynamic_docs' });\nconsole.log('Documents ingested.');\n```\n\n### **6️⃣ Perform a Vector Search**\n```javascript\nconst query = 'How does vector search work?';\n\nconst results = await rag.search(query, {\n    database: 'dynamic_db',\n    collection: 'dynamic_docs',\n    maxResults: 3\n});\n\nconsole.log('Search Results:', results);\n```\n\n### **7️⃣ Close Connection**\n```javascript\nawait rag.close();\n```\n\n---\n\n## **⚡ Additional Features**\n\n### **🌍 Multi-Database \u0026 Collection Support**\nStore embeddings in multiple **databases and collections** dynamically.\n```javascript\nawait rag.ingestBatch(docs, { database: 'finance_db', collection: 'reports' });\n```\n\n### **🔎 Hybrid Search (Vector + Metadata Filtering)**\n```javascript\nconst results = await rag.search('AI topics', {\n    database: 'my_rag_db',\n    collection: 'documents',\n    maxResults: 5,\n    filter: { 'metadata.source': 'ai' }\n});\n```\n\n---\n\n## **🤝 Contributing**\nContributions are welcome! Please fork the repository and submit a pull request.\n\n---\n\n## **📜 License**\nThis project is licensed under the MIT License.\n\n## **💡 Examples**\n\n- For more examples, check our [examples directory](https://github.com/mongodb-developer/mongodb-rag/tree/main/examples).\n    \n\n## 🔗 Links\n\n- CLI Reference\n- [Documentation](https://mongodb-developer.github.io/mongodb-rag/)\n- [GitHub Repository](https://github.com/mongodb-developer/mongodb-rag)\n- [Bug Reports](https://github.com/mongodb-developer/mongodb-rag/issues)\n- [MongoDB Atlas](https://www.mongodb.com/cloud/atlas)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-developer%2Fmongodb-rag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmongodb-developer%2Fmongodb-rag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-developer%2Fmongodb-rag/lists"}