Add GetVectors batch interface.

This commit is contained in:
hchen2020 2023-08-15 12:21:04 -05:00
parent a4f5af93f7
commit 38bf2cdf4e
3 changed files with 17 additions and 0 deletions

View file

@ -4,4 +4,5 @@ public interface ITextEmbedding
{
int Dimension { get; }
float[] GetVector(string text);
List<float[]> GetVectors(List<string> texts);
}

View file

@ -26,4 +26,9 @@ public class TextEmbeddingProvider : ITextEmbedding
return _embedder.GetEmbeddings(text);
}
public List<float[]> GetVectors(List<string> texts)
{
throw new NotImplementedException();
}
}

View file

@ -1,6 +1,7 @@
using BotSharp.Abstraction.MLTasks;
using BotSharp.Plugin.MetaAI.Settings;
using FastText.NetWrapper;
using System.Collections.Generic;
using System.IO;
namespace BotSharp.Plugin.MetaAI.Providers;
@ -42,4 +43,14 @@ public class fastTextEmbeddingProvider : ITextEmbedding
return _fastText.GetSentenceVector(text);
}
public List<float[]> GetVectors(List<string> texts)
{
var vectors = new List<float[]>();
for (int i = 0; i < texts.Count; i++)
{
vectors.Add(GetVector(texts[i]));
}
return vectors;
}
}