Skip to content

Binary-encode vectors in sort clauses as well #146

@sl-at-ibm

Description

@sl-at-ibm

Both for the sort in collections and tables, currently (as of main on April 16, 2026) the vectors there appear as lists of floats in the payload.

There's a little perf improvement in enabling $binary encoding.

Can be tested e.g. by inspecting payloads of this for collections:

    [Fact]
    public async Task Test_VectorWriteCollection()
    {
        var collectionName = "vectorWriteTestCollection";
        try
        {
            // TODO replace with annotations in the class since 125 is in
            var collOptions = new CollectionDefinition
            {
                Vector = new VectorOptions
                {
                    Dimension = 3,
                }
            };
            var collection = await fixture.Database.CreateCollectionAsync<BinaryVectorObject>(collectionName, collOptions);
            var insertee = new BinaryVectorObject
            {
                _id = "001",
                TheVector = new float[] {0.1f, -0.2f, 0.3f},
            };
            await collection.InsertOneAsync(insertee);

            var findOptions = new DocumentFindOptions<BinaryVectorObject>()
            {
                Sort = Builders<BinaryVectorObject>.Sort.Vector(new float[] {-0.1f, 0.2f, -0.3f}),
            };
            var reread = await collection.FindOneAsync(findOptions);

            Assert.Equal(insertee._id, reread._id);
        }
        finally
        {
            await fixture.Database.DropCollectionAsync(collectionName);
        }
    }

and e.g. the existing FindOne_Vector test for tables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions