Added filtering query output to top n elements
This commit is contained in:
@@ -154,7 +154,7 @@ public class Searchdomain
|
||||
embeddingCache = []; // TODO remove this and implement proper remediation to improve performance
|
||||
}
|
||||
|
||||
public List<(float, string)> Search(string query)
|
||||
public List<(float, string)> Search(string query, int? topN = null)
|
||||
{
|
||||
if (searchCache.TryGetValue(query, out DateTimedSearchResult cachedResult))
|
||||
{
|
||||
@@ -190,9 +190,14 @@ public class Searchdomain
|
||||
}
|
||||
result.Add((entity.probMethod(datapointProbs), entity.name));
|
||||
}
|
||||
List<(float, string)> results = [.. result.OrderByDescending(s => s.Item1)];
|
||||
IEnumerable<(float, string)> sortedResults = result.OrderByDescending(s => s.Item1);
|
||||
if (topN is not null)
|
||||
{
|
||||
sortedResults = sortedResults.Take(topN ?? 0);
|
||||
}
|
||||
List<(float, string)> results = [.. sortedResults];
|
||||
List<ResultItem> searchResult = new(
|
||||
[.. results.Select(r =>
|
||||
[.. sortedResults.Select(r =>
|
||||
new ResultItem(r.Item1, r.Item2 ))]
|
||||
);
|
||||
searchCache[query] = new DateTimedSearchResult(DateTime.Now, searchResult);
|
||||
|
||||
Reference in New Issue
Block a user