UNPKG

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
#!/usr/bin/env node /** * 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();