kernel-memory icon indicating copy to clipboard operation
kernel-memory copied to clipboard

[Bug] Regression: Converting double.MinValue to float yields -Infinity

Open alissonsolitto opened this issue 10 months ago • 1 comments

Context / Scenario

When executing the search method (SearchAsync) with filters only (i.e., without a query), the system now assigns the relevance value as double.MinValue. Previously, the code used float.MinValue, which represents a very large negative finite value. This change occurs during the addition of the partition in the citation (citation.Partitions.Add(...)).

IAsyncEnumerable<(MemoryRecord, double)> matches = string.IsNullOrEmpty(query)
    ? this._memoryDb.GetListAsync(index, filters, limit, false, cancellationToken).Select(memoryRecord => (memoryRecord, double.MinValue))
    : this._memoryDb.GetSimilarListAsync(index, text: query, filters, minRelevance, limit, false, cancellationToken);

What happened?

After commit 3f9a04a74e95195634c2f0107bda918c8dae3369 (Refactor search client (#905)), the relevance value is being passed as a double.MinValue and then converted to a float. Since double.MinValue exceeds the lower bound of a float, this conversion results in -Infinity instead of a finite negative value. This behavior may lead to unexpected issues in sorting and displaying the search results.

Importance

edge case

Platform, Language, Versions

  • .NET 9

Relevant log output

.NET number values such as positive and negative infinity cannot be written as valid JSON. To make it work when using 'JsonSerializer', consider specifying 'JsonNumberHandling.AllowNamedFloatingPointLiterals' (see https://learn.microsoft.com/dotnet/api/system.text.json.serialization.jsonnumberhandling).

alissonsolitto avatar Mar 06 '25 12:03 alissonsolitto