Improved exception handling for indexing
This commit is contained in:
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Shared.Models;
|
using Shared.Models;
|
||||||
using Server.Helper;
|
using Server.Helper;
|
||||||
|
using Server.Exceptions;
|
||||||
namespace Server.Controllers;
|
namespace Server.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
@@ -42,6 +43,8 @@ public class EntityController : ControllerBase
|
|||||||
|
|
||||||
[HttpPost("Index")]
|
[HttpPost("Index")]
|
||||||
public ActionResult<EntityIndexResult> Index([FromBody] List<JSONEntity>? jsonEntities)
|
public ActionResult<EntityIndexResult> Index([FromBody] List<JSONEntity>? jsonEntities)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
List<Entity>? entities = SearchdomainHelper.EntitiesFromJSON(
|
List<Entity>? entities = SearchdomainHelper.EntitiesFromJSON(
|
||||||
[],
|
[],
|
||||||
@@ -69,9 +72,15 @@ public class EntityController : ControllerBase
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogError("Unable to deserialize an entity");
|
_logger.LogError("Unable to deserialize an entity");
|
||||||
|
return Ok(new EntityIndexResult() { Success = false, Message = "Unable to deserialize an entity"});
|
||||||
|
}
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (ex.InnerException is not null) ex = ex.InnerException;
|
||||||
|
_logger.LogError("Unable to index the provided entities. {ex.Message}", [ex.Message]);
|
||||||
|
return Ok(new EntityIndexResult() { Success = false, Message = ex.Message });
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(new EntityIndexResult() { Success = false });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("List")]
|
[HttpGet("List")]
|
||||||
|
|||||||
5
src/Server/Exceptions/SearchdomainExceptions.cs
Normal file
5
src/Server/Exceptions/SearchdomainExceptions.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
namespace Server.Exceptions;
|
||||||
|
|
||||||
|
public class ProbMethodNotFoundException(string probMethod) : Exception($"Unknown probMethod name {probMethod}") { }
|
||||||
|
|
||||||
|
public class SimilarityMethodNotFoundException(string similarityMethod) : Exception($"Unknown similarityMethod name \"{similarityMethod}\"") { }
|
||||||
@@ -2,6 +2,7 @@ using System.Collections.Concurrent;
|
|||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Server.Exceptions;
|
||||||
using Shared.Models;
|
using Shared.Models;
|
||||||
|
|
||||||
namespace Server.Helper;
|
namespace Server.Helper;
|
||||||
@@ -140,8 +141,8 @@ public static class SearchdomainHelper
|
|||||||
{
|
{
|
||||||
embeddings = Datapoint.GenerateEmbeddings(jsonDatapoint.Text, [.. jsonDatapoint.Model], aIProvider, embeddingCache);
|
embeddings = Datapoint.GenerateEmbeddings(jsonDatapoint.Text, [.. jsonDatapoint.Model], aIProvider, embeddingCache);
|
||||||
}
|
}
|
||||||
var probMethod_embedding = new ProbMethod(jsonDatapoint.Probmethod_embedding, logger) ?? throw new Exception($"Unknown probMethod name {jsonDatapoint.Probmethod_embedding}");
|
var probMethod_embedding = new ProbMethod(jsonDatapoint.Probmethod_embedding, logger) ?? throw new ProbMethodNotFoundException(jsonDatapoint.Probmethod_embedding);
|
||||||
var similarityMethod = new SimilarityMethod(jsonDatapoint.SimilarityMethod, logger) ?? throw new Exception($"Unknown similarityMethod name {jsonDatapoint.SimilarityMethod}");
|
var similarityMethod = new SimilarityMethod(jsonDatapoint.SimilarityMethod, logger) ?? throw new SimilarityMethodNotFoundException(jsonDatapoint.SimilarityMethod);
|
||||||
Datapoint datapoint = new(jsonDatapoint.Name, probMethod_embedding, similarityMethod, hash, [.. embeddings.Select(kv => (kv.Key, kv.Value))]);
|
Datapoint datapoint = new(jsonDatapoint.Name, probMethod_embedding, similarityMethod, hash, [.. embeddings.Select(kv => (kv.Key, kv.Value))]);
|
||||||
int id_datapoint = DatabaseHelper.DatabaseInsertDatapoint(helper, jsonDatapoint.Name, jsonDatapoint.Probmethod_embedding, jsonDatapoint.SimilarityMethod, hash, id_entity); // TODO make this a bulk add action to reduce number of queries
|
int id_datapoint = DatabaseHelper.DatabaseInsertDatapoint(helper, jsonDatapoint.Name, jsonDatapoint.Probmethod_embedding, jsonDatapoint.SimilarityMethod, hash, id_entity); // TODO make this a bulk add action to reduce number of queries
|
||||||
List<(string model, byte[] embedding)> data = [];
|
List<(string model, byte[] embedding)> data = [];
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.Numerics.Tensors;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Server.Exceptions;
|
||||||
|
|
||||||
namespace Server;
|
namespace Server;
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ public class ProbMethod
|
|||||||
if (probMethod is null)
|
if (probMethod is null)
|
||||||
{
|
{
|
||||||
logger.LogError("Unable to retrieve probMethod {name}", [name]);
|
logger.LogError("Unable to retrieve probMethod {name}", [name]);
|
||||||
throw new Exception("Unable to retrieve probMethod");
|
throw new ProbMethodNotFoundException(name);
|
||||||
}
|
}
|
||||||
method = probMethod;
|
method = probMethod;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user