Move entire score computation to an isolate
This commit is contained in:
parent
cb82d44d4d
commit
289fbc8a11
1 changed files with 25 additions and 15 deletions
|
@ -110,17 +110,16 @@ class SemanticSearchService {
|
||||||
);
|
);
|
||||||
|
|
||||||
startTime = DateTime.now();
|
startTime = DateTime.now();
|
||||||
final queryResults = <QueryResult>[];
|
|
||||||
for (final embedding in _cachedEmbeddings) {
|
final List<QueryResult> queryResults = await _computer.compute(
|
||||||
final score = computeScore({
|
computeBulkScore,
|
||||||
"imageEmbedding": embedding.embedding,
|
param: {
|
||||||
|
"imageEmbeddings": _cachedEmbeddings,
|
||||||
"textEmbedding": textEmbedding,
|
"textEmbedding": textEmbedding,
|
||||||
});
|
},
|
||||||
if (score >= kScoreThreshold) {
|
taskName: "computeBulkScore",
|
||||||
queryResults.add(QueryResult(embedding.fileID, score));
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
queryResults.sort((first, second) => second.score.compareTo(first.score));
|
|
||||||
endTime = DateTime.now();
|
endTime = DateTime.now();
|
||||||
_logger.info(
|
_logger.info(
|
||||||
"computingScores took: " +
|
"computingScores took: " +
|
||||||
|
@ -260,11 +259,22 @@ List<double> createTextEmbedding(Map args) {
|
||||||
return CLIP.createTextEmbedding(args["text"]);
|
return CLIP.createTextEmbedding(args["text"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
double computeScore(Map args) {
|
List<QueryResult> computeBulkScore(Map args) {
|
||||||
return CLIP.computeScore(
|
final queryResults = <QueryResult>[];
|
||||||
args["imageEmbedding"] as List<double>,
|
final imageEmbeddings = args["imageEmbeddings"] as List<Embedding>;
|
||||||
args["textEmbedding"] as List<double>,
|
final textEmbedding = args["textEmbedding"] as List<double>;
|
||||||
);
|
for (final imageEmbedding in imageEmbeddings) {
|
||||||
|
final score = CLIP.computeScore(
|
||||||
|
imageEmbedding.embedding,
|
||||||
|
textEmbedding,
|
||||||
|
);
|
||||||
|
if (score >= 0.23) {
|
||||||
|
queryResults.add(QueryResult(imageEmbedding.fileID, score));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
queryResults.sort((first, second) => second.score.compareTo(first.score));
|
||||||
|
return queryResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
class QueryResult {
|
class QueryResult {
|
||||||
|
|
Loading…
Add table
Reference in a new issue