using System;
using xCommons.Extensions;
namespace xAiModels.Extensions
{
public static class XEmbeddingExtensions
{
///
/// Converts String to Embeddings JSON ...
///
///
///
public static float[] AsEmbedding(this string source)
{
//
// Validate ...
if (source.IsNullOrEmpty())
{
return [];
}
//
// JSON is expected to be like: [0.12, 0.34, ...] ...
var result = source.FromJSON();
if (!result.HasChild())
{
result = [];
}
//
return result;
}
///
/// Converts ReadOnly Memory to Embedding Representation ...
///
///
///
public static string ToEmbedding(this ReadOnlyMemory source)
{
//
var result = string.Empty;
//
if (!source.IsNull() && !source.IsEmpty)
{
result = source.ToArray().ToJSON();
}
//
return result;
}
}
}