@@ -114,9 +114,9 @@ def main():
114114
115115 # Load configuration from environment variables
116116 config = {
117- 'cluster_name' : os .getenv ('MONGO_CLUSTER_NAME' , 'vectorSearch' ),
118- 'database_name' : 'vectorSearchDB ' ,
119- 'collection_name' : 'vectorSearchCollection ' ,
117+ 'cluster_name' : os .getenv ('MONGO_CLUSTER_NAME' ),
118+ 'database_name' : 'Hotels ' ,
119+ 'collection_name' : 'hotels_ivf ' ,
120120 'data_file' : os .getenv ('DATA_FILE_WITH_VECTORS' , 'data/Hotels_Vector.json' ),
121121 'vector_field' : os .getenv ('EMBEDDED_FIELD' , 'DescriptionVector' ),
122122 'model_name' : os .getenv ('AZURE_OPENAI_EMBEDDING_MODEL' , 'text-embedding-3-small' ),
@@ -147,32 +147,29 @@ def main():
147147 # Prepare collection with fresh data
148148 print (f"\n Preparing collection '{ config ['collection_name' ]} '..." )
149149
150- # Remove any existing data for clean state
151- collection .delete_many ({})
152- print ("Cleared existing data from collection" )
153-
154150 # Insert hotel data with embeddings
155151 stats = insert_data (
156152 collection ,
157153 documents_with_embeddings ,
158154 batch_size = config ['batch_size' ]
159155 )
160156
161- if stats ['inserted' ] == 0 :
157+ if stats ['inserted' ] == 0 and not stats . get ( 'skipped' ) :
162158 raise ValueError ("No documents were inserted successfully" )
163159
164- # Create IVF vector index for clustering-based search
165- print ("\n Creating IVF vector index..." )
166- create_ivf_vector_index (
167- collection ,
168- config ['vector_field' ],
169- config ['dimensions' ]
170- )
171-
172- # Wait for index to be built and ready
173- import time
174- print ("Waiting for index clustering to complete..." )
175- time .sleep (3 ) # IVF may need more time for clustering
160+ # Create IVF vector index (skip if data was already present)
161+ if not stats .get ('skipped' ):
162+ print ("\n Creating IVF vector index..." )
163+ create_ivf_vector_index (
164+ collection ,
165+ config ['vector_field' ],
166+ config ['dimensions' ]
167+ )
168+
169+ # Wait for index to be built and ready
170+ import time
171+ print ("Waiting for index clustering to complete..." )
172+ time .sleep (3 ) # IVF may need more time for clustering
176173
177174 # Demonstrate IVF search
178175 query = "quintessential lodging near running trails, eateries, retail"
0 commit comments