Skip to content

Commit 6f0336d

Browse files
committed
Revert "feature: add not tool filter to search component"
This reverts commit 78c6c27.
1 parent 416a88f commit 6f0336d

2 files changed

Lines changed: 76 additions & 165 deletions

File tree

clients/search-component/src/utils/hooks/chat-context.tsx

Lines changed: 75 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import React, { createContext, useContext, useRef, useState } from "react";
33
import {
44
defaultPriceToolCallOptions,
5-
defaultNotFilterToolCallOptions,
65
defaultRelevanceToolCallOptions,
76
defaultSearchToolCallOptions,
87
useModalState,
@@ -491,7 +490,6 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
491490
}
492491

493492
let skipSearch = false;
494-
let notFilter = false;
495493

496494
if (
497495
props.recommendOptions?.filter &&
@@ -622,55 +620,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
622620
},
623621
});
624622
}
625-
});
626-
627-
const notFilterPromise = retryOperation(async () => {
628-
if (!curGroup && messages.length > 1) {
629-
return await trieveSDK.getToolCallFunctionParams({
630-
user_message_text: `Here's the previous message thread so far: ${messages.map(
631-
(message) => {
632-
if (
633-
message.type === "system" &&
634-
message.additional?.length &&
635-
props.type === "ecommerce"
636-
) {
637-
const chunks = message.additional
638-
.map((chunk) => {
639-
return JSON.stringify({
640-
title: chunk.metadata?.title || "",
641-
description: chunk.chunk_html || "",
642-
price: chunk.num_value
643-
? `${props.defaultCurrency || ""} ${chunk.num_value}`
644-
: "",
645-
link: chunk.link || "",
646-
});
647-
})
648-
.join("\n\n");
649-
return `\n\n${chunks}${message.text}`;
650-
} else {
651-
return `\n\n${message.text}`;
652-
}
653-
},
654-
)} \n\n${props.notFilterToolCallOptions?.userMessageTextPrefix ?? defaultNotFilterToolCallOptions.userMessageTextPrefix}: ${questionProp || currentQuestion}.`,
655-
image_url: localImageUrl ? localImageUrl : null,
656-
audio_input: curAudioBase64 ? curAudioBase64 : null,
657-
tool_function: {
658-
name: "not_filter",
659-
description:
660-
props.notFilterToolCallOptions?.toolDescription ??
661-
defaultNotFilterToolCallOptions.toolDescription,
662-
parameters: [
663-
{
664-
name: "not_filter",
665-
parameter_type: "boolean",
666-
description:
667-
"Whether or not the user is interested in the products previously shown to them. Set this to true if the user is not interested in the products they were shown or want something different.",
668-
},
669-
],
670-
},
671-
});
672-
}
673-
});
623+
})
674624

675625
const imageFiltersPromise = retryOperation(async () => {
676626
if (localImageUrl) {
@@ -709,13 +659,13 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
709659
user_message_text:
710660
questionProp || currentQuestion
711661
? `Get filters from the following messages: ${messages
712-
.slice(0, -1)
713-
.filter((message) => {
714-
return message.type == "user";
715-
})
716-
.map(
717-
(message) => `\n\n${message.text}`,
718-
)} \n\n ${questionProp || currentQuestion}`
662+
.slice(0, -1)
663+
.filter((message) => {
664+
return message.type == "user";
665+
})
666+
.map(
667+
(message) => `\n\n${message.text}`,
668+
)} \n\n ${questionProp || currentQuestion}`
719669
: null,
720670
image_url: localImageUrl ? localImageUrl : null,
721671
audio_input: curAudioBase64 ? curAudioBase64 : null,
@@ -747,19 +697,13 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
747697
}
748698
});
749699

750-
const [
751-
priceFiltersResp,
752-
imageFiltersResp,
753-
tagFiltersResp,
754-
skipSearchResp,
755-
notFilterResp,
756-
] = await Promise.all([
757-
priceFiltersPromise,
758-
imageFiltersPromise,
759-
tagFiltersPromise,
760-
skipSearchPromise,
761-
notFilterPromise,
762-
]);
700+
const [priceFiltersResp, imageFiltersResp, tagFiltersResp, skipSearchResp] =
701+
await Promise.all([
702+
priceFiltersPromise,
703+
imageFiltersPromise,
704+
tagFiltersPromise,
705+
skipSearchPromise,
706+
]);
763707

764708
if (transcribedQuery && curAudioBase64) {
765709
questionProp = transcribedQuery;
@@ -847,15 +791,6 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
847791
}
848792
}
849793

850-
if (notFilterResp?.parameters) {
851-
const notFilterParam = (notFilterResp.parameters as any)[
852-
"not_filter"
853-
];
854-
if (typeof notFilterParam === "boolean" && notFilterParam) {
855-
notFilter = true;
856-
}
857-
}
858-
859794
clearTimeout(toolCallTimeout);
860795
} catch (e) {
861796
console.error("error getting getToolCallFunctionParams", e);
@@ -889,19 +824,6 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
889824
filters.should == null
890825
) {
891826
filters = null;
892-
893-
if (notFilter) {
894-
if (filters == null) {
895-
filters = { must_not: [] };
896-
}
897-
898-
if (filters?.must_not) {
899-
filters.must_not.push({
900-
field: "group_ids",
901-
match_any: groupIdsInChat,
902-
});
903-
}
904-
}
905827
}
906828

907829
searchAbortController.current = new AbortController();
@@ -996,13 +918,13 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
996918
: null;
997919
const imageUrls = props.relevanceToolCallOptions?.includeImages
998920
? (
999-
(firstChunk?.image_urls?.filter(
1000-
(stringOrNull): stringOrNull is string =>
1001-
Boolean(stringOrNull),
1002-
) ||
1003-
[]) ??
1004-
[]
1005-
).splice(0, 1)
921+
(firstChunk?.image_urls?.filter(
922+
(stringOrNull): stringOrNull is string =>
923+
Boolean(stringOrNull),
924+
) ||
925+
[]) ??
926+
[]
927+
).splice(0, 1)
1006928
: undefined;
1007929
const jsonOfFirstChunk = {
1008930
title: (firstChunk?.metadata as any)?.title ?? "",
@@ -1194,47 +1116,47 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
11941116

11951117
if (referenceImageUrls.length > 0 || curGroup) {
11961118
if (referenceImageUrls.length == 0 && curGroup) {
1197-
const fulltextSearchPromise = trieveSDK.searchInGroup(
1198-
{
1199-
query: questionProp || currentQuestion,
1200-
search_type: "fulltext",
1201-
page_size: 10,
1202-
group_id: curGroup.id,
1203-
user_id: fingerprint,
1204-
},
1205-
searchAbortController.current.signal,
1206-
);
1207-
1208-
const chunksInGroupPromise = trieveSDK.getChunksInGroup(
1209-
{
1210-
groupId: curGroup.id,
1211-
page: 1,
1212-
},
1213-
searchAbortController.current.signal,
1214-
);
1215-
1216-
const [fulltextSearchResp, chunksInGroupResp] = await Promise.all([
1217-
fulltextSearchPromise,
1218-
chunksInGroupPromise,
1219-
]);
1220-
1221-
const chunkIds = fulltextSearchResp.chunks.map(
1222-
(score_chunk) => score_chunk.chunk.id,
1223-
);
1119+
const fulltextSearchPromise = trieveSDK.searchInGroup(
1120+
{
1121+
query: questionProp || currentQuestion,
1122+
search_type: "fulltext",
1123+
page_size: 10,
1124+
group_id: curGroup.id,
1125+
user_id: fingerprint,
1126+
},
1127+
searchAbortController.current.signal,
1128+
);
12241129

1225-
chunksInGroupResp.chunks.filter((chunk) => chunkIds.includes(chunk.id));
1130+
const chunksInGroupPromise = trieveSDK.getChunksInGroup(
1131+
{
1132+
groupId: curGroup.id,
1133+
page: 1,
1134+
},
1135+
searchAbortController.current.signal,
1136+
);
12261137

1227-
const topChunk = chunksInGroupResp.chunks[0];
1138+
const [fulltextSearchResp, chunksInGroupResp] = await Promise.all([
1139+
fulltextSearchPromise,
1140+
chunksInGroupPromise,
1141+
]);
12281142

1229-
if (topChunk) {
1230-
topChunk.image_urls?.forEach((url) => {
1231-
if (url) {
1232-
referenceImageUrls.push(url);
1233-
}
1234-
});
1235-
}
1143+
const chunkIds = fulltextSearchResp.chunks.map(
1144+
(score_chunk) => score_chunk.chunk.id,
1145+
);
1146+
1147+
chunksInGroupResp.chunks.filter((chunk) => chunkIds.includes(chunk.id));
1148+
1149+
const topChunk = chunksInGroupResp.chunks[0];
1150+
1151+
if (topChunk) {
1152+
topChunk.image_urls?.forEach((url) => {
1153+
if (url) {
1154+
referenceImageUrls.push(url);
1155+
}
1156+
});
1157+
}
12361158

1237-
referenceImageUrls.slice(0, 3);
1159+
referenceImageUrls.slice(0, 3);
12381160
}
12391161

12401162
if (await handleImageEdit()) {
@@ -1278,23 +1200,23 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
12781200
if (skipSearch) {
12791201
createMessageFilters = props.useGroupSearch
12801202
? {
1281-
must: [
1282-
{
1283-
field: "group_ids",
1284-
match_any: groupIdsInChat,
1285-
},
1286-
],
1287-
}
1203+
must: [
1204+
{
1205+
field: "group_ids",
1206+
match_any: groupIdsInChat,
1207+
},
1208+
],
1209+
}
12881210
: {
1289-
must: [
1290-
{
1291-
field: "ids",
1292-
match_any: messages
1293-
.flatMap((m) => m.additional ?? [])
1294-
.map((chunk) => chunk.id),
1295-
},
1296-
],
1297-
};
1211+
must: [
1212+
{
1213+
field: "ids",
1214+
match_any: messages
1215+
.flatMap((m) => m.additional ?? [])
1216+
.map((chunk) => chunk.id),
1217+
},
1218+
],
1219+
};
12981220
}
12991221
const systemPromptToUse =
13001222
props.systemPrompt && props.systemPrompt !== ""

clients/search-component/src/utils/hooks/modal-context.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ export interface SearchToolCallOptions {
8989
toolDescription: string;
9090
}
9191

92-
export interface NotFilterToolCallOptions {
93-
userMessageTextPrefix?: string;
94-
toolDescription: string;
95-
}
96-
97-
export const defaultNotFilterToolCallOptions: NotFilterToolCallOptions = {
98-
userMessageTextPrefix: "Here is the user query:",
99-
toolDescription:
100-
"Set to true if the query is not interested in the products they were shown previously or would like to see something different. Ensure that this is only set to true when the user wants to see something different from the previously returned results or is not interested in those previously returned results.",
101-
};
102-
10392
export const defaultSearchToolCallOptions: SearchToolCallOptions = {
10493
userMessageTextPrefix: "Here is the user query:",
10594
toolDescription:
@@ -158,6 +147,7 @@ export function isDefaultSearchQuery(
158147
return typeof question === "object" && "query" in question;
159148
}
160149

150+
161151
export type ModalProps = {
162152
datasetId: string;
163153
apiKey: string;
@@ -192,7 +182,6 @@ export type ModalProps = {
192182
relevanceToolCallOptions?: RelevanceToolCallOptions;
193183
priceToolCallOptions?: PriceToolCallOptions;
194184
searchToolCallOptions?: SearchToolCallOptions;
195-
notFilterToolCallOptions?: NotFilterToolCallOptions;
196185
defaultSearchMode?: SearchModes;
197186
usePagefind?: boolean;
198187
type?: ModalTypes;

0 commit comments

Comments
 (0)