Fixed cache invalidation issue
This commit is contained in:
@@ -56,10 +56,10 @@ public class EntityController : ControllerBase
|
|||||||
foreach (var jsonEntity in jsonEntities)
|
foreach (var jsonEntity in jsonEntities)
|
||||||
{
|
{
|
||||||
string jsonEntityName = jsonEntity.Name;
|
string jsonEntityName = jsonEntity.Name;
|
||||||
|
string jsonEntitySearchdomainName = jsonEntity.Searchdomain;
|
||||||
if (entities.Select(x => x.name == jsonEntityName).Any()
|
if (entities.Select(x => x.name == jsonEntityName).Any()
|
||||||
&& !invalidatedSearchdomains.Contains(jsonEntityName))
|
&& !invalidatedSearchdomains.Contains(jsonEntitySearchdomainName))
|
||||||
{
|
{
|
||||||
string jsonEntitySearchdomainName = jsonEntity.Searchdomain;
|
|
||||||
invalidatedSearchdomains.Add(jsonEntitySearchdomainName);
|
invalidatedSearchdomains.Add(jsonEntitySearchdomainName);
|
||||||
_domainManager.InvalidateSearchdomainCache(jsonEntitySearchdomainName);
|
_domainManager.InvalidateSearchdomainCache(jsonEntitySearchdomainName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,8 +118,24 @@ public static class SearchdomainHelper
|
|||||||
foreach (JSONDatapoint jsonDatapoint in jsonEntity.Datapoints)
|
foreach (JSONDatapoint jsonDatapoint in jsonEntity.Datapoints)
|
||||||
{
|
{
|
||||||
string hash = Convert.ToBase64String(SHA256.HashData(Encoding.UTF8.GetBytes(jsonDatapoint.Text)));
|
string hash = Convert.ToBase64String(SHA256.HashData(Encoding.UTF8.GetBytes(jsonDatapoint.Text)));
|
||||||
Dictionary<string, float[]> embeddings = embeddingsLUT.ContainsKey(hash) ? embeddingsLUT[hash] : [];
|
Dictionary<string, float[]> embeddings = [];
|
||||||
if (embeddings.Count == 0)
|
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);
|
embeddings = Datapoint.GenerateEmbeddings(jsonDatapoint.Text, [.. jsonDatapoint.Model], ollama, embeddingCache);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ public class Searchdomain
|
|||||||
|
|
||||||
public void UpdateEntityCache()
|
public void UpdateEntityCache()
|
||||||
{
|
{
|
||||||
entityCache = [];
|
|
||||||
Dictionary<string, dynamic> parametersIDSearchdomain = new()
|
Dictionary<string, dynamic> parametersIDSearchdomain = new()
|
||||||
{
|
{
|
||||||
["id"] = this.id
|
["id"] = this.id
|
||||||
@@ -92,7 +91,7 @@ public class Searchdomain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
embeddingReader.Close();
|
embeddingReader.Close();
|
||||||
|
|
||||||
DbDataReader datapointReader = helper.ExecuteSQLCommand("SELECT id, id_entity, name, probmethod_embedding, hash FROM datapoint", parametersIDSearchdomain);
|
DbDataReader datapointReader = helper.ExecuteSQLCommand("SELECT id, id_entity, name, probmethod_embedding, hash FROM datapoint", parametersIDSearchdomain);
|
||||||
Dictionary<int, List<Datapoint>> datapoint_unassigned = [];
|
Dictionary<int, List<Datapoint>> datapoint_unassigned = [];
|
||||||
while (datapointReader.Read())
|
while (datapointReader.Read())
|
||||||
@@ -115,7 +114,7 @@ public class Searchdomain
|
|||||||
}
|
}
|
||||||
datapointReader.Close();
|
datapointReader.Close();
|
||||||
|
|
||||||
DbDataReader attributeReader = helper.ExecuteSQLCommand("SELECT id, id_entity, attribute, value FROM attribute", parametersIDSearchdomain);
|
DbDataReader attributeReader = helper.ExecuteSQLCommand("SELECT id, id_entity, attribute, value FROM attribute", parametersIDSearchdomain);
|
||||||
Dictionary<int, Dictionary<string, string>> attributes_unassigned = [];
|
Dictionary<int, Dictionary<string, string>> attributes_unassigned = [];
|
||||||
while (attributeReader.Read())
|
while (attributeReader.Read())
|
||||||
{
|
{
|
||||||
@@ -132,6 +131,7 @@ public class Searchdomain
|
|||||||
}
|
}
|
||||||
attributeReader.Close();
|
attributeReader.Close();
|
||||||
|
|
||||||
|
entityCache = [];
|
||||||
DbDataReader entityReader = helper.ExecuteSQLCommand("SELECT entity.id, name, probmethod FROM entity WHERE id_searchdomain=@id", parametersIDSearchdomain);
|
DbDataReader entityReader = helper.ExecuteSQLCommand("SELECT entity.id, name, probmethod FROM entity WHERE id_searchdomain=@id", parametersIDSearchdomain);
|
||||||
while (entityReader.Read())
|
while (entityReader.Read())
|
||||||
{
|
{
|
||||||
@@ -155,6 +155,7 @@ public class Searchdomain
|
|||||||
}
|
}
|
||||||
entityReader.Close();
|
entityReader.Close();
|
||||||
modelsInUse = GetModels(entityCache);
|
modelsInUse = GetModels(entityCache);
|
||||||
|
embeddingCache = []; // TODO remove this and implement proper remediation to improve performance
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<(float, string)> Search(string query, bool sort=true)
|
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
|
{ // 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);
|
embeddingCache.Add(query, queryEmbeddings);
|
||||||
}
|
}
|
||||||
}
|
} // TODO implement proper cache remediation for embeddingCache here
|
||||||
|
|
||||||
List<(float, string)> result = [];
|
List<(float, string)> result = [];
|
||||||
|
|
||||||
|
|||||||
@@ -64,10 +64,7 @@ public class SearchdomainManager
|
|||||||
|
|
||||||
public void InvalidateSearchdomainCache(string searchdomainName)
|
public void InvalidateSearchdomainCache(string searchdomainName)
|
||||||
{
|
{
|
||||||
if (searchdomains.TryGetValue(searchdomainName, out var searchdomain))
|
GetSearchdomain(searchdomainName).UpdateEntityCache();
|
||||||
{
|
|
||||||
searchdomain.UpdateEntityCache();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<string> ListSearchdomains()
|
public List<string> ListSearchdomains()
|
||||||
|
|||||||
Reference in New Issue
Block a user