AzureDocumentDB: CosineDistance returns similarity scores, and ScoreThreshold filters the wrong way
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- azure, csharp, docker, mongodb
- Área
- databases, testing-qa
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- C#
- Estrellas
- 8
- Forks
- 8
- Merge medio
- 1 d 8 h
- PR fusionados (30 d)
- 10
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de CommunityToolkit/AI
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
CommunityToolkit/AI#19 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
CommunityToolkit/AI#61 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
CommunityToolkit/AI#59 ·
Los mantenedores suelen responder en 1 día
-
Report all Cosmos DB emulator issuesQuizá libre de nuevo @adamsitnik la tomó hace 103 días y no hay ningún pull request abierto. Abierto
CommunityToolkit/AI#23 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Make Azure SQL tests conditionalAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
CommunityToolkit/AI#20 ·
Los mantenedores suelen responder en 1 día
Todos los issues de CommunityToolkit/AI
Issues similares
-
byte类型在条件中的解析BUGAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
dotnetcore/FreeSql#2290 ·
-
status:waiting-for-triage type:bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
microsoftgraph/msgraph-sdk-dotnet#3194 ·
Los mantenedores suelen responder en 1 día
-
Backend enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
UI: money shows the minus sign next to the number, not before the currency (IL -3.0m, not -IL 3.0m)Abiertoarea: sim area: unity enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
eyalgolan/statecraft-israel#1107 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
dimitar-radenkov/Pointframe#271 ·
Los mantenedores suelen responder en 1 día