Skip to content

Commit

Permalink
Cherry pick branch 'genexuslabs:embedding-data-type' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudia Beatriz Murialdo Garrone authored and Beta Bot committed Sep 18, 2024
1 parent 0ea9498 commit 974589b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 5 additions & 1 deletion dotnet/src/dotnetcore/GxClasses/Domain/GxEmbedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace GeneXus.Utils
{
public class GxEmbedding
{
public static readonly GxEmbedding Empty = new GxEmbedding() { Model=string.Empty, Dimensions=0};

ReadOnlyMemory<float> _embedding;
public GxEmbedding()
Expand All @@ -20,6 +19,7 @@ public GxEmbedding(string model, int dimensions)
{
Model = model;
Dimensions = dimensions;
_embedding = new ReadOnlyMemory<float>(new float[dimensions]);
}
internal GxEmbedding(IReadOnlyList<double> embedding)
{
Expand All @@ -30,6 +30,10 @@ internal GxEmbedding(float[] embedding)
_embedding = embedding;
}

internal static GxEmbedding Empty(string model, int dimensions)
{
return new GxEmbedding(model, dimensions);
}
public override string ToString()
{
return $"[{string.Join(",", _embedding.Span.ToArray())}]";
Expand Down
15 changes: 11 additions & 4 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,7 @@ public static object GetCopyFrom(object value)
else
{
Type type = value.GetType();

if (type.IsSubclassOf(typeof(ValueType)))
return value;
else if (type == typeof(string))
if (type.IsSubclassOf(typeof(ValueType)) || type == typeof(string))
return value;
else if (type == typeof(Stream))
{
Expand All @@ -874,6 +871,16 @@ public static object GetCopyFrom(object value)
oStream.CopyTo(memStream);
return memStream;
}
#if NETCORE
else if (type == typeof(Pgvector.Vector))
{
Pgvector.Vector vector = (Pgvector.Vector)value;
float[] copyArray = new float[vector.Memory.Length];
vector.Memory.Span.CopyTo(copyArray);
Pgvector.Vector copyVector = new Pgvector.Vector(new ReadOnlyMemory<float>(copyArray));
return copyVector;
}
#endif
else
{
byte[] valueByte = value as byte[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public override IGeographicNative GetGeospatial(IGxDbCommand cmd, IDataRecord DR
public override GxEmbedding GetEmbedding(IGxDbCommand cmd, IDataReader DR, int i, string model, int dimensions)
{
if (!cmd.HasMoreRows || DR == null || DR.IsDBNull(i))
return GxEmbedding.Empty;
return GxEmbedding.Empty(model, dimensions);
else
{
Pgvector.Vector vector = (Pgvector.Vector)DR.GetValue(i);
Expand Down

0 comments on commit 974589b

Please sign in to comment.