fix: Spaces filter not working

This commit is contained in:
Dhravya 2024-06-29 01:02:04 -05:00
parent 610360dffd
commit 3754b2c2c8
5 changed files with 25 additions and 18 deletions

View file

@ -64,6 +64,7 @@ app.post("/api/add", zValidator("json", vectorObj), async (c) => {
const { store } = await initQuery(c);
console.log(body.spaces);
await batchCreateChunksAndEmbeddings({
store,
body,
@ -354,6 +355,7 @@ app.post(
}
const spaces = query.spaces?.split(",") ?? [undefined];
console.log(spaces);
// Get the AI model maker and vector store
const { model, store } = await initQuery(c, query.model);
@ -372,8 +374,11 @@ app.post(
// SLICED to 5 to avoid too many queries
for (const space of spaces.slice(0, 5)) {
console.log("space", space);
if (!space && spaces.length > 1) {
if (space && space.length >= 1) {
console.log(
"this is the key being used",
`space-${query.user}-${space}`,
);
// it's possible for space list to be [undefined] so we only add space filter conditionally
filter[`space-${query.user}-${space}`] = 1;
}

View file

@ -28,7 +28,7 @@ async function Page({
return (
<ChatWindow
q={q}
spaces={spaces}
spaces={spaces ?? []}
initialChat={chat.data.length > 0 ? chat.data : undefined}
threadId={params.chatid}
/>

View file

@ -41,7 +41,7 @@ function ChatWindow({
threadId,
}: {
q: string;
spaces: { id: string; name: string }[];
spaces: { id: number; name: string }[];
initialChat?: ChatHistory[];
threadId: string;
}) {
@ -179,7 +179,7 @@ function ChatWindow({
if (startGenerating) {
getAnswer(
q,
spaces.map((s) => `${s}`),
spaces.map((s) => `${s.id}`),
);
}
} else {

View file

@ -181,6 +181,7 @@ export const createMemory = async (input: {
storeToSpaces = [];
}
console.log(storeToSpaces);
const vectorSaveResponse = await fetch(
`${process.env.BACKEND_BASE_URL}/api/add`,
{

View file

@ -15,20 +15,21 @@ export const homeSearchParamsCache = createSearchParamsCache({
export const chatSearchParamsCache = createSearchParamsCache({
firstTime: parseAsBoolean.withDefault(false),
q: parseAsString.withDefault(""),
spaces: parseAsArrayOf(
parseAsJson((c) => {
const valid = z
.object({
id: z.string(),
spaces: parseAsJson((c) => {
const valid = z
.array(
z.object({
id: z.number(),
name: z.string(),
})
.safeParse(c);
}),
)
.safeParse(c);
if (!valid.success) {
return null;
}
if (!valid.success) {
console.log("invalid spaces", valid.error);
return null;
}
return valid.data;
}),
).withDefault([]),
return valid.data;
}),
});