mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-23 20:18:42 +08:00
feat(server): workspace embedding status count with files (#12420)
fix AI-32 fix AI-132
This commit is contained in:
@@ -144,6 +144,37 @@ export class CopilotWorkspaceConfigModel extends BaseModel {
|
|||||||
return docIds.filter(id => ignored.has(id));
|
return docIds.filter(id => ignored.has(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional()
|
||||||
|
async getWorkspaceEmbeddingStatus(workspaceId: string) {
|
||||||
|
const ignoredDocIds = (await this.listIgnoredDocIds(workspaceId)).map(
|
||||||
|
d => d.docId
|
||||||
|
);
|
||||||
|
const snapshotCondition = {
|
||||||
|
workspaceId,
|
||||||
|
AND: [
|
||||||
|
{ id: { notIn: ignoredDocIds } },
|
||||||
|
{ id: { not: workspaceId } },
|
||||||
|
{ id: { not: { contains: '$' } } },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const [docTotal, docEmbedded, fileTotal, fileEmbedded] = await Promise.all([
|
||||||
|
this.db.snapshot.count({ where: snapshotCondition }),
|
||||||
|
this.db.snapshot.count({
|
||||||
|
where: { ...snapshotCondition, embedding: { some: {} } },
|
||||||
|
}),
|
||||||
|
this.db.aiWorkspaceFiles.count({ where: { workspaceId } }),
|
||||||
|
this.db.aiWorkspaceFiles.count({
|
||||||
|
where: { workspaceId, embeddings: { some: {} } },
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
total: docTotal + fileTotal,
|
||||||
|
embedded: docEmbedded + fileEmbedded,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// ================ embeddings ================
|
// ================ embeddings ================
|
||||||
|
|
||||||
async checkEmbeddingAvailable(): Promise<boolean> {
|
async checkEmbeddingAvailable(): Promise<boolean> {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import {
|
|||||||
ResolveField,
|
ResolveField,
|
||||||
Resolver,
|
Resolver,
|
||||||
} from '@nestjs/graphql';
|
} from '@nestjs/graphql';
|
||||||
import { PrismaClient } from '@prisma/client';
|
|
||||||
import type { Request } from 'express';
|
import type { Request } from 'express';
|
||||||
import { SafeIntResolver } from 'graphql-scalars';
|
import { SafeIntResolver } from 'graphql-scalars';
|
||||||
import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
|
import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
|
||||||
@@ -241,12 +240,12 @@ class ContextMatchedDocChunk implements DocChunkSimilarity {
|
|||||||
@Resolver(() => CopilotType)
|
@Resolver(() => CopilotType)
|
||||||
export class CopilotContextRootResolver {
|
export class CopilotContextRootResolver {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly db: PrismaClient,
|
|
||||||
private readonly ac: AccessController,
|
private readonly ac: AccessController,
|
||||||
private readonly event: EventBus,
|
private readonly event: EventBus,
|
||||||
private readonly mutex: RequestMutex,
|
private readonly mutex: RequestMutex,
|
||||||
private readonly chatSession: ChatSessionService,
|
private readonly chatSession: ChatSessionService,
|
||||||
private readonly context: CopilotContextService
|
private readonly context: CopilotContextService,
|
||||||
|
private readonly models: Models
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
private async checkChatSession(
|
private async checkChatSession(
|
||||||
@@ -369,10 +368,10 @@ export class CopilotContextRootResolver {
|
|||||||
.assert('Workspace.Copilot');
|
.assert('Workspace.Copilot');
|
||||||
|
|
||||||
if (this.context.canEmbedding) {
|
if (this.context.canEmbedding) {
|
||||||
const total = await this.db.snapshot.count({ where: { workspaceId } });
|
const { total, embedded } =
|
||||||
const embedded = await this.db.snapshot.count({
|
await this.models.copilotWorkspace.getWorkspaceEmbeddingStatus(
|
||||||
where: { workspaceId, embedding: { some: {} } },
|
workspaceId
|
||||||
});
|
);
|
||||||
return { total, embedded };
|
return { total, embedded };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user