@@ -488,7 +488,7 @@ program
488488
489489 program
490490 . command ( 'show-indexes' )
491- . description ( 'Display all indexes for the configured MongoDB collection' )
491+ . description ( 'Display all Vector Search indexes for the configured MongoDB collection' )
492492 . action ( async ( ) => {
493493 if ( ! isConfigValid ( config ) ) {
494494 console . error ( chalk . red ( "❌ Configuration missing. Run 'npx mongodb-rag init' first." ) ) ;
@@ -503,20 +503,49 @@ program
503503 try {
504504 const collection = client . db ( config . database ) . collection ( config . collection ) ;
505505
506- // Use the indexes() method to get all indexes
507- const indexes = await collection . indexes ( ) ;
506+ // Use $listSearchIndexes aggregation stage to get vector search indexes
507+ const searchIndexes = await collection . aggregate ( [
508+ { $listSearchIndexes : { } }
509+ ] ) . toArray ( ) ;
510+
511+ // Get regular indexes as well for completeness
512+ const regularIndexes = await collection . indexes ( ) ;
508513
509- if ( indexes . length === 0 ) {
514+ if ( searchIndexes . length === 0 && regularIndexes . length === 0 ) {
510515 console . log ( chalk . yellow ( "⚠️ No indexes found in this collection." ) ) ;
511- } else {
512- console . log ( chalk . bold ( "\n📄 List of Indexes:" ) ) ;
513- indexes . forEach ( ( index , i ) => {
516+ return ;
517+ }
518+
519+ // Display Vector Search Indexes
520+ if ( searchIndexes . length > 0 ) {
521+ console . log ( chalk . bold ( "\n🔍 Vector Search Indexes:" ) ) ;
522+ searchIndexes . forEach ( ( index , i ) => {
514523 console . log ( chalk . green ( `${ i + 1 } . 🔹 Index Name: ${ index . name } ` ) ) ;
515- console . log ( ` 📌 Type: ${ chalk . magenta ( index . type || 'Standard' ) } ` ) ;
524+ console . log ( ` 📌 Type: ${ chalk . magenta ( 'Vector Search' ) } ` ) ;
525+ console . log ( ` 🎯 Definition: ${ chalk . yellow ( JSON . stringify ( index . definition , null , 2 ) ) } ` ) ;
526+ if ( index . queryable ) {
527+ console . log ( ` ✅ Status: ${ chalk . green ( 'Queryable' ) } ` ) ;
528+ } else {
529+ console . log ( ` ⚠️ Status: ${ chalk . yellow ( 'Building' ) } ` ) ;
530+ }
531+ console . log ( chalk . gray ( "---------------------------------------------------" ) ) ;
532+ } ) ;
533+ }
534+
535+ // Display Regular Indexes
536+ if ( regularIndexes . length > 0 ) {
537+ console . log ( chalk . bold ( "\n📄 Regular Indexes:" ) ) ;
538+ regularIndexes . forEach ( ( index , i ) => {
539+ // Skip _id_ index as it's created by default
540+ if ( index . name === '_id_' ) return ;
541+
542+ console . log ( chalk . green ( `${ i + 1 } . 🔹 Index Name: ${ index . name } ` ) ) ;
543+ console . log ( ` 📌 Type: ${ chalk . magenta ( 'Standard' ) } ` ) ;
516544 console . log ( ` 🔍 Fields: ${ chalk . yellow ( JSON . stringify ( index . key , null , 2 ) ) } ` ) ;
517545 console . log ( chalk . gray ( "---------------------------------------------------" ) ) ;
518546 } ) ;
519547 }
548+
520549 } catch ( error ) {
521550 console . error ( chalk . red ( "❌ Error retrieving indexes:" ) , error . message ) ;
522551 process . exit ( 1 ) ;
0 commit comments