fix: score filter (#5645)

* fix: score filter

* chore: update score limit
This commit is contained in:
Nathan.fooo 2024-06-28 07:57:12 +08:00 committed by GitHub
parent 605a53f2ae
commit bf087bba5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -1,4 +1,5 @@
use std::sync::Arc;
use tracing::{trace, warn};
use flowy_error::FlowyResult;
use flowy_folder::{manager::FolderManager, ViewLayout};
@ -52,6 +53,7 @@ impl SearchHandler for DocumentSearchHandler {
.cloud_service
.document_search(&workspace_id, query)
.await?;
trace!("[Search] remote search results: {:?}", results);
// Grab all views from folder cache
// Notice that `get_all_view_pb` returns Views that don't include trashed and private views
@ -86,9 +88,12 @@ impl SearchHandler for DocumentSearchHandler {
workspace_id: result.workspace_id,
preview: result.preview,
});
} else {
warn!("No view found for search result: {:?}", result);
}
}
trace!("[Search] showing results: {:?}", search_results);
Ok(search_results)
}

View File

@ -11,7 +11,8 @@ pub(crate) struct AFCloudSearchCloudServiceImpl<T> {
// The limit of what the score should be for results, used to
// filter out irrelevant results.
const SCORE_LIMIT: f64 = 0.8;
// https://community.openai.com/t/rule-of-thumb-cosine-similarity-thresholds/693670/5
const SCORE_LIMIT: f64 = 0.3;
const DEFAULT_PREVIEW: u32 = 80;
#[async_trait]
@ -32,7 +33,7 @@ where
// Filter out irrelevant results
let result = result
.into_iter()
.filter(|r| r.score < SCORE_LIMIT)
.filter(|r| r.score > SCORE_LIMIT)
.collect();
Ok(result)