mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 18:16:15 +08:00
fix(server): embedding chunks primary key (#12416)
fix AI-131 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Updated database schema to consolidate unique constraints into composite primary keys for embedding-related data, improving consistency. - Changed the relation in the Snapshot model to allow multiple embeddings. - Improved filtering logic for documents and snapshots based on embedding existence. - Reformatted SQL queries and schema attributes for improved readability; no changes to functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -210,9 +210,12 @@ export class CopilotContextModel extends BaseModel {
|
||||
);
|
||||
await this.db.$executeRaw`
|
||||
INSERT INTO "ai_workspace_embeddings"
|
||||
("workspace_id", "doc_id", "chunk", "content", "embedding", "updated_at") VALUES ${values}
|
||||
ON CONFLICT (workspace_id, doc_id, chunk) DO UPDATE SET
|
||||
embedding = EXCLUDED.embedding, updated_at = excluded.updated_at;
|
||||
("workspace_id", "doc_id", "chunk", "content", "embedding", "updated_at")
|
||||
VALUES ${values}
|
||||
ON CONFLICT (workspace_id, doc_id, chunk)
|
||||
DO UPDATE SET
|
||||
embedding = EXCLUDED.embedding,
|
||||
updated_at = excluded.updated_at;
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ export class CopilotWorkspaceConfigModel extends BaseModel {
|
||||
where: {
|
||||
workspaceId,
|
||||
embedding: {
|
||||
is: null,
|
||||
none: {},
|
||||
},
|
||||
},
|
||||
select: { id: true },
|
||||
|
||||
Reference in New Issue
Block a user