From 6dd196c067bc2e0cdc512ad6d9061b22505c632f Mon Sep 17 00:00:00 2001 From: LOSSES Don <1384036+Losses@users.noreply.github.com> Date: Tue, 3 Dec 2024 11:49:44 +0800 Subject: [PATCH] fix: Fix #148 --- database/src/actions/recommendation.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/database/src/actions/recommendation.rs b/database/src/actions/recommendation.rs index 626b62a04..0dc41abe2 100644 --- a/database/src/actions/recommendation.rs +++ b/database/src/actions/recommendation.rs @@ -4,6 +4,7 @@ use std::num::NonZeroUsize; use anyhow::{bail, Context, Result}; use arroy::distances::Euclidean; use arroy::{Reader, Writer}; +use log::error; use rand::rngs::StdRng; use rand::SeedableRng; use rust_decimal::prelude::ToPrimitive; @@ -71,12 +72,20 @@ pub fn get_recommendation_by_parameter( let results = reader .nns_by_vector(&rtxn, &feature_vector, n, Some(search_k), None) - .with_context(|| "Failed to get recommendation by parameter")?; - - if results.is_empty() { - bail!("No results found for the given parameter") - } else { - Ok(results) + .with_context(|| "Failed to get recommendation by parameter"); + + match results { + Ok(results) => { + if results.is_empty() { + bail!("No results found for the given parameter") + } else { + Ok(results) + } + } + Err(e) => { + error!("{:#?}", e); + Ok(vec![]) + } } }