File tree Expand file tree Collapse file tree 5 files changed +43
-34
lines changed
packages/backend/server/src Expand file tree Collapse file tree 5 files changed +43
-34
lines changed Original file line number Diff line number Diff line change @@ -148,3 +148,36 @@ export type IgnoredDoc = {
148
148
createdByAvatar : string | undefined ;
149
149
updatedBy : string | undefined ;
150
150
} ;
151
+
152
+ export const EMBEDDING_DIMENSIONS = 1024 ;
153
+
154
+ const FILTER_PREFIX = [
155
+ 'Title: ' ,
156
+ 'Created at: ' ,
157
+ 'Updated at: ' ,
158
+ 'Created by: ' ,
159
+ 'Updated by: ' ,
160
+ ] ;
161
+
162
+ export function clearEmbeddingContent ( content : string ) : string {
163
+ const lines = content . split ( '\n' ) ;
164
+ let maxLines = 5 ;
165
+ while ( maxLines > 0 && lines . length > 0 ) {
166
+ if ( FILTER_PREFIX . some ( prefix => lines [ 0 ] . startsWith ( prefix ) ) ) {
167
+ lines . shift ( ) ;
168
+ maxLines -- ;
169
+ } else {
170
+ // only process consecutive metadata rows
171
+ break ;
172
+ }
173
+ }
174
+ return lines . join ( '\n' ) ;
175
+ }
176
+
177
+ export function clearEmbeddingChunk ( chunk : ChunkSimilarity ) : ChunkSimilarity {
178
+ if ( chunk . content ) {
179
+ const content = clearEmbeddingContent ( chunk . content ) ;
180
+ return { ...chunk , content } ;
181
+ }
182
+ return chunk ;
183
+ }
Original file line number Diff line number Diff line change @@ -6,21 +6,21 @@ import { Prisma } from '@prisma/client';
6
6
import { CopilotSessionNotFound } from '../base' ;
7
7
import { BaseModel } from './base' ;
8
8
import {
9
+ clearEmbeddingContent ,
9
10
ContextBlob ,
10
11
ContextConfigSchema ,
11
12
ContextDoc ,
12
13
ContextEmbedStatus ,
13
14
CopilotContext ,
14
15
DocChunkSimilarity ,
15
16
Embedding ,
17
+ EMBEDDING_DIMENSIONS ,
16
18
FileChunkSimilarity ,
17
19
MinimalContextConfigSchema ,
18
20
} from './common/copilot' ;
19
21
20
22
type UpdateCopilotContextInput = Pick < CopilotContext , 'config' > ;
21
23
22
- export const EMBEDDING_DIMENSIONS = 1024 ;
23
-
24
24
/**
25
25
* Copilot Job Model
26
26
*/
@@ -215,7 +215,7 @@ export class CopilotContextModel extends BaseModel {
215
215
select : { content : true } ,
216
216
orderBy : { chunk : 'asc' } ,
217
217
} ) ;
218
- return file ?. map ( f => f . content ) . join ( '\n' ) ;
218
+ return file ?. map ( f => clearEmbeddingContent ( f . content ) ) . join ( '\n' ) ;
219
219
}
220
220
221
221
async insertFileEmbedding (
@@ -274,7 +274,7 @@ export class CopilotContextModel extends BaseModel {
274
274
select : { content : true } ,
275
275
orderBy : { chunk : 'asc' } ,
276
276
} ) ;
277
- return file ?. map ( f => f . content ) . join ( '\n' ) ;
277
+ return file ?. map ( f => clearEmbeddingContent ( f . content ) ) . join ( '\n' ) ;
278
278
}
279
279
280
280
async insertWorkspaceEmbedding (
Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ import z from 'zod';
6
6
7
7
import { DocReader } from '../../../core/doc' ;
8
8
import { AccessController } from '../../../core/permission' ;
9
+ import { clearEmbeddingChunk } from '../../../models' ;
9
10
import { IndexerService } from '../../indexer' ;
10
11
import { CopilotContextService } from '../context' ;
11
- import { clearEmbeddingChunk } from '../utils' ;
12
12
13
13
@Injectable ( )
14
14
export class WorkspaceMcpProvider {
Original file line number Diff line number Diff line change @@ -3,11 +3,14 @@ import { omit } from 'lodash-es';
3
3
import { z } from 'zod' ;
4
4
5
5
import type { AccessController } from '../../../core/permission' ;
6
- import type { ChunkSimilarity , Models } from '../../../models' ;
6
+ import {
7
+ type ChunkSimilarity ,
8
+ clearEmbeddingChunk ,
9
+ type Models ,
10
+ } from '../../../models' ;
7
11
import type { CopilotContextService } from '../context' ;
8
12
import type { ContextSession } from '../context/session' ;
9
13
import type { CopilotChatOptions } from '../providers' ;
10
- import { clearEmbeddingChunk } from '../utils' ;
11
14
import { toolError } from './error' ;
12
15
13
16
export const buildDocSearchGetter = (
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ import { Readable } from 'node:stream';
3
3
import type { Request } from 'express' ;
4
4
5
5
import { OneMB , readBufferWithLimit } from '../../base' ;
6
- import type { ChunkSimilarity } from '../../models' ;
7
6
import type { PromptTools } from './providers' ;
8
7
import type { ToolsConfig } from './types' ;
9
8
@@ -83,29 +82,3 @@ export function getTools(
83
82
} ) ;
84
83
return result ;
85
84
}
86
-
87
- const FILTER_PREFIX = [
88
- 'Title: ' ,
89
- 'Created at: ' ,
90
- 'Updated at: ' ,
91
- 'Created by: ' ,
92
- 'Updated by: ' ,
93
- ] ;
94
-
95
- export function clearEmbeddingChunk ( chunk : ChunkSimilarity ) : ChunkSimilarity {
96
- if ( chunk . content ) {
97
- const lines = chunk . content . split ( '\n' ) ;
98
- let maxLines = 5 ;
99
- while ( maxLines > 0 && lines . length > 0 ) {
100
- if ( FILTER_PREFIX . some ( prefix => lines [ 0 ] . startsWith ( prefix ) ) ) {
101
- lines . shift ( ) ;
102
- maxLines -- ;
103
- } else {
104
- // only process consecutive metadata rows
105
- break ;
106
- }
107
- }
108
- return { ...chunk , content : lines . join ( '\n' ) } ;
109
- }
110
- return chunk ;
111
- }
You can’t perform that action at this time.
0 commit comments