diff --git a/ai/vector-search-dotnet/Services/VectorSearchService.cs b/ai/vector-search-dotnet/Services/VectorSearchService.cs index e8505a1..8aff7de 100644 --- a/ai/vector-search-dotnet/Services/VectorSearchService.cs +++ b/ai/vector-search-dotnet/Services/VectorSearchService.cs @@ -131,6 +131,10 @@ await _mongoService.CreateVectorIndexAsync( _logger.LogInformation($" {i + 1}. {hotelName} (Similarity: {result.Score:F4})"); } } + + // Drop the collection + await _mongoService.DropCollectionAsync(_config.VectorSearch.DatabaseName, collectionName); + _logger.LogInformation($"Dropped collection: {collectionName}"); } catch (Exception ex) { diff --git a/ai/vector-search-go/src/diskann.go b/ai/vector-search-go/src/diskann.go index 8991f58..003badf 100644 --- a/ai/vector-search-go/src/diskann.go +++ b/ai/vector-search-go/src/diskann.go @@ -227,5 +227,11 @@ func main() { // Display results PrintSearchResults(results, 5, true) + // Drop the collection + if err := collection.Drop(ctx); err != nil { + log.Printf("Warning: Failed to drop collection: %v", err) + } + fmt.Println("Dropped collection: hotels_diskann") + fmt.Println("\nDiskANN demonstration completed successfully!") } diff --git a/ai/vector-search-go/src/hnsw.go b/ai/vector-search-go/src/hnsw.go index ab6977c..bc5b485 100644 --- a/ai/vector-search-go/src/hnsw.go +++ b/ai/vector-search-go/src/hnsw.go @@ -230,5 +230,11 @@ func main() { // Display the search results PrintSearchResults(results, 5, true) + // Drop the collection + if err := collection.Drop(ctx); err != nil { + log.Printf("Warning: Failed to drop collection: %v", err) + } + fmt.Println("Dropped collection: hotels_hnsw") + fmt.Println("\nHNSW demonstration completed successfully!") } diff --git a/ai/vector-search-go/src/ivf.go b/ai/vector-search-go/src/ivf.go index 2aeddd8..4b019c4 100644 --- a/ai/vector-search-go/src/ivf.go +++ b/ai/vector-search-go/src/ivf.go @@ -227,5 +227,11 @@ func main() { // Display the search results PrintSearchResults(results, 5, true) + // Drop the collection + if err := collection.Drop(ctx); err != nil { + log.Printf("Warning: Failed to drop collection: %v", err) + } + fmt.Println("Dropped collection: hotels_ivf") + fmt.Println("\nIVF demonstration completed successfully!") } diff --git a/ai/vector-search-java/src/main/java/com/azure/documentdb/samples/DiskAnn.java b/ai/vector-search-java/src/main/java/com/azure/documentdb/samples/DiskAnn.java index 676630b..06fbf6b 100644 --- a/ai/vector-search-java/src/main/java/com/azure/documentdb/samples/DiskAnn.java +++ b/ai/vector-search-java/src/main/java/com/azure/documentdb/samples/DiskAnn.java @@ -66,6 +66,10 @@ public void run() { var queryEmbedding = createEmbedding(openAIClient, SAMPLE_QUERY); performVectorSearch(collection, queryEmbedding); + // Drop the collection + collection.drop(); + System.out.println("Dropped collection: " + COLLECTION_NAME); + } catch (Exception e) { System.err.println("Error: " + e.getMessage()); e.printStackTrace(); diff --git a/ai/vector-search-java/src/main/java/com/azure/documentdb/samples/HNSW.java b/ai/vector-search-java/src/main/java/com/azure/documentdb/samples/HNSW.java index 146fc27..499bd37 100644 --- a/ai/vector-search-java/src/main/java/com/azure/documentdb/samples/HNSW.java +++ b/ai/vector-search-java/src/main/java/com/azure/documentdb/samples/HNSW.java @@ -66,6 +66,10 @@ public void run() { var queryEmbedding = createEmbedding(openAIClient, SAMPLE_QUERY); performVectorSearch(collection, queryEmbedding); + // Drop the collection + collection.drop(); + System.out.println("Dropped collection: " + COLLECTION_NAME); + } catch (Exception e) { System.err.println("Error: " + e.getMessage()); e.printStackTrace(); diff --git a/ai/vector-search-java/src/main/java/com/azure/documentdb/samples/IVF.java b/ai/vector-search-java/src/main/java/com/azure/documentdb/samples/IVF.java index e800107..3996565 100644 --- a/ai/vector-search-java/src/main/java/com/azure/documentdb/samples/IVF.java +++ b/ai/vector-search-java/src/main/java/com/azure/documentdb/samples/IVF.java @@ -66,6 +66,10 @@ public void run() { var queryEmbedding = createEmbedding(openAIClient, SAMPLE_QUERY); performVectorSearch(collection, queryEmbedding); + // Drop the collection + collection.drop(); + System.out.println("Dropped collection: " + COLLECTION_NAME); + } catch (Exception e) { System.err.println("Error: " + e.getMessage()); e.printStackTrace(); diff --git a/ai/vector-search-python/src/diskann.py b/ai/vector-search-python/src/diskann.py index 81720ab..f511efa 100644 --- a/ai/vector-search-python/src/diskann.py +++ b/ai/vector-search-python/src/diskann.py @@ -200,8 +200,10 @@ def main(): raise finally: - # Close the MongoDB client + # Drop the collection and close connection if 'mongo_client' in locals(): + mongo_client[config['database_name']].drop_collection(config['collection_name']) + print(f"Dropped collection: {config['collection_name']}") mongo_client.close() diff --git a/ai/vector-search-python/src/hnsw.py b/ai/vector-search-python/src/hnsw.py index 9352220..175b59c 100644 --- a/ai/vector-search-python/src/hnsw.py +++ b/ai/vector-search-python/src/hnsw.py @@ -196,8 +196,10 @@ def main(): raise finally: - # Clean up MongoDB connection + # Drop the collection and close connection if 'mongo_client' in locals(): + mongo_client[config['database_name']].drop_collection(config['collection_name']) + print(f"Dropped collection: {config['collection_name']}") mongo_client.close() diff --git a/ai/vector-search-python/src/ivf.py b/ai/vector-search-python/src/ivf.py index f39c0d2..9773a86 100644 --- a/ai/vector-search-python/src/ivf.py +++ b/ai/vector-search-python/src/ivf.py @@ -191,8 +191,10 @@ def main(): raise finally: - # Ensure MongoDB connection is properly closed + # Drop the collection and close connection if 'mongo_client' in locals(): + mongo_client[config['database_name']].drop_collection(config['collection_name']) + print(f"Dropped collection: {config['collection_name']}") mongo_client.close() diff --git a/ai/vector-search-typescript/src/diskann.ts b/ai/vector-search-typescript/src/diskann.ts index 96b547c..60a4b9d 100644 --- a/ai/vector-search-typescript/src/diskann.ts +++ b/ai/vector-search-typescript/src/diskann.ts @@ -95,9 +95,13 @@ async function main() { console.error('App failed:', error); process.exitCode = 1; } finally { - console.log('Closing database connection...'); - if (dbClient) await dbClient.close(); - console.log('Database connection closed'); + if (dbClient) { + const db = dbClient.db(config.dbName); + await db.dropCollection(config.collectionName); + console.log('Dropped collection:', config.collectionName); + await dbClient.close(); + console.log('Database connection closed'); + } } } diff --git a/ai/vector-search-typescript/src/hnsw.ts b/ai/vector-search-typescript/src/hnsw.ts index 771146c..6cda349 100644 --- a/ai/vector-search-typescript/src/hnsw.ts +++ b/ai/vector-search-typescript/src/hnsw.ts @@ -95,9 +95,13 @@ async function main() { console.error('App failed:', error); process.exitCode = 1; } finally { - console.log('Closing database connection...'); - if (dbClient) await dbClient.close(); - console.log('Database connection closed'); + if (dbClient) { + const db = dbClient.db(config.dbName); + await db.dropCollection(config.collectionName); + console.log('Dropped collection:', config.collectionName); + await dbClient.close(); + console.log('Database connection closed'); + } } } diff --git a/ai/vector-search-typescript/src/ivf.ts b/ai/vector-search-typescript/src/ivf.ts index e81ace8..b13f122 100644 --- a/ai/vector-search-typescript/src/ivf.ts +++ b/ai/vector-search-typescript/src/ivf.ts @@ -96,9 +96,13 @@ async function main() { console.error('App failed:', error); process.exitCode = 1; } finally { - console.log('Closing database connection...'); - if (dbClient) await dbClient.close(); - console.log('Database connection closed'); + if (dbClient) { + const db = dbClient.db(config.dbName); + await db.dropCollection(config.collectionName); + console.log('Dropped collection:', config.collectionName); + await dbClient.close(); + console.log('Database connection closed'); + } } }