Skip to content

Commit 38bf2cd

Browse files
author
hchen2020
committed
Add GetVectors batch interface.
1 parent a4f5af9 commit 38bf2cd

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎src/Infrastructure/BotSharp.Abstraction/MLTasks/ITextEmbedding.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ public interface ITextEmbedding
44
{
55
int Dimension { get; }
66
float[] GetVector(string text);
7+
List<float[]> GetVectors(List<string> texts);
78
}

‎src/Infrastructure/BotSharp.Core/Plugins/LLamaSharp/TextEmbeddingProvider.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public float[] GetVector(string text)
2626

2727
return _embedder.GetEmbeddings(text);
2828
}
29+
30+
public List<float[]> GetVectors(List<string> texts)
31+
{
32+
throw new NotImplementedException();
33+
}
2934
}

‎src/Plugins/BotSharp.Plugin.MetaAI/Providers/fastTextEmbeddingProvider.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BotSharp.Abstraction.MLTasks;
22
using BotSharp.Plugin.MetaAI.Settings;
33
using FastText.NetWrapper;
4+
using System.Collections.Generic;
45
using System.IO;
56

67
namespace BotSharp.Plugin.MetaAI.Providers;
@@ -42,4 +43,14 @@ public float[] GetVector(string text)
4243

4344
return _fastText.GetSentenceVector(text);
4445
}
46+
47+
public List<float[]> GetVectors(List<string> texts)
48+
{
49+
var vectors = new List<float[]>();
50+
for (int i = 0; i < texts.Count; i++)
51+
{
52+
vectors.Add(GetVector(texts[i]));
53+
}
54+
return vectors;
55+
}
4556
}

0 commit comments

Comments
 (0)