Added embeddings prefetching for entities ingest

This commit is contained in:
2026-01-16 12:52:15 +01:00
parent 17cc8f41d5
commit a9a5ee4cb6
3 changed files with 75 additions and 4 deletions

View File

@@ -31,7 +31,12 @@ public class AIProvider
}
}
public float[] GenerateEmbeddings(string modelUri, string[] input)
public float[] GenerateEmbeddings(string modelUri, string input)
{
return [.. GenerateEmbeddings(modelUri, [input]).First()];
}
public IEnumerable<float[]> GenerateEmbeddings(string modelUri, string[] input)
{
Uri uri = new(modelUri);
string provider = uri.Scheme;
@@ -103,13 +108,13 @@ public class AIProvider
try
{
JObject responseContentJson = JObject.Parse(responseContent);
JToken? responseContentTokens = responseContentJson.SelectToken(embeddingsJsonPath);
List<JToken>? responseContentTokens = [.. responseContentJson.SelectTokens(embeddingsJsonPath)];
if (responseContentTokens is null)
{
_logger.LogError("Unable to select tokens using JSONPath {embeddingsJsonPath} for string: {responseContent}.", [embeddingsJsonPath, responseContent]);
throw new JSONPathSelectionException(embeddingsJsonPath, responseContent);
}
return [.. responseContentTokens.Values<float>()];
return [.. responseContentTokens.Select(token => token.ToObject<float[]>() ?? throw new Exception("Unable to cast embeddings response to float[]"))];
}
catch (Exception ex)
{