microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
20.52k stars 2.96k forks source link

.Net: HuggingFace Embedding : Unable Deserlization for certain models #6635

Open N-E-W-T-O-N opened 1 month ago

N-E-W-T-O-N commented 1 month ago

Describe the bug HuggingFace Embedding Interface API: Issue related to Deserialization So I was using BAAI/bge-large-en embedding model from huggingface Interface API .The code execution produces the following error:

The JSON value could not be converted to System.Collections.Generic.List`1[System.ReadOnlyMemory`1[System.Single]]. Path: $[0][0] | LineNumber: 0 | BytePositionInLine: 23.

To Reproduce Steps to reproduce the behavior:

  1. Use the BAAI/bge-large-en embedding model.
  2. Execute the embedding code.

Based on the output, it was clear that this issue was related to Json Deserilaztion .First, I check what the expected datatype. internal sealed class TextEmbeddingResponse : List<List<List<ReadOnlyMemory<float>>>>; The the HuggingFace Embedinng Expected ist<List<List<ReadOnlyMemory<float>>>> & then return [0][0].ToList() Then I check in Postman what is the response coming from the embedding BAAI

So it was clear that APi is sending List<ReadOnlyMemory> while services expects a list<list<list<ReadOnlyMemory>> .

I tested for other models and got the same response .

Screenshots

MxBai image

All-MiniLM-L6-v2 Screenshot 2024-06-02 162430

Jina Screenshot 2024-06-02 162628

Finally I tested with the following embedding LaBSE .Able to get the expected response . Screenshot 2024-06-02 162657

Platform

N-E-W-T-O-N commented 1 month ago

I suggest adding a condition check for the type coming from the API response to handle the deserialization process more gracefully.

markwallace-microsoft commented 1 month ago

@N-E-W-T-O-N Thanks for creating the issue. Would you be interested in creating a PR with the fix for this?

N-E-W-T-O-N commented 1 month ago

Happy to do that.

N-E-W-T-O-N commented 4 weeks ago

Hello @markwallace-microsoft . I have created a Pull Request #6673 as Asked Please review my PR