You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

LLamaSharpEmbeddingGeneration.cs 935 B

123456789101112131415161718192021222324252627282930
  1. using LLama;
  2. using Microsoft.SemanticKernel;
  3. using Microsoft.SemanticKernel.Embeddings;
  4. namespace LLamaSharp.SemanticKernel.TextEmbedding;
  5. public sealed class LLamaSharpEmbeddingGeneration : ITextEmbeddingGenerationService
  6. {
  7. private readonly LLamaEmbedder _embedder;
  8. private readonly Dictionary<string, object?> _attributes = new();
  9. public IReadOnlyDictionary<string, object?> Attributes => this._attributes;
  10. public LLamaSharpEmbeddingGeneration(LLamaEmbedder embedder)
  11. {
  12. _embedder = embedder;
  13. }
  14. /// <inheritdoc/>
  15. public async Task<IList<ReadOnlyMemory<float>>> GenerateEmbeddingsAsync(IList<string> data, Kernel? kernel = null, CancellationToken cancellationToken = default)
  16. {
  17. var result = new List<ReadOnlyMemory<float>>();
  18. foreach (var item in data)
  19. result.Add(await _embedder.GetEmbeddings(item, cancellationToken));
  20. return result;
  21. }
  22. }