Skip to content

feat: support sparse text embeddings - #202

Open
iccfish wants to merge 1 commit into
cnblogs:mainfrom
iccfish:feature/260806-text-embedding-support-sparse
Open

feat: support sparse text embeddings#202
iccfish wants to merge 1 commit into
cnblogs:mainfrom
iccfish:feature/260806-text-embedding-support-sparse

Conversation

@iccfish

@iccfish iccfish commented Aug 6, 2026

Copy link
Copy Markdown

Add support sparse text embeddings in repsonse.

PixPin_2026-08-06_14-02-35

/// <param name="Embedding">The resulting embedding.</param>
public record TextEmbeddingItem(int TextIndex, float[] Embedding);
/// <param name="SparseEmbedding">The resulting sparse embedding.</param>
public record TextEmbeddingItem(int TextIndex, float[] Embedding, List<SparseEmbeddingItem> SparseEmbedding);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public record TextEmbeddingItem(int TextIndex, float[] Embedding, List<SparseEmbeddingItem> SparseEmbedding);
public record TextEmbeddingItem(int TextIndex, float[] Embedding, List<SparseEmbeddingItem>? SparseEmbedding);

SparseEmbedding isn't always available in the response.

Image

new ModelResponse<TextEmbeddingOutput, TextEmbeddingTokenUsage>
{
Output = new TextEmbeddingOutput(new List<TextEmbeddingItem> { new(0, new float[0]) }),
Output = new TextEmbeddingOutput(new List<TextEmbeddingItem> { new(0, new float[0], new()) }),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Output = new TextEmbeddingOutput(new List<TextEmbeddingItem> { new(0, new float[0], new()) }),
Output = new TextEmbeddingOutput(new List<TextEmbeddingItem> { new(0, new float[0], null) }),

new ModelResponse<TextEmbeddingOutput, TextEmbeddingTokenUsage>
{
Output = new TextEmbeddingOutput(new List<TextEmbeddingItem> { new(0, new float[0]) }),
Output = new TextEmbeddingOutput(new List<TextEmbeddingItem> { new(0, new float[0], new()) }),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Output = new TextEmbeddingOutput(new List<TextEmbeddingItem> { new(0, new float[0], new()) }),
Output = new TextEmbeddingOutput(new List<TextEmbeddingItem> { new(0, new float[0], null) }),

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants