Skip to content

Commit

Permalink
- VectorSearchTests update
Browse files Browse the repository at this point in the history
- Rebase
  • Loading branch information
BorisDog committed Jan 27, 2025
1 parent cd2e772 commit 1243134
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public AtlasSearchTests(ITestOutputHelper testOutputHelper) : base(testOutputHel
var atlasSearchUri = Environment.GetEnvironmentVariable("ATLAS_SEARCH");
Ensure.IsNotNullOrEmpty(atlasSearchUri, nameof(atlasSearchUri));

var mongoClientSettings = MongoClientSettings.FromConnectionString(atlasSearchUri);
mongoClientSettings.ClusterSource = DisposingClusterSource.Instance;

_mongoClient = new MongoClient(atlasSearchUri);
}

Expand Down
13 changes: 10 additions & 3 deletions tests/MongoDB.Driver.Tests/Search/VectorSearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,29 @@ public VectorSearchTests(ITestOutputHelper testOutputHelper) : base(testOutputHe
var atlasSearchUri = Environment.GetEnvironmentVariable("ATLAS_SEARCH");
Ensure.IsNotNullOrEmpty(atlasSearchUri, nameof(atlasSearchUri));

var mongoClientSettings = MongoClientSettings.FromConnectionString(atlasSearchUri);
mongoClientSettings.ClusterSource = DisposingClusterSource.Instance;

_mongoClient = new MongoClient(atlasSearchUri);
}

protected override void DisposeInternal() => _mongoClient.Dispose();

[Theory(Skip = "Shared BsonVector cluster not set. TODO BEFORE MERGE")]
[Theory]
[MemberData(nameof(BsonVectorSearchTestData))]
public void BsonVectorSearch<T>(BsonVectorBase<T> bsonVector, string fieldName)
where T : struct
{
const int Limit = 5;
var collection = _mongoClient.GetDatabase("vectorSearch").GetCollection<BsonVectorSearchItem>("BinaryVectorTests");
var collection = _mongoClient.GetDatabase("csharpExtraTests").GetCollection<BsonVectorSearchItem>("binaryVectorTests");

var options = new VectorSearchOptions<BsonVectorSearchItem>() { IndexName = "vector_search_index" };

var result = collection.Aggregate().VectorSearch(fieldName, bsonVector.ToQueryVector(), Limit).ToList();
var result = collection
.Aggregate()
.VectorSearch(fieldName, bsonVector.ToQueryVector(), Limit, options)
.Project<BsonVectorSearchItem>(Builders<BsonVectorSearchItem>.Projection.MetaVectorSearchScore(p => p.Score))
.ToList();

result.Count.Should().Be(Limit);
result.Should().BeInDescendingOrder(b => b.Score);
Expand Down

0 comments on commit 1243134

Please sign in to comment.