Skip to content

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

@N-E-W-T-O-N

Description

@N-E-W-T-O-N

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

  • OS: [e.g. Windows, Mac]
  • IDE: [e.g. Visual Studio, VS Code]
  • Language: [e.g. C#, Python]
  • Source: [e.g. NuGet package version Latest ]
  • Embedding : HuggingfaceEmbedding
  • Vector Database : Qdrant

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET codebugSomething isn't working

Type

No type

Projects

Status

Sprint: Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions