Skip to content

Commit

Permalink
🐛 fix: fix file relative chunks (lobehub#3676)
Browse files Browse the repository at this point in the history
* 🌐 chore: update i18n

* 🐛 fix: fix relative files
  • Loading branch information
arvinxx authored Aug 30, 2024
1 parent fe62aee commit afe1906
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion locales/en-US/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/database/server/models/chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ export class ChunkModel {
}) {
const similarity = sql<number>`1 - (${cosineDistance(embeddings.embeddings, embedding)})`;

const hasFiles = fileIds && fileIds.length > 0;

if (!hasFiles) return [];

const result = await serverDB
.select({
fileId: files.id,
Expand All @@ -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);

Expand Down

0 comments on commit afe1906

Please sign in to comment.