Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Hybrid & vector search options #651

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ pub enum MatchingStrategies {
FREQUENCY,
}

/// Hybrid search options.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HybridSearch {
pub semantic_ratio: f64,
pub embedder: String,
}

/// A single result.
///
/// Contains the complete object, optionally the formatted object, and optionally an object that contains information about the matches.
Expand Down Expand Up @@ -347,14 +355,22 @@ pub struct SearchQuery<'a, Http: HttpClient> {
#[serde(skip_serializing_if = "Option::is_none")]
pub matching_strategy: Option<MatchingStrategies>,

///Defines one attribute in the filterableAttributes list as a distinct attribute.
/// Defines one attribute in the filterableAttributes list as a distinct attribute.
#[serde(skip_serializing_if = "Option::is_none")]
pub distinct: Option<&'a str>,

///Excludes results below the specified ranking score.
/// Excludes results below the specified ranking score.
#[serde(skip_serializing_if = "Option::is_none")]
pub ranking_score_threshold: Option<f64>,

/// Defines hybrid search options.
#[serde(skip_serializing_if = "Option::is_none")]
pub hybrid: Option<HybridSearch>,

/// Defines a custom embedding vector.
#[serde(skip_serializing_if = "Option::is_none")]
pub vector: Option<Vec<f64>>,

/// Defines the language of the search query.
#[serde(skip_serializing_if = "Option::is_none")]
pub locales: Option<&'a [&'a str]>,
Expand Down Expand Up @@ -392,6 +408,8 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
index_uid: None,
distinct: None,
ranking_score_threshold: None,
hybrid: None,
vector: None,
locales: None,
}
}
Expand Down Expand Up @@ -596,6 +614,20 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
self.ranking_score_threshold = Some(ranking_score_threshold);
self
}
pub fn with_hybrid_search<'b>(
&'b mut self,
hybrid: HybridSearch,
) -> &'b mut SearchQuery<'a, Http> {
self.hybrid = Some(hybrid);
self
}
pub fn with_custom_embedding_vector<'b>(
&'b mut self,
vector: Vec<f64>,
) -> &'b mut SearchQuery<'a, Http> {
self.vector = Some(vector);
self
}
pub fn with_locales<'b>(&'b mut self, locales: &'a [&'a str]) -> &'b mut SearchQuery<'a, Http> {
self.locales = Some(locales);
self
Expand Down