@@ -35,19 +35,42 @@ export async function createIndex(config) {
3535
3636 console . log ( chalk . blue ( `📌 Creating Vector Search Index: ${ config . indexName } ...` ) ) ;
3737
38+ import chalk from 'chalk' ;
39+ import { getMongoClient } from '../../utils/mongodb.js' ;
40+ import { isConfigValid } from '../../utils/validation.js' ;
41+
42+ export async function createIndex ( config ) {
43+ console . log ( chalk . blue ( `🔍 Debug: Checking config...` ) , config ) ;
44+
45+ try {
46+ console . log ( chalk . blue ( `🔍 Debug: Connecting to MongoDB at ${ config . mongoUrl } ` ) ) ;
47+ const client = await getMongoClient ( config . mongoUrl ) ;
48+ console . log ( chalk . green ( `✅ Debug: client obtained: Yes` ) ) ;
49+
50+ const db = client . db ( config . database ) ;
51+ const collection = db . collection ( config . collection ) ;
52+
53+ console . log ( chalk . blue ( `📂 Database: ${ config . database } ` ) ) ;
54+ console . log ( chalk . blue ( `📑 Collection: ${ config . collection } ` ) ) ;
55+
56+ if ( ! config || ! config . embedding || ! config . embedding . dimensions ) {
57+ console . error ( chalk . red ( "❌ MongoDB Error: Missing embedding dimensions in config." ) ) ;
58+ throw new Error ( "Missing embedding dimensions in config." ) ;
59+ }
60+
61+ console . log ( chalk . blue ( `📌 Creating Vector Search Index: ${ config . indexName } ...` ) ) ;
62+
63+ // Updated index configuration to match MongoDB Vector Search syntax
3864 const indexConfig = {
3965 name : config . indexName || "vector_index" ,
66+ type : "vectorSearch" ,
4067 definition : {
41- mappings : {
42- dynamic : false , // More restrictive than true, better for vector search
43- fields : {
44- [ config . embedding . path || "embedding" ] : {
45- type : "knnVector" ,
46- dimensions : config . embedding . dimensions ,
47- similarity : config . embedding . similarity || "cosine"
48- }
49- }
50- }
68+ fields : [ {
69+ type : "vector" ,
70+ path : config . embedding . path || "embedding" ,
71+ numDimensions : config . embedding . dimensions ,
72+ similarity : config . embedding . similarity || "cosine"
73+ } ]
5174 }
5275 } ;
5376
0 commit comments