Skip to content

.Net: [MEVD] Batching GetAsync and DeleteAsync don't work in dynamic mode #13303

@roji

Description

@roji

We have a typing issue with the intersection of the batching APIs accepting keys (GetAsync, DeleteAsync) and dynamic collections. In a nutshell, with dynamic collections, the generic TKey type is object, and so GetAsync/DeleteAsync accept IEnumerable<object>. At the same time, the actual implementation of these methods in providers infers the (concrete) key type from the parameter type, but object obviously isn't a supported key type.

This is a provider implementation issue: we need to stop looking at the generic type.

using var collection = new PostgresDynamicCollection(
    "Host=localhost;Username=test;Password=test",
    "test",
    new()
    {
        Definition = new()
        {
            Properties =
            [
                new VectorStoreKeyProperty("Id", typeof(int)),
                new VectorStoreDataProperty("Text", typeof(string)),
                new VectorStoreVectorProperty("Embedding", typeof(float[]), dimensions: 3)
            ]
        }
    });

await collection.EnsureCollectionDeletedAsync();
await collection.EnsureCollectionExistsAsync();

// Unsupported key type Object
await collection.DeleteAsync(new object[] { 1, 2 });

// Resolves to non-batching DeleteAsync(object key), errors because array of ints isn't supported (or isn't the right key type)
await collection.DeleteAsync(new int[] { 1, 2 });

// Does not compile: cannot convert from 'int[]' to 'System.Collections.Generic.IEnumerable<object>'
await collection.DeleteAsync(keys: new int[] { 1, 2 });

// Same thing happens with GetAsync
_ = await collection.GetAsync(new object[] { 1, 2 }).ToArrayAsync();
_ = await collection.GetAsync(new int[] { 1, 2 });
_ = await collection.GetAsync(keys: new int[] { 1, 2 }).ToArrayAsync();

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET codemsft.ext.vectordataRelated to Microsoft.Extensions.VectorData

Type

Projects

Status

Sprint: Planned

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions