AzureDocumentDB: CosineDistance returns similarity scores, and ScoreThreshold filters the wrong way
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- azure, csharp, docker, mongodb
- Lĩnh vực
- databases, testing-qa
Hướng nghiên cứu
Read MEVD/src/AzureDocumentDB/DocumentDBCollectionCreateMapping.cs, MEVD/src/AzureDocumentDB/DocumentDBCollectionSearchMapping.cs, and MEVD/src/AzureDocumentDB/DocumentDBCollection.cs to compare the provider’s cosine score and threshold semantics with InMemory. Run the supplied dotnet run repro.cs, then inspect MEVD/test/AzureDocumentDB.ConformanceTests/DocumentDBDistanceFunctionTests.cs for the current score assertions. Completion requires agreeing whether to normalize similarity into distance, adjusting the threshold comparison, and updating conformance coverage without silently changing existing behavior.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
With CosineDistance, the default, AzureDocumentDB returns the cosine similarity as Score, and ScoreThreshold keeps scores >= the threshold. InMemory returns the distance and keeps scores <= it.
Repro: with Docker running, dotnet run repro.cs.
#:package [email protected]
#:package [email protected]
#:package [email protected]
#:property PublishAot=false
using System.Security.Authentication;
using CommunityToolkit.VectorData.AzureDocumentDB;
using CommunityToolkit.VectorData.InMemory;
using DotNet.Testcontainers.Builders;
using Microsoft.Extensions.VectorData;
using MongoDB.Driver;
// Starts DocumentDB local in Docker, then compares InMemory and AzureDocumentDB with CosineDistance.
await using var container = new ContainerBuilder("ghcr.io/microsoft/documentdb/documentdb-local:latest")
.WithEnvironment("USERNAME", "user")
.WithEnvironment("PASSWORD", "Pass123!")
.WithPortBinding(10260, true)
.WithWaitStrategy(Wait.ForUnixContainer().UntilInternalTcpPortIsAvailable(10260))
.Build();
await container.StartAsync();
var settings = MongoClientSettings.FromConnectionString($"mongodb://user:Pass123!@{container.Hostname}:{container.GetMappedPublicPort(10260)}/?tls=true");
settings.SslSettings = new SslSettings { EnabledSslProtocols = SslProtocols.Tls12, ServerCertificateValidationCallback = (_, _, _, _) => true };
var documentDb = new DocumentDBVectorStore(new MongoClient(settings).GetDatabase("repro"));
var inMemory = new InMemoryVectorStore();
Hotel[] hotels =
[
new() { Id = "same", Vector = new float[] { 1, 0, 0 } },
new() { Id = "orthogonal", Vector = new float[] { 0, 1, 0 } },
new() { Id = "opposite", Vector = new float[] { -1, 0, 0 } },
];
ReadOnlyMemory<float> query = new float[] { 1, 0, 0 };
foreach (var (name, store) in new (string, VectorStore)[] { ("InMemory", inMemory), ("DocumentDB", documentDb) })
{
var collection = store.GetCollection<string, Hotel>("hotels");
await collection.EnsureCollectionDeletedAsync();
await collection.EnsureCollectionExistsAsync();
await collection.UpsertAsync(hotels);
await Task.Delay(1000);
Console.WriteLine($"{name} CosineDistance");
await foreach (var r in collection.SearchAsync(query, 3))
Console.WriteLine($" {r.Record.Id,-10} score {r.Score:0.##}");
var within = await collection.SearchAsync(query, 3, new() { ScoreThreshold = 1.5 }).Select(r => r.Record.Id).ToListAsync();
Console.WriteLine($" ScoreThreshold = 1.5 -> [{string.Join(", ", within)}]");
}
public sealed class Hotel
{
[VectorStoreKey] public string Id { get; set; } = "";
[VectorStoreVector(3, DistanceFunction = DistanceFunction.CosineDistance)] public ReadOnlyMemory<float> Vector { get; set; }
}
InMemory CosineDistance
same score 0
orthogonal score 1
opposite score 2
ScoreThreshold = 1.5 -> [same, orthogonal]
DocumentDB CosineDistance
same score 1
orthogonal score 0
opposite score -1
ScoreThreshold = 1.5 -> []
Cause:
CosineDistancemaps toCOS(DocumentDBCollectionCreateMapping.cs#L123), which returns a similarity.- The threshold uses
$gte(DocumentDBCollectionSearchMapping.cs#L98-L110). - The score is returned as is (DocumentDBCollection.cs#L575-L578).
AssertScores = falsein the conformance tests hides it (DocumentDBDistanceFunctionTests.cs#L24).
Returning 1 - similarity and filtering with $lte would match the other providers, but it changes the scores existing users get. Which way do you prefer? I can send the PR.
- Ngôn ngữ chính
- C#
- Star
- 10
- Fork
- 8
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 10
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của CommunityToolkit/AI
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
CommunityToolkit/AI#19 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 66/100
CommunityToolkit/AI#74 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 57/100
CommunityToolkit/AI#73 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
CommunityToolkit/AI#61 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
CommunityToolkit/AI#59 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của CommunityToolkit/AI
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
KnifeLemon/Filee#363 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[CI] .trgen-ignore required for several grammars.Có thể đã có người làm @kaby76 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
antlr/grammars-v4#5073 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
/api/oauth/introspect emits clientId and tokenType instead of RFC 7662's client_id and token_typeĐang mởbug P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nightscout/nocturne#2317 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG]: Position intent set on a simple order is dropped when it becomes a bracket, OCO or OTO orderCó thể đã có người làm @RaphaelFakhri đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
alpacahq/alpaca-trade-api-csharp#903 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
joinrpg/joinrpg-net#5752 ·
Maintainer thường phản hồi trong vòng 1 ngày