File tree Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -118,14 +118,13 @@ async function setupRagCollection(db) {
118
118
*/
119
119
async function setVectorIndex ( collection , indexDefinition ) {
120
120
const existingIndexes = await collection . listSearchIndexes ( ) . toArray ( ) ;
121
- const vectorIndexExists = existingIndexes . some ( ( index ) => index . name === 'default' ) ;
122
121
const defaultIndex = existingIndexes . find ( ( index ) => index . name === 'default' ) ;
123
- if ( vectorIndexExists && defaultIndex ?. latestDefinition ?. mappings ?. fields ?. embedding ?. dimensions !== indexDefinition . mappings . fields . embedding . dimensions ) {
124
- await collection . updateSearchIndex ( 'default' , indexDefinition ) ;
125
- console . log ( `Updated vector search index for ${ collection . collectionName } with dimensions: ${ indexDefinition . mappings . fields . embedding . dimensions } .` ) ;
126
- } else {
122
+ if ( ! defaultIndex ) {
127
123
await collection . createSearchIndex ( { name : 'default' , definition : indexDefinition } ) ;
128
124
console . log ( `Created vector search index for ${ collection . collectionName } with dimensions: ${ indexDefinition . mappings . fields . embedding . dimensions } .` ) ;
125
+ } else if ( defaultIndex . latestDefinition ?. mappings ?. fields ?. embedding ?. dimensions !== indexDefinition . mappings . fields . embedding . dimensions ) {
126
+ await collection . updateSearchIndex ( 'default' , indexDefinition ) ;
127
+ console . log ( `Updated vector search index for ${ collection . collectionName } with dimensions: ${ indexDefinition . mappings . fields . embedding . dimensions } .` ) ;
129
128
}
130
129
}
131
130
You can’t perform that action at this time.
0 commit comments