Fixed cache invalidation issue
This commit is contained in:
@@ -56,10 +56,10 @@ public class EntityController : ControllerBase
|
||||
foreach (var jsonEntity in jsonEntities)
|
||||
{
|
||||
string jsonEntityName = jsonEntity.Name;
|
||||
if (entities.Select(x => x.name == jsonEntityName).Any()
|
||||
&& !invalidatedSearchdomains.Contains(jsonEntityName))
|
||||
{
|
||||
string jsonEntitySearchdomainName = jsonEntity.Searchdomain;
|
||||
if (entities.Select(x => x.name == jsonEntityName).Any()
|
||||
&& !invalidatedSearchdomains.Contains(jsonEntitySearchdomainName))
|
||||
{
|
||||
invalidatedSearchdomains.Add(jsonEntitySearchdomainName);
|
||||
_domainManager.InvalidateSearchdomainCache(jsonEntitySearchdomainName);
|
||||
}
|
||||
|
||||
@@ -118,8 +118,24 @@ public static class SearchdomainHelper
|
||||
foreach (JSONDatapoint jsonDatapoint in jsonEntity.Datapoints)
|
||||
{
|
||||
string hash = Convert.ToBase64String(SHA256.HashData(Encoding.UTF8.GetBytes(jsonDatapoint.Text)));
|
||||
Dictionary<string, float[]> embeddings = embeddingsLUT.ContainsKey(hash) ? embeddingsLUT[hash] : [];
|
||||
if (embeddings.Count == 0)
|
||||
Dictionary<string, float[]> embeddings = [];
|
||||
if (embeddingsLUT.ContainsKey(hash))
|
||||
{
|
||||
Dictionary<string, float[]> hashLUT = embeddingsLUT[hash];
|
||||
foreach (string model in jsonDatapoint.Model)
|
||||
{
|
||||
if (hashLUT.ContainsKey(model))
|
||||
{
|
||||
embeddings.Add(model, hashLUT[model]);
|
||||
}
|
||||
else
|
||||
{
|
||||
var additionalEmbeddings = Datapoint.GenerateEmbeddings(jsonDatapoint.Text, [model], ollama, embeddingCache);
|
||||
embeddings.Add(model, additionalEmbeddings.First().Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
embeddings = Datapoint.GenerateEmbeddings(jsonDatapoint.Text, [.. jsonDatapoint.Model], ollama, embeddingCache);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,6 @@ public class Searchdomain
|
||||
|
||||
public void UpdateEntityCache()
|
||||
{
|
||||
entityCache = [];
|
||||
Dictionary<string, dynamic> parametersIDSearchdomain = new()
|
||||
{
|
||||
["id"] = this.id
|
||||
@@ -132,6 +131,7 @@ public class Searchdomain
|
||||
}
|
||||
attributeReader.Close();
|
||||
|
||||
entityCache = [];
|
||||
DbDataReader entityReader = helper.ExecuteSQLCommand("SELECT entity.id, name, probmethod FROM entity WHERE id_searchdomain=@id", parametersIDSearchdomain);
|
||||
while (entityReader.Read())
|
||||
{
|
||||
@@ -155,6 +155,7 @@ public class Searchdomain
|
||||
}
|
||||
entityReader.Close();
|
||||
modelsInUse = GetModels(entityCache);
|
||||
embeddingCache = []; // TODO remove this and implement proper remediation to improve performance
|
||||
}
|
||||
|
||||
public List<(float, string)> Search(string query, bool sort=true)
|
||||
@@ -166,7 +167,7 @@ public class Searchdomain
|
||||
{ // Idea: Add access count to each entry. On limit hit, sort the entries by access count and remove the bottom 10% of entries
|
||||
embeddingCache.Add(query, queryEmbeddings);
|
||||
}
|
||||
}
|
||||
} // TODO implement proper cache remediation for embeddingCache here
|
||||
|
||||
List<(float, string)> result = [];
|
||||
|
||||
|
||||
@@ -64,10 +64,7 @@ public class SearchdomainManager
|
||||
|
||||
public void InvalidateSearchdomainCache(string searchdomainName)
|
||||
{
|
||||
if (searchdomains.TryGetValue(searchdomainName, out var searchdomain))
|
||||
{
|
||||
searchdomain.UpdateEntityCache();
|
||||
}
|
||||
GetSearchdomain(searchdomainName).UpdateEntityCache();
|
||||
}
|
||||
|
||||
public List<string> ListSearchdomains()
|
||||
|
||||
Reference in New Issue
Block a user