Skip to content

Commit d2b884c

Browse files
vid277cdxker
authored andcommitted
feature: use different prompt for ecommerce suggested queries
1 parent 34bf260 commit d2b884c

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

clients/search-component/src/utils/hooks/useSuggestedQuestions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const useSuggestedQuestions = () => {
2222
: currentGroup?.tracking_id,
2323
query,
2424
props,
25+
isEcommerce: props.type === "ecommerce",
2526
});
2627
setSuggestedQuestions(queries.queries);
2728
setIsLoadingSuggestedQueries(false);

clients/search-component/src/utils/trieve.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ export const getSuggestedQuestions = async ({
431431
prevUserMessages,
432432
is_followup,
433433
chunks,
434+
isEcommerce,
434435
}: {
435436
trieve: TrieveSDK;
436437
abortController?: AbortController;
@@ -441,6 +442,7 @@ export const getSuggestedQuestions = async ({
441442
prevUserMessages?: string[];
442443
props?: ModalProps;
443444
chunks?: Chunk[] | null;
445+
isEcommerce?: boolean;
444446
}) => {
445447
let context: string;
446448
if (groupTrackingId && modalProps?.cleanGroupName) {
@@ -485,6 +487,7 @@ export const getSuggestedQuestions = async ({
485487
],
486488
},
487489
}),
490+
is_ecommerce: isEcommerce ?? false,
488491
},
489492
abortController?.signal,
490493
),

clients/ts-sdk/openapi.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22471,8 +22471,14 @@
2247122471
],
2247222472
"nullable": true
2247322473
},
22474+
"is_ecommerce": {
22475+
"type": "boolean",
22476+
"description": "Whether of not the suggested queries are being generated for ecomm. If true, the suggested queries will be generated for ecomm. If false, the suggested queries will be generated for non-ecomm.",
22477+
"nullable": true
22478+
},
2247422479
"is_followup": {
2247522480
"type": "boolean",
22481+
"description": "Whether or not the suggested queries are being generated for a followup question. If true, the suggested queries will be generated for a followup question. If false, the suggested queries will be generated for a new question.",
2247622482
"nullable": true
2247722483
},
2247822484
"query": {

clients/ts-sdk/src/types.gen.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4524,6 +4524,13 @@ export type SuggestedQueriesReqPayload = {
45244524
*/
45254525
context?: (string) | null;
45264526
filters?: ((ChunkFilter) | null);
4527+
/**
4528+
* Whether of not the suggested queries are being generated for ecomm. If true, the suggested queries will be generated for ecomm. If false, the suggested queries will be generated for non-ecomm.
4529+
*/
4530+
is_ecommerce?: (boolean) | null;
4531+
/**
4532+
* Whether or not the suggested queries are being generated for a followup question. If true, the suggested queries will be generated for a followup question. If false, the suggested queries will be generated for a new question.
4533+
*/
45274534
is_followup?: (boolean) | null;
45284535
/**
45294536
* The query to base the generated suggested queries off of using RAG. A hybrid search for 10 chunks from your dataset using this query will be performed and the context of the chunks will be used to generate the suggested queries.

server/src/handlers/message_handler.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,10 @@ pub struct SuggestedQueriesReqPayload {
829829
pub context: Option<String>,
830830
/// Filters is a JSON object which can be used to filter chunks. This is useful for when you want to filter chunks by arbitrary metadata. Unlike with tag filtering, there is a performance hit for filtering on metadata.
831831
pub filters: Option<ChunkFilter>,
832-
832+
/// Whether or not the suggested queries are being generated for a followup question. If true, the suggested queries will be generated for a followup question. If false, the suggested queries will be generated for a new question.
833833
pub is_followup: Option<bool>,
834+
/// Whether of not the suggested queries are being generated for ecommerce.
835+
pub is_ecommerce: Option<bool>,
834836
}
835837

836838
#[derive(Deserialize, Serialize, Debug, ToSchema)]

server/src/operators/message_operator.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,10 +1921,17 @@ pub async fn suggested_new_queries(
19211921
};
19221922
let context_sentence = match payload.context.clone() {
19231923
Some(context) => {
1924-
format!(
1925-
"Suggest varied {query_style} queries with the following context in mind: {}. Generate one question that requests for a comparison of two products, explicitly including these questions in the query through phrases such as 'compare, versus, different, etc...'. Another question should contain one product title, explicitly include the name of the product in the query and ask questions related to this product within the provided context. For another question, generate a question that usses the format of find me and then a broader category name that makes sense within the provided context. Ensure all queries are short and to the point.",
1926-
context
1927-
)
1924+
if payload.is_ecommerce.unwrap_or(false) {
1925+
format!(
1926+
"Suggest varied {query_style} queries with the following context in mind: {}. Generate one question that requests for a comparison of two products, explicitly including these questions in the query through phrases such as 'compare, versus, different, etc...'. Another question should contain one product title, explicitly include the name of the product in the query and ask questions related to this product within the provided context. For another question, generate a question that usses the format of find me and then a broader category name that makes sense within the provided context. Ensure all queries are short and to the point.",
1927+
context
1928+
)
1929+
} else {
1930+
format!(
1931+
"Suggest varied {query_style} queries with the following context in mind: {}. Generate queries that are short, specific, and directly related to the provided context.",
1932+
context
1933+
)
1934+
}
19281935
}
19291936
None => "".to_string(),
19301937
};

0 commit comments

Comments
 (0)