feat(server): add copilot embedding feature (#12590)

fix AI-154
This commit is contained in:
darkskygit
2025-05-28 04:36:37 +00:00
parent 88339b4022
commit f4e7595f4b
5 changed files with 9 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import { DeploymentType } from '../../env';
export enum ServerFeature {
Captcha = 'captcha',
Copilot = 'copilot',
CopilotEmbedding = 'copilot_embedding',
Payment = 'payment',
OAuth = 'oauth',
Indexer = 'indexer',

View File

@@ -232,8 +232,8 @@ export class CopilotWorkspaceConfigModel extends BaseModel {
async checkEmbeddingAvailable(): Promise<boolean> {
const [{ count }] = await this.db.$queryRaw<
{ count: number }[]
>`SELECT count(1) FROM pg_tables WHERE tablename in ('ai_workspace_file_embeddings')`;
return Number(count) === 1;
>`SELECT count(1) FROM pg_tables WHERE tablename in ('ai_workspace_embeddings', 'ai_workspace_file_embeddings')`;
return Number(count) === 2;
}
private processEmbeddings(

View File

@@ -3,6 +3,7 @@ import { createHash } from 'node:crypto';
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
import { FileUpload, JobQueue, PaginationInput } from '../../../base';
import { ServerFeature, ServerService } from '../../../core';
import { Models } from '../../../models';
import { CopilotStorage } from '../storage';
import { readStream } from '../utils';
@@ -12,6 +13,7 @@ export class CopilotWorkspaceService implements OnApplicationBootstrap {
private supportEmbedding = false;
constructor(
private readonly server: ServerService,
private readonly models: Models,
private readonly queue: JobQueue,
private readonly storage: CopilotStorage
@@ -19,8 +21,9 @@ export class CopilotWorkspaceService implements OnApplicationBootstrap {
async onApplicationBootstrap() {
const supportEmbedding =
await this.models.copilotContext.checkEmbeddingAvailable();
await this.models.copilotWorkspace.checkEmbeddingAvailable();
if (supportEmbedding) {
this.server.enableFeature(ServerFeature.CopilotEmbedding);
this.supportEmbedding = true;
}
}

View File

@@ -1606,6 +1606,7 @@ enum ServerDeploymentType {
enum ServerFeature {
Captcha
Copilot
CopilotEmbedding
Indexer
OAuth
Payment