Skip to content

.Net: VectorStore: Add ability to filter results by the similarity score #9566

Description

@arzzzae

Would be nice to be able to filter by the similarity search score on a database level.

For example, If I wanted to return just the records that is greater than or equal to 0.80. I am able to do this in Azure Cosmos Mongo DB instance by adding a match pipeline.

BsonDocument[] pipeline =
[
    new BsonDocument
    {
        {
            "$search", new BsonDocument
            {
                {
                    "cosmosSearch", new BsonDocument
                    {
                        { "vector", embeddings },
                        { "path", indexProperty },
                        { "k", 5 }
                    }
                },
                { "returnStoredSource", true },
            }
        }
    },
    new BsonDocument
    {
        {
            "$project", new BsonDocument
            {
                { "id", 1 },
                { "name", 1 },
                { "text", 1 },
                { "url", 1 },
                { "vector", 1 },
                { "searchScore", new BsonDocument { { "$meta", "searchScore" } } }
            }
        }
    },
    new BsonDocument
    {
        {
            "$match", new BsonDocument
            {
                { "searchScore", new BsonDocument { { "$gte", 0.80 } } }
            }
        }
    }
];

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions