
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A type-safe MongoDB implementation for Retrieval Augmented Generation with vector search
A type-safe MongoDB implementation for Retrieval Augmented Generation with vector search
MongoDB RAG is a semantic memory system for AI applications that provides persistent storage and retrieval of context-aware knowledge using MongoDB Atlas. It enables AI systems to remember past interactions, learn from them, and provide more personalized and context-aware responses over time.
This package implements a RAG (Retrieval Augmented Generation) system that:
Check out the Changelog to see what changed in the last releases.
npm install mongo-rag
bun add mongo-rag
Set up the required environment variables:
# MongoDB connection string
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/database
# Gemini API key for embeddings and fact extraction
GEMINI_API_KEY=your_gemini_api_key
import mongoose from 'mongoose'
// Connect to MongoDB
await mongoose.connect(process.env.MONGO_URI)
import { MongoRagClient } from 'mongo-rag'
const client = new MongoRagClient({
gemini_api_key: process.env.GEMINI_API_KEY,
})
// Add a simple memory string
const stringMemory = await client.add('User prefers vegetarian food', {
user_id: 'user123',
categories: ['preferences', 'food'],
})
// Add from chat messages
const messages = [
{ role: 'user', content: 'I like science fiction books' },
{ role: 'assistant', content: "I'll recommend sci-fi titles then!" },
]
const messageMemory = await client.add(messages, {
user_id: 'user123',
agent_id: 'books_agent',
categories: ['preferences', 'books'],
metadata: { genre: 'science fiction' },
})
// Add with expiration date
const temporaryMemory = await client.add(
'User is currently looking for a birthday gift',
{
user_id: 'user123',
// Memory expires in 7 days
expiration_date: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
}
)
// Semantic search
const searchResults = await client.search('What books does the user like?', {
user_id: 'user123',
})
// With filters
const filteredResults = await client.search('What food preferences?', {
user_id: 'user123',
categories: ['preferences'],
})
// Advanced filtering
const advancedResults = await client.search('User interests', {
filters: {
AND: [
{ user_id: 'user123' },
{
created_at: {
gte: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
},
},
],
},
})
// Get all memories for a user
const allMemories = await client.getAll({ user_id: 'user123' })
// Get memories by category
const foodMemories = await client.getAll({
user_id: 'user123',
categories: ['food'],
})
// With pagination
const paginatedMemories = await client.getAll({
user_id: 'user123',
page: 1,
page_size: 10,
})
The MongoRagClient provides these primary methods:
add(content, options): Add a new memorysearch(query, options): Find semantically similar memoriesgetAll(options): Retrieve memories with filters and paginationget(id): Get a specific memory by IDupdate(id, content, options): Update an existing memorydelete(id): Delete a specific memorydeleteAll(options): Delete memories matching criteriabatchUpdate(updates): Update multiple memories at oncebatchDelete(deletes): Delete multiple memories at onceSee the API Documentation for complete details.
# Clone the repository
git clone https://github.com/mguleryuz/mongo-rag.git
cd mongo-rag
# Install dependencies
bun i
# Set environment variables for testing
export MONGO_URI=mongodb+srv://...
export GEMINI_API_KEY=your_gemini_api_key
export NODE_ENV=test
# Run tests
bun test
bun watch
For the Maintainer: Add NPM_TOKEN to the GitHub Secrets.
git pullbun release: '' | alpha | beta optionally add -- --release-as minor | major | 0.0.1bun release:pubThis package is licensed - see the LICENSE file for details.
FAQs
A type-safe MongoDB implementation for Retrieval Augmented Generation with vector search
We found that mongo-rag demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.