From afe19064d3e8506b628de834a5f7c6bacfaab5d7 Mon Sep 17 00:00:00 2001 From: Arvin Xu Date: Fri, 30 Aug 2024 13:14:50 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20fix=20file=20relative=20c?= =?UTF-8?q?hunks=20(#3676)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🌐 chore: update i18n * 🐛 fix: fix relative files --- locales/en-US/components.json | 2 +- src/database/server/models/chunk.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/locales/en-US/components.json b/locales/en-US/components.json index 0110d9a12db3..e257f5582cd4 100644 --- a/locales/en-US/components.json +++ b/locales/en-US/components.json @@ -59,7 +59,7 @@ "status": { "error": "Chunking failed", "errorResult": "Chunking failed, please check and try again. Error detail:", - "processing": "Chunking in progress.", + "processing": "Chunking", "processingTip": "The server is splitting text chunks; closing the page will not affect the chunking progress." } } diff --git a/src/database/server/models/chunk.ts b/src/database/server/models/chunk.ts index 174f761bc2cf..0a7cd8fce6f2 100644 --- a/src/database/server/models/chunk.ts +++ b/src/database/server/models/chunk.ts @@ -171,6 +171,10 @@ export class ChunkModel { }) { const similarity = sql`1 - (${cosineDistance(embeddings.embeddings, embedding)})`; + const hasFiles = fileIds && fileIds.length > 0; + + if (!hasFiles) return []; + const result = await serverDB .select({ fileId: files.id, @@ -186,7 +190,7 @@ export class ChunkModel { .leftJoin(embeddings, eq(chunks.id, embeddings.chunkId)) .leftJoin(fileChunks, eq(chunks.id, fileChunks.chunkId)) .leftJoin(files, eq(files.id, fileChunks.fileId)) - .where(and(fileIds && fileIds.length > 0 ? inArray(fileChunks.fileId, fileIds) : undefined)) + .where(inArray(fileChunks.fileId, fileIds)) .orderBy((t) => desc(t.similarity)) .limit(5);