AzureDocumentDB: CosineDistance returns similarity scores, and ScoreThreshold filters the wrong way
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- azure, csharp, docker, mongodb
- 領域
- databases, testing-qa
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C#
- スター
- 10
- フォーク
- 8
- 平均マージ
- 1日 7時間
- マージ済み PR(30日)
- 9
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
CommunityToolkit/AI のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
CommunityToolkit/AI#19 ·
メンテナーはふだん 1 日以内に返信
-
Add the Milvus provider (CommunityToolkit.VectorData.Milvus)対応中かも @Overvolted が今日担当しました。 オープンenhancement
難易度 4/5 3〜5日 初心者へのやさしさ 56/100
CommunityToolkit/AI#76 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 66/100
CommunityToolkit/AI#74 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 57/100
CommunityToolkit/AI#73 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
CommunityToolkit/AI#61 ·
メンテナーはふだん 1 日以内に返信
CommunityToolkit/AI の issue をすべて見る
似ている issue
-
area-multitenancy area-security p1-recommended priority-high technical-debt
難易度 2/5 1時間未満 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
kind/enhancement Provider Upgrade pulumi/pulumi-azure R1 Task
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
pulumi/pulumi-azure#3669 ·
-
type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
webclient does not start対応中かも @PawelTroka が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
PawelTroka/Computator.NET#257 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
eriknihlen/OpenAC#255 ·
メンテナーはふだん 1 日以内に返信