Skip to content

Commit 3dd319a

Browse files
vid277cdxker
authored andcommitted
feature: fetch top chunks in group for reference images
1 parent 213f3ca commit 3dd319a

File tree

2 files changed

+53
-23
lines changed

2 files changed

+53
-23
lines changed

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

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,21 +1116,47 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
11161116

11171117
if (referenceImageUrls.length > 0 || curGroup) {
11181118
if (referenceImageUrls.length == 0 && curGroup) {
1119-
const chunksInGroupPromise = await trieveSDK.getChunksInGroup(
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+
);
1129+
1130+
const chunksInGroupPromise = trieveSDK.getChunksInGroup(
11201131
{
11211132
groupId: curGroup.id,
11221133
page: 1,
11231134
},
11241135
searchAbortController.current.signal,
11251136
);
11261137

1127-
if (chunksInGroupPromise.chunks[0].image_urls) {
1128-
chunksInGroupPromise.chunks[0].image_urls.forEach((url) => {
1129-
referenceImageUrls.push(url ?? "");
1138+
const [fulltextSearchResp, chunksInGroupResp] = await Promise.all([
1139+
fulltextSearchPromise,
1140+
chunksInGroupPromise,
1141+
]);
1142+
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+
}
11301156
});
11311157
}
11321158

1133-
referenceImageUrls.slice(0, 5);
1159+
referenceImageUrls.slice(0, 3);
11341160
}
11351161

11361162
if (await handleImageEdit()) {

frontends/shared/ui/MultiStringInput.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createEffect, For, Show } from "solid-js";
1+
import { For, Show } from "solid-js";
22
import { createStore } from "solid-js/store";
33
import { cn } from "../utils";
44
import { FiPlus, FiX } from "solid-icons/fi";
@@ -29,14 +29,29 @@ export const MultiStringInput = (props: MultiStringInputProps) => {
2929
})),
3030
);
3131

32-
createEffect(() => {
32+
const updateValue = (id: string, value: string) => {
33+
setProxyStore((v) => v.id == id, "value", value);
3334
props.onChange(
3435
proxyStore.map((item) => item.value).filter((i) => i !== ""),
3536
);
36-
});
37+
};
3738

38-
const updateValue = (id: string, value: string) => {
39-
setProxyStore((v) => v.id == id, "value", value);
39+
const removeValue = (id: string) => {
40+
if (proxyStore.length === 1) {
41+
updateValue(id, "");
42+
} else {
43+
setProxyStore((v) => v.filter((item) => item.id != id));
44+
props.onChange(
45+
proxyStore.map((item) => item.value).filter((i) => i !== ""),
46+
);
47+
}
48+
};
49+
50+
const addValue = () => {
51+
setProxyStore((v) => [
52+
...v,
53+
{ value: "", id: Math.random().toString(36).slice(2) },
54+
]);
4055
};
4156

4257
return (
@@ -60,13 +75,7 @@ export const MultiStringInput = (props: MultiStringInputProps) => {
6075
type="button"
6176
disabled={props.disabled}
6277
class="text-neutral-400 hover:text-neutral-500 dark:text-neutral-300 dark:hover:text-neutral-400"
63-
onClick={() => {
64-
if (proxyStore.length === 1) {
65-
updateValue(entry.id, "");
66-
} else {
67-
setProxyStore((v) => v.filter((item) => item.id != entry.id));
68-
}
69-
}}
78+
onClick={() => removeValue(entry.id)}
7079
>
7180
<FiX />
7281
</button>
@@ -77,12 +86,7 @@ export const MultiStringInput = (props: MultiStringInputProps) => {
7786
type="button"
7887
disabled={props.disabled}
7988
class={cn("flex gap-2 items-center justify-center", props.addClass)}
80-
onClick={() => {
81-
setProxyStore((v) => [
82-
...v,
83-
{ value: "", id: Math.random().toString(36).slice(2) },
84-
]);
85-
}}
89+
onClick={addValue}
8690
>
8791
<Show when={props.addLabel}>{props.addLabel}</Show>
8892
<FiPlus />

0 commit comments

Comments
 (0)