Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ai/vector-search-dotnet/Services/VectorSearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions ai/vector-search-go/src/diskann.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
6 changes: 6 additions & 0 deletions ai/vector-search-go/src/hnsw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
6 changes: 6 additions & 0 deletions ai/vector-search-go/src/ivf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion ai/vector-search-python/src/diskann.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
4 changes: 3 additions & 1 deletion ai/vector-search-python/src/hnsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
4 changes: 3 additions & 1 deletion ai/vector-search-python/src/ivf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
10 changes: 7 additions & 3 deletions ai/vector-search-typescript/src/diskann.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions ai/vector-search-typescript/src/hnsw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions ai/vector-search-typescript/src/ivf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}

Expand Down
Loading