Skip to content

Commit

Permalink
feature: new highlight strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryanpunia authored and skeptrunedev committed Jul 26, 2024
1 parent 83a3e3b commit bfb0292
Show file tree
Hide file tree
Showing 6 changed files with 547 additions and 49 deletions.
7 changes: 7 additions & 0 deletions server/src/handlers/chunk_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,8 @@ pub struct SearchChunksReqPayload {
pub tag_weights: Option<HashMap<String, f32>>,
/// Set highlight_results to false for a slight latency improvement (1-10ms). If not specified, this defaults to true. This will add `<b><mark>` tags to the chunk_html of the chunks to highlight matching splits and return the highlights on each scored chunk in the response.
pub highlight_results: Option<bool>,
/// Set highlight_exact_match to true to highlight exact matches from your query.
pub highlight_strategy: Option<HighlightStrategy>,
/// Set highlight_threshold to a lower or higher value to adjust the sensitivity of the highlights applied to the chunk html. If not specified, this defaults to 0.8. The range is 0.0 to 1.0.
pub highlight_threshold: Option<f64>,
/// Set highlight_delimiters to a list of strings to use as delimiters for highlighting. If not specified, this defaults to ["?", ",", ".", "!"]. These are the characters that will be used to split the chunk_html into splits for highlighting. These are the characters that will be used to split the chunk_html into splits for highlighting.
Expand Down Expand Up @@ -1003,6 +1005,7 @@ impl Default for SearchChunksReqPayload {
use_weights: None,
tag_weights: None,
highlight_results: None,
highlight_strategy: None,
highlight_threshold: None,
highlight_delimiters: None,
highlight_max_length: None,
Expand Down Expand Up @@ -1277,6 +1280,8 @@ pub struct AutocompleteReqPayload {
pub tag_weights: Option<HashMap<String, f32>>,
/// Set highlight_results to false for a slight latency improvement (1-10ms). If not specified, this defaults to true. This will add `<b><mark>` tags to the chunk_html of the chunks to highlight matching splits and return the highlights on each scored chunk in the response.
pub highlight_results: Option<bool>,
/// Set highlight_exact_match to true to highlight exact matches from your query.
pub highlight_strategy: Option<HighlightStrategy>,
/// Set highlight_threshold to a lower or higher value to adjust the sensitivity of the highlights applied to the chunk html. If not specified, this defaults to 0.8. The range is 0.0 to 1.0.
pub highlight_threshold: Option<f64>,
/// Set highlight_delimiters to a list of strings to use as delimiters for highlighting. If not specified, this defaults to ["?", ",", ".", "!"]. These are the characters that will be used to split the chunk_html into splits for highlighting.
Expand Down Expand Up @@ -1312,6 +1317,7 @@ impl From<AutocompleteReqPayload> for SearchChunksReqPayload {
use_weights: autocomplete_data.use_weights,
tag_weights: autocomplete_data.tag_weights,
highlight_results: autocomplete_data.highlight_results,
highlight_strategy: autocomplete_data.highlight_strategy,
highlight_threshold: autocomplete_data.highlight_threshold,
highlight_delimiters: Some(
autocomplete_data
Expand Down Expand Up @@ -1590,6 +1596,7 @@ impl From<CountChunksReqPayload> for SearchChunksReqPayload {
use_weights: None,
tag_weights: None,
highlight_results: None,
highlight_strategy: None,
highlight_threshold: None,
highlight_delimiters: None,
highlight_max_length: None,
Expand Down
7 changes: 6 additions & 1 deletion server/src/handlers/group_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
errors::ServiceError,
middleware::api_version::APIVersion,
operators::{
chunk_operator::get_metadata_from_tracking_id_query,
chunk_operator::{get_metadata_from_tracking_id_query, HighlightStrategy},
clickhouse_operator::{get_latency_from_header, send_to_clickhouse, ClickHouseEvent},
group_operator::*,
qdrant_operator::{
Expand Down Expand Up @@ -1389,6 +1389,8 @@ pub struct SearchWithinGroupReqPayload {
pub tag_weights: Option<HashMap<String, f32>>,
/// Set highlight_results to false for a slight latency improvement (1-10ms). If not specified, this defaults to true. This will add `<b><mark>` tags to the chunk_html of the chunks to highlight matching splits and return the highlights on each scored chunk in the response.
pub highlight_results: Option<bool>,
/// Set highlight_exact_match to true to highlight exact matches from your query.
pub highlight_strategy: Option<HighlightStrategy>,
/// Set highlight_threshold to a lower or higher value to adjust the sensitivity of the highlights applied to the chunk html. If not specified, this defaults to 0.8. The range is 0.0 to 1.0.
pub highlight_threshold: Option<f64>,
/// Set highlight_delimiters to a list of strings to use as delimiters for highlighting. If not specified, this defaults to ["?", ",", ".", "!"]. These are the characters that will be used to split the chunk_html into splits for highlighting.
Expand Down Expand Up @@ -1425,6 +1427,7 @@ impl From<SearchWithinGroupReqPayload> for SearchChunksReqPayload {
use_weights: search_within_group_data.use_weights,
tag_weights: search_within_group_data.tag_weights,
highlight_results: search_within_group_data.highlight_results,
highlight_strategy: search_within_group_data.highlight_strategy,
highlight_threshold: search_within_group_data.highlight_threshold,
highlight_delimiters: search_within_group_data.highlight_delimiters,
highlight_max_length: search_within_group_data.highlight_max_length,
Expand Down Expand Up @@ -1613,6 +1616,8 @@ pub struct SearchOverGroupsReqPayload {
pub filters: Option<ChunkFilter>,
/// Set highlight_results to false for a slight latency improvement (1-10ms). If not specified, this defaults to true. This will add `<b><mark>` tags to the chunk_html of the chunks to highlight matching splits and return the highlights on each scored chunk in the response.
pub highlight_results: Option<bool>,
/// Set highlight_exact_match to true to highlight exact matches from your query.
pub highlight_strategy: Option<HighlightStrategy>,
/// Set highlight_threshold to a lower or higher value to adjust the sensitivity of the highlights applied to the chunk html. If not specified, this defaults to 0.8. The range is 0.0 to 1.0.
pub highlight_threshold: Option<f64>,
/// Set highlight_delimiters to a list of strings to use as delimiters for highlighting. If not specified, this defaults to ["?", ",", ".", "!"]. These are the characters that will be used to split the chunk_html into splits for highlighting.
Expand Down
1 change: 1 addition & 0 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ impl Modify for SecurityAddon {
operators::analytics_operator::CTRRecommendationsWithClicksResponse,
operators::analytics_operator::CTRRecommendationsWithoutClicksResponse,
handlers::analytics_handler::CTRDataRequestBody,
operators::chunk_operator::HighlightStrategy,
handlers::stripe_handler::CreateSetupCheckoutSessionResPayload,
data::models::DateRange,
data::models::FieldCondition,
Expand Down
Loading

0 comments on commit bfb0292

Please sign in to comment.