anhuiqiang 1 неделя назад
Родитель
Сommit
08ea4230c4
2 измененных файлов с 63 добавлено и 63 удалено
  1. 26 26
      server/src/chat/chat.controller.ts
  2. 37 37
      server/src/knowledge-base/chunk-config.service.ts

+ 26 - 26
server/src/chat/chat.controller.ts

@@ -18,19 +18,19 @@ class StreamChatDto {
   history: ChatMessage[];
   userLanguage?: string;
   selectedEmbeddingId?: string;
-  selectedLLMId?: string; 
-  selectedGroups?: string[]; 
-  selectedFiles?: string[]; 
-  historyId?: string; 
-  enableRerank?: boolean; 
-  selectedRerankId?: string; 
-  temperature?: number; 
-  maxTokens?: number; 
-  topK?: number; 
-  similarityThreshold?: number; 
-  rerankSimilarityThreshold?: number; 
-  enableQueryExpansion?: boolean; 
-  enableHyDE?: boolean; 
+  selectedLLMId?: string;
+  selectedGroups?: string[];
+  selectedFiles?: string[];
+  historyId?: string;
+  enableRerank?: boolean;
+  selectedRerankId?: string;
+  temperature?: number;
+  maxTokens?: number;
+  topK?: number;
+  similarityThreshold?: number;
+  rerankSimilarityThreshold?: number;
+  enableQueryExpansion?: boolean;
+  enableHyDE?: boolean;
 }
 
 @Controller('chat')
@@ -73,7 +73,7 @@ export class ChatController {
       const role = req.user.role;
       const tenantId = req.user.tenantId;
 
-      
+
       let models = await this.modelConfigService.findAll(userId, tenantId);
 
       if (role !== 'SUPER_ADMIN') {
@@ -91,10 +91,10 @@ export class ChatController {
       } else {
         // Use organization's default LLM from Index Chat Config (strict)
         llmModel = await this.modelConfigService.findDefaultByType(tenantId, ModelType.LLM);
-        console.log('Final LLM model used (default):', llmModel ? llmModel.name : '');
+        console.log('Final LLM model used (default):', llmModel ? llmModel.name : 'None');
       }
 
-      
+
       res.setHeader('Content-Type', 'text/event-stream');
       res.setHeader('Cache-Control', 'no-cache');
       res.setHeader('Connection', 'keep-alive');
@@ -116,18 +116,18 @@ export class ChatController {
         llmModel as any,
         userLanguage,
         selectedEmbeddingId,
-        selectedGroups, 
-        selectedFiles, 
-        historyId, 
+        selectedGroups,
+        selectedFiles,
+        historyId,
         enableRerank,
         selectedRerankId,
-        temperature, 
-        maxTokens, 
-        topK, 
-        similarityThreshold, 
-        rerankSimilarityThreshold, 
-        enableQueryExpansion, 
-        enableHyDE, 
+        temperature,
+        maxTokens,
+        topK,
+        similarityThreshold,
+        rerankSimilarityThreshold,
+        enableQueryExpansion,
+        enableHyDE,
         req.user.tenantId // Pass tenant ID
       );
 

+ 37 - 37
server/src/knowledge-base/chunk-config.service.ts

@@ -20,18 +20,18 @@ import { I18nService } from '../i18n/i18n.service';
 export class ChunkConfigService {
   private readonly logger = new Logger(ChunkConfigService.name);
 
-  
+
   private readonly DEFAULTS = {
     chunkSize: DEFAULT_CHUNK_SIZE,
     chunkOverlap: DEFAULT_CHUNK_OVERLAP,
     minChunkSize: MIN_CHUNK_SIZE,
     minChunkOverlap: MIN_CHUNK_OVERLAP,
-    maxOverlapRatio: DEFAULT_MAX_OVERLAP_RATIO,  
-    maxBatchSize: DEFAULT_MAX_BATCH_SIZE,    
-    expectedDimensions: DEFAULT_VECTOR_DIMENSIONS, 
+    maxOverlapRatio: DEFAULT_MAX_OVERLAP_RATIO,
+    maxBatchSize: DEFAULT_MAX_BATCH_SIZE,
+    expectedDimensions: DEFAULT_VECTOR_DIMENSIONS,
   };
 
-  
+
   private readonly envMaxChunkSize: number;
   private readonly envMaxOverlapSize: number;
 
@@ -42,7 +42,7 @@ export class ChunkConfigService {
     private tenantService: TenantService,
     private userSettingService: UserSettingService,
   ) {
-    
+
     this.envMaxChunkSize = parseInt(
       this.configService.get<string>('MAX_CHUNK_SIZE', '8191')
     );
@@ -55,7 +55,7 @@ export class ChunkConfigService {
     );
   }
 
-  
+
   async getModelLimits(modelId: string, userId: string, tenantId?: string): Promise<{
     maxInputTokens: number;
     maxBatchSize: number;
@@ -69,20 +69,20 @@ export class ChunkConfigService {
       throw new BadRequestException(this.i18nService.formatMessage('embeddingModelNotFound', { id: modelId }));
     }
 
-    
+
     const maxInputTokens = modelConfig.maxInputTokens || this.envMaxChunkSize;
     const maxBatchSize = modelConfig.maxBatchSize || this.DEFAULTS.maxBatchSize;
     const expectedDimensions = modelConfig.dimensions || parseInt(this.configService.get('DEFAULT_VECTOR_DIMENSIONS', String(this.DEFAULTS.expectedDimensions)));
-    const providerName = modelConfig.providerName || '不明';
+    const providerName = modelConfig.providerName || 'Unknown';
     const isVectorModel = modelConfig.isVectorModel || false;
 
     this.logger.log(
       this.i18nService.formatMessage('configLoaded', { name: modelConfig.name, id: modelConfig.modelId }) + '\n' +
-      `  - プロバイダー: ${providerName}\n` +
-      `  - Token制限: ${maxInputTokens}\n` +
+      `  - Provider: ${providerName}\n` +
+      `  - Token Limit: ${maxInputTokens}\n` +
       `  - Batch Limit: ${maxBatchSize}\n` +
       `  - Vector Dimensions: ${expectedDimensions}\n` +
-      `  - ベクトルモデルか: ${isVectorModel}`,
+      `  - Is Vector Model: ${isVectorModel}`,
     );
 
     return {
@@ -94,7 +94,7 @@ export class ChunkConfigService {
     };
   }
 
-  
+
   async validateChunkConfig(
     chunkSize: number,
     chunkOverlap: number,
@@ -111,7 +111,7 @@ export class ChunkConfigService {
     const warnings: string[] = [];
     const limits = await this.getModelLimits(modelId, userId, tenantId);
 
-    
+
     const effectiveMaxChunkSize = Math.min(
       this.envMaxChunkSize,
       limits.maxInputTokens,
@@ -122,7 +122,7 @@ export class ChunkConfigService {
       Math.floor(effectiveMaxChunkSize * this.DEFAULTS.maxOverlapRatio),
     );
 
-    
+
     if (chunkSize > effectiveMaxChunkSize) {
       const reason =
         this.envMaxChunkSize < limits.maxInputTokens
@@ -139,7 +139,7 @@ export class ChunkConfigService {
       chunkSize = effectiveMaxChunkSize;
     }
 
-    
+
     if (chunkSize < this.DEFAULTS.minChunkSize) {
       warnings.push(
         this.i18nService.formatMessage('chunkUnderflow', {
@@ -150,7 +150,7 @@ export class ChunkConfigService {
       chunkSize = this.DEFAULTS.minChunkSize;
     }
 
-    
+
     if (chunkOverlap > effectiveMaxOverlapSize) {
       warnings.push(
         this.i18nService.formatMessage('overlapOverflow', {
@@ -161,7 +161,7 @@ export class ChunkConfigService {
       chunkOverlap = effectiveMaxOverlapSize;
     }
 
-    
+
     const maxOverlapByRatio = Math.floor(
       chunkSize * this.DEFAULTS.maxOverlapRatio,
     );
@@ -185,9 +185,9 @@ export class ChunkConfigService {
       chunkOverlap = this.DEFAULTS.minChunkOverlap;
     }
 
-    
-    
-    const safetyMargin = 0.8; 
+
+
+    const safetyMargin = 0.8;
     const safeChunkSize = Math.floor(effectiveMaxChunkSize * safetyMargin);
 
     if (chunkSize > safeChunkSize) {
@@ -200,9 +200,9 @@ export class ChunkConfigService {
       );
     }
 
-    
+
     const estimatedChunkCount = this.estimateChunkCount(
-      1000000, 
+      1000000,
       chunkSize,
     );
 
@@ -221,7 +221,7 @@ export class ChunkConfigService {
     };
   }
 
-  
+
   async getRecommendedBatchSize(
     modelId: string,
     userId: string,
@@ -230,11 +230,11 @@ export class ChunkConfigService {
   ): Promise<number> {
     const limits = await this.getModelLimits(modelId, userId, tenantId);
 
-    
+
     const recommended = Math.min(
       currentBatchSize,
       limits.maxBatchSize,
-      200, 
+      200,
     );
 
     if (recommended < currentBatchSize) {
@@ -247,16 +247,16 @@ export class ChunkConfigService {
       );
     }
 
-    return Math.max(10, recommended); 
+    return Math.max(10, recommended);
   }
 
-  
+
   estimateChunkCount(textLength: number, chunkSize: number): number {
     const chunkSizeInChars = chunkSize * 4; // 1 token ≈ 4 chars
     return Math.ceil(textLength / chunkSizeInChars);
   }
 
-  
+
   async validateDimensions(
     modelId: string,
     userId: string,
@@ -279,7 +279,7 @@ export class ChunkConfigService {
     return true;
   }
 
-  
+
   async getConfigSummary(
     chunkSize: number,
     chunkOverlap: number,
@@ -291,14 +291,14 @@ export class ChunkConfigService {
 
     return [
       `Model: ${modelId}`,
-      `Chunk size: ${chunkSize} tokens (制限: ${limits.maxInputTokens})`,
-      `重なりサイズ: ${chunkOverlap} tokens`,
-      `バッチサイズ: ${limits.maxBatchSize}`,
+      `Chunk size: ${chunkSize} tokens (Limit: ${limits.maxInputTokens})`,
+      `Overlap size: ${chunkOverlap} tokens`,
+      `Batch size: ${limits.maxBatchSize}`,
       `Vector Dimensions: ${limits.expectedDimensions}`,
     ].join(', ');
   }
 
-  
+
   async getFrontendLimits(
     modelId: string,
     userId: string,
@@ -318,18 +318,18 @@ export class ChunkConfigService {
   }> {
     const limits = await this.getModelLimits(modelId, userId, tenantId);
 
-    
+
     const maxChunkSize = Math.min(this.envMaxChunkSize, limits.maxInputTokens);
     const maxOverlapSize = Math.min(
       this.envMaxOverlapSize,
       Math.floor(maxChunkSize * this.DEFAULTS.maxOverlapRatio),
     );
 
-    
+
     const modelConfig = await this.modelConfigService.findOne(modelId, userId, tenantId || '');
     const modelName = modelConfig?.name || 'Unknown';
 
-    
+
     let defaultChunkSize = this.DEFAULTS.chunkSize;
     let defaultOverlapSize = this.DEFAULTS.chunkOverlap;