Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ› fix: fix file relative chunks #3676

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading