Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Distance function 'CosineDistance' for VectorStoreRecordVectorProperty 'DescriptionEmbedding' is not supported by the Qdrant VectorStore.” #10639

Closed
Sc7-git opened this issue Feb 22, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Sc7-git
Copy link

Sc7-git commented Feb 22, 2025

SK source code:

	public static Distance GetSDKDistanceAlgorithm(VectorStoreRecordVectorProperty vectorProperty)
	{
		if (vectorProperty.DistanceFunction == null)
		{
			return Distance.Cosine;
		}
		return vectorProperty.DistanceFunction switch
		{
			"CosineSimilarity" => Distance.Cosine, 
			"DotProductSimilarity" => Distance.Dot, 
			"EuclideanDistance" => Distance.Euclid, 
			"ManhattanDistance" => Distance.Manhattan, 
			_ => throw new InvalidOperationException("Distance function '" + vectorProperty.DistanceFunction + "' for VectorStoreRecordVectorProperty '" + vectorProperty.DataModelPropertyName + "' is not supported by the Qdrant VectorStore."), 
		};
	}

docs:

Image
https://learn.microsoft.com/en-us/semantic-kernel/concepts/vector-store-connectors/?pivots=programming-language-csharp#define-your-data-model

Image

https://learn.microsoft.com/en-us/semantic-kernel/concepts/vector-store-connectors/out-of-the-box-connectors/qdrant-connector?pivots=programming-language-csharp#property-name-override

my code:

         // Create a Qdrant VectorStore object
         var vectorStore = new QdrantVectorStore(new QdrantClient("192.168.16.53"));

         // Choose a collection from the database and specify the type of key and record stored in it via Generic parameters.
         var collection = vectorStore.GetCollection<ulong, Hotel>("skhotels");

         // Create the collection if it doesn't exist yet.
         await collection.CreateCollectionIfNotExistsAsync(); 

await collection.CreateCollectionIfNotExistsAsync(); error System.InvalidOperationException:“Distance function 'CosineDistance' for VectorStoreRecordVectorProperty 'DescriptionEmbedding' is not supported by the Qdrant VectorStore.”

Please fix the documentation or sk source code, I will be very grateful.

@Sc7-git Sc7-git added the bug Something isn't working label Feb 22, 2025
@Sc7-git
Copy link
Author

Sc7-git commented Feb 22, 2025

This is normal.

    public class Hotel
    {
        [VectorStoreRecordKey]
        public ulong HotelId { get; set; }

        [VectorStoreRecordData(IsFilterable = true)]
        public string HotelName { get; set; }

        [VectorStoreRecordData(IsFullTextSearchable = true)]
        public string Description { get; set; }

        //[VectorStoreRecordVector(4, DistanceFunction.CosineDistance, IndexKind.Hnsw, StoragePropertyName = "hotel_description_embedding")]
        //[VectorStoreRecordVector(Dimensions: 4, DistanceFunction.CosineDistance, IndexKind.Hnsw)]
        [VectorStoreRecordVector(1536)]
        public ReadOnlyMemory<float>? DescriptionEmbedding { get; set; }

        [VectorStoreRecordData(IsFilterable = true)]
        public string[] Tags { get; set; }
    }

@westey-m
Copy link
Contributor

Thanks @Sc7-git for raising this. I'm working on updating the docs now.

@westey-m
Copy link
Contributor

Docs have been updated.

@westey-m westey-m moved this from Bug to Sprint: Done in Semantic Kernel Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Sprint: Done
Development

No branches or pull requests

2 participants