Fixed requested value LVEWAvg was not found, improved resiliency

This commit is contained in:
2025-12-14 14:40:00 +01:00
parent da603746e8
commit eb6f7ef524
2 changed files with 24 additions and 16 deletions

View File

@@ -29,7 +29,7 @@ public enum ProbMethodEnum
GeometricMean, GeometricMean,
EVEWAvg, EVEWAvg,
HVEWAvg, HVEWAvg,
LVEWavg, LVEWAvg,
DictionaryWeightedAverage DictionaryWeightedAverage
} }
@@ -49,7 +49,7 @@ public static class Probmethods
[ProbMethodEnum.GeometricMean] = GeometricMean, [ProbMethodEnum.GeometricMean] = GeometricMean,
[ProbMethodEnum.EVEWAvg] = ExtremeValuesEmphasisWeightedAverage, [ProbMethodEnum.EVEWAvg] = ExtremeValuesEmphasisWeightedAverage,
[ProbMethodEnum.HVEWAvg] = HighValueEmphasisWeightedAverage, [ProbMethodEnum.HVEWAvg] = HighValueEmphasisWeightedAverage,
[ProbMethodEnum.LVEWavg] = LowValueEmphasisWeightedAverage, [ProbMethodEnum.LVEWAvg] = LowValueEmphasisWeightedAverage,
[ProbMethodEnum.DictionaryWeightedAverage] = DictionaryWeightedAverage [ProbMethodEnum.DictionaryWeightedAverage] = DictionaryWeightedAverage
}; };
} }
@@ -66,7 +66,6 @@ public static class Probmethods
methodName = name[..colonIndex]; methodName = name[..colonIndex];
jsonArg = name[(colonIndex + 1)..]; jsonArg = name[(colonIndex + 1)..];
} }
ProbMethodEnum probMethodEnum = (ProbMethodEnum)Enum.Parse( ProbMethodEnum probMethodEnum = (ProbMethodEnum)Enum.Parse(
typeof(ProbMethodEnum), typeof(ProbMethodEnum),
methodName methodName

View File

@@ -1,5 +1,6 @@
using System.Data; using System.Data;
using System.Data.Common; using System.Data.Common;
using ElmahCore.Mvc.Logger;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using Server.Helper; using Server.Helper;
@@ -54,21 +55,29 @@ public class Searchdomain
Dictionary<int, Dictionary<string, float[]>> embedding_unassigned = []; Dictionary<int, Dictionary<string, float[]>> embedding_unassigned = [];
while (embeddingReader.Read()) while (embeddingReader.Read())
{ {
int id_datapoint = embeddingReader.GetInt32(1); int id_datapoint;
string model = embeddingReader.GetString(2); try
long length = embeddingReader.GetBytes(3, 0, null, 0, 0);
byte[] embedding = new byte[length];
embeddingReader.GetBytes(3, 0, embedding, 0, (int) length);
if (embedding_unassigned.TryGetValue(id_datapoint, out Dictionary<string, float[]>? embedding_unassigned_id_datapoint))
{ {
embedding_unassigned[id_datapoint][model] = SearchdomainHelper.FloatArrayFromBytes(embedding); id_datapoint = embeddingReader.GetInt32(1);
} string model = embeddingReader.GetString(2);
else long length = embeddingReader.GetBytes(3, 0, null, 0, 0);
{ byte[] embedding = new byte[length];
embedding_unassigned[id_datapoint] = new() embeddingReader.GetBytes(3, 0, embedding, 0, (int) length);
if (embedding_unassigned.TryGetValue(id_datapoint, out Dictionary<string, float[]>? embedding_unassigned_id_datapoint))
{ {
[model] = SearchdomainHelper.FloatArrayFromBytes(embedding) embedding_unassigned[id_datapoint][model] = SearchdomainHelper.FloatArrayFromBytes(embedding);
}; }
else
{
embedding_unassigned[id_datapoint] = new()
{
[model] = SearchdomainHelper.FloatArrayFromBytes(embedding)
};
}
} catch (Exception e)
{
_logger.LogError("Error reading embedding (id: {id_datapoint}) from database: {e.Message} - {e.StackTrace}", [id_datapoint, e.Message, e.StackTrace]);
ElmahCore.ElmahExtensions.RaiseError(e);
} }
} }
embeddingReader.Close(); embeddingReader.Close();