feat(server): integrate blob to context (#13491)

This commit is contained in:
DarkSky
2025-08-15 17:35:45 +08:00
committed by GitHub
parent 795bfb2f95
commit e2156ea135
5 changed files with 85 additions and 12 deletions
+6 -1
View File
@@ -67,12 +67,17 @@ export class BlobModel extends BaseModel {
});
}
async list(workspaceId: string) {
async list(
workspaceId: string,
options?: { where: Prisma.BlobWhereInput; select?: Prisma.BlobSelect }
) {
return await this.db.blob.findMany({
where: {
...options?.where,
workspaceId,
deletedAt: null,
},
select: options?.select,
});
}
@@ -6,13 +6,14 @@ import { Prisma, PrismaClient } from '@prisma/client';
import { PaginationInput } from '../base';
import { BaseModel } from './base';
import type {
BlobChunkSimilarity,
CopilotWorkspaceFile,
CopilotWorkspaceFileMetadata,
Embedding,
FileChunkSimilarity,
IgnoredDoc,
import {
type BlobChunkSimilarity,
clearEmbeddingContent,
type CopilotWorkspaceFile,
type CopilotWorkspaceFileMetadata,
type Embedding,
type FileChunkSimilarity,
type IgnoredDoc,
} from './common';
@Injectable()
@@ -413,6 +414,33 @@ export class CopilotWorkspaceConfigModel extends BaseModel {
return similarityChunks.filter(c => Number(c.distance) <= threshold);
}
async getBlobContent(
workspaceId: string,
blobId: string,
chunk?: number
): Promise<string | undefined> {
const blob = await this.db.aiWorkspaceBlobEmbedding.findMany({
where: { workspaceId, blobId, chunk },
select: { content: true },
orderBy: { chunk: 'asc' },
});
return blob?.map(f => clearEmbeddingContent(f.content)).join('\n');
}
async getBlobChunkSizes(workspaceId: string, blobIds: string[]) {
const sizes = await this.db.aiWorkspaceBlobEmbedding.groupBy({
by: ['blobId'],
_count: { chunk: true },
where: { workspaceId, blobId: { in: blobIds } },
});
return sizes.reduce((acc, cur) => {
if (cur._count.chunk) {
acc.set(cur.blobId, cur._count.chunk);
}
return acc;
}, new Map<string, number>());
}
@Transactional()
async insertBlobEmbeddings(
workspaceId: string,