Skip to content

.Net: [MEVD] Comparing to nullable value type in filter translators fails #11665

Closed

Description

@TsengSR

Describe the bug
When the Filter predicate on VectorSearchOptions<T> is a nullable, search fails with an exception.

activeOnly is defined as bool? activeOnly = null in the methods parameters. Since the if block already ensures its never null, I don't see any issue why that operation should fail.

Both activeOnly and activeOnly.Value result in the exception.

Only by changing the method declaration to bool activeOnly or bool activeOnly = true, read non-nullable, the query executes successfully.

Imho this is not an expected behaviour and should be fixed, as its a very common way to define predicates that way.

To Reproduce

        Expression<Func<Project, bool>>? filter = null;
        if (activeOnly is not null)
        {
            filter = project => project.IsActive == activeOnly;
        }
        VectorSearchOptions<Project> filterOptions = new()
        {
            Top = top,
            IncludeTotalCount = true,
            Filter = filter,
        };

Throws:

Exception Details

System.NotSupportedException
  HResult=0x80131515
  Message=Equality expression not supported by Qdrant
  Source=Microsoft.SemanticKernel.Connectors.Qdrant
  StackTrace:
   at Microsoft.SemanticKernel.Connectors.Qdrant.QdrantFilterTranslator.TranslateEqual(Expression left, Expression right, Boolean negated)
   at Microsoft.SemanticKernel.Connectors.Qdrant.QdrantFilterTranslator.Translate(Expression node)
   at Microsoft.SemanticKernel.Connectors.Qdrant.QdrantFilterTranslator.Translate(LambdaExpression lambdaExpression, IReadOnlyDictionary`2 storagePropertyNames)
   at Microsoft.SemanticKernel.Connectors.Qdrant.QdrantVectorStoreRecordCollection`1.d__32`1.MoveNext()

        Expression<Func<Project, bool>>? filter = null;
        if (activeOnly is not null)
        {
            filter = project => project.IsActive == activeOnly.Value;
        }
        VectorSearchOptions<Project> filterOptions = new()
        {
            Top = top,
            IncludeTotalCount = true,
            Filter = filter,
        };

Expected behavior
Operation to succeed.

Platform

  • Language: C#
  • Source: Nuget
    • Microsoft.SemanticKernel 1.47.0
    • Microsoft.SemanticKernel.Connectors.Ollama 1.47.0-alpha
    • Microsoft.SemanticKernel.Connectors.Qdrant 1.47.0-preview
  • AI model: not applicable
  • IDE: Visual Studio 2022
  • OS: Windows 11, 24H2

Activity

  1. changed the title [-].NET: Bug: Quadrant Vector Store filtering with Nullable<bool>/bool? fails[/-] [+].Net: Bug: Quadrant Vector Store filtering with Nullable<bool>/bool? fails[/+] on Apr 21, 2025
  2. changed the title [-].Net: Bug: Quadrant Vector Store filtering with Nullable<bool>/bool? fails[/-] [+].Net: Bug: Qdrant Vector Store filtering with Nullable<bool>/bool? fails[/+] on Apr 21, 2025
  3. changed the title [-].Net: Bug: Qdrant Vector Store filtering with Nullable<bool>/bool? fails[/-] [+].Net: [MEVD] Comparing to nullable value type in filter translators fails[/+] on Apr 28, 2025
  4. added a commit that references this issue on Apr 28, 2025
    7f0c8cc
  5. moved this from Bug to Sprint: In Review in Semantic Kernelon Apr 28, 2025
  6. added 3 commits that reference this issue on Apr 29, 2025
    88b9a26
    b1d4cc2
    a165624
  7. moved this from Sprint: In Review to Sprint: Done in Semantic Kernelon May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

.NETIssue or Pull requests regarding .NET codeBuildFeatures planned for next Build conferencebugSomething isn't workingmsft.ext.vectordataRelated to Microsoft.Extensions.VectorData

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions