memory-engineering-mcp
Version:
š§ AI Memory System powered by MongoDB Atlas & Voyage AI - Autonomous memory management with zero manual work
112 lines (91 loc) ⢠3.79 kB
JavaScript
/**
* Create Atlas Search Indexes for Memory Engineering MCP
* This creates the vector search and text search indexes in MongoDB Atlas
*/
import { MongoClient } from 'mongodb';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb+srv://rom:05101994@mongovibe.mmzhvvr.mongodb.net/memory_engineering?retryWrites=true&w=majority&appName=mongovibe';
async function createAtlasSearchIndexes() {
const client = new MongoClient(MONGODB_URI);
try {
console.log('š Connecting to MongoDB Atlas...');
await client.connect();
console.log('ā
Connected to Atlas!\n');
const db = client.db();
// Read index definitions
const indexDefinitions = JSON.parse(
readFileSync(join(__dirname, 'atlas-search-indexes.json'), 'utf-8')
);
console.log('š Creating Atlas Search Indexes...\n');
// Create indexes for memory_engineering_documents collection
const docsCollection = db.collection('memory_engineering_documents');
for (const indexDef of indexDefinitions) {
try {
console.log(`ā” Creating index: ${indexDef.name} (type: ${indexDef.type})...`);
await docsCollection.createSearchIndex({
name: indexDef.name,
type: indexDef.type,
definition: indexDef.definition
});
console.log(`ā
Created index: ${indexDef.name}`);
} catch (error) {
if (error.codeName === 'IndexAlreadyExists' || error.code === 68) {
console.log(`ā Index already exists: ${indexDef.name}`);
} else {
console.error(`ā Error creating ${indexDef.name}:`, error.message);
}
}
}
// Now create code collection vector index
console.log('\nš Creating code collection vector index...\n');
const codeCollection = db.collection('memory_engineering_code');
try {
await codeCollection.createSearchIndex({
name: 'code_vectors',
type: 'vectorSearch',
definition: {
fields: [
{
type: 'vector',
path: 'contentVector',
numDimensions: 1024,
similarity: 'cosine'
},
{
type: 'filter',
path: 'projectId'
}
]
}
});
console.log('ā
Created code_vectors index');
} catch (error) {
if (error.codeName === 'IndexAlreadyExists' || error.code === 68) {
console.log('ā Index already exists: code_vectors');
} else {
console.error('ā Error creating code_vectors:', error.message);
}
}
console.log('\nš Atlas Search indexes created!');
console.log('\nā ļø IMPORTANT: It may take 1-2 minutes for Atlas to finish building these indexes.');
console.log('š Check the Atlas UI to see when indexes are "Active"');
console.log('\nš Next steps:');
console.log(' 1. Wait for indexes to become "Active" in Atlas UI');
console.log(' 2. Try vector search: memory_engineering_search --query "MongoDB" --codeSearch "similar"');
console.log(' 3. Enjoy semantic search! š');
} catch (error) {
console.error('\nā Error:', error.message);
console.error('\nš” Note: Creating search indexes requires Atlas M10+ cluster or higher.');
console.error(' Free tier (M0) does not support Atlas Search vector indexes.');
process.exit(1);
} finally {
await client.close();
console.log('\nš Disconnected from Atlas');
}
}
createAtlasSearchIndexes();