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:
darkskygit
2025-05-21 10:51:35 +00:00
parent c9b296c896
commit 7fd3ee957f
5 changed files with 41 additions and 20 deletions

View File

@@ -371,7 +371,7 @@ export class CopilotContextRootResolver {
if (this.context.canEmbedding) {
const total = await this.db.snapshot.count({ where: { workspaceId } });
const embedded = await this.db.snapshot.count({
where: { workspaceId, embedding: { isNot: null } },
where: { workspaceId, embedding: { some: {} } },
});
return { total, embedded };
}