@@ -13,8 +13,9 @@ import { URI } from '../../../util/vs/base/common/uri';
13
13
import { IAuthenticationService } from '../../authentication/common/authentication' ;
14
14
import { FileChunkAndScore , FileChunkWithEmbedding } from '../../chunking/common/chunk' ;
15
15
import { ChunkableContent , ComputeBatchInfo , EmbeddingsComputeQos , IChunkingEndpointClient } from '../../chunking/common/chunkingEndpointClient' ;
16
- import { distance , Embedding , EmbeddingType , IEmbeddingsComputer } from '../../embeddings/common/embeddingsComputer' ;
16
+ import { distance , Embedding , EmbeddingInputType , EmbeddingType , IEmbeddingsComputer } from '../../embeddings/common/embeddingsComputer' ;
17
17
import { ILogService } from '../../log/common/logService' ;
18
+ import { IGithubAvailableEmbeddingTypesService } from '../../workspaceChunkSearch/common/githubAvailableEmbeddingTypes' ;
18
19
19
20
/**
20
21
* The maximum content length to sent to the chunking endpoint.
@@ -51,6 +52,7 @@ export class UrlChunkEmbeddingsIndex extends Disposable {
51
52
@ILogService private readonly _logService : ILogService ,
52
53
@IEmbeddingsComputer private readonly _embeddingsComputer : IEmbeddingsComputer ,
53
54
@IChunkingEndpointClient private readonly _chunkingEndpointClient : IChunkingEndpointClient ,
55
+ @IGithubAvailableEmbeddingTypesService private readonly _availableEmbeddingTypesService : IGithubAvailableEmbeddingTypesService ,
54
56
) {
55
57
super ( ) ;
56
58
}
@@ -60,20 +62,25 @@ export class UrlChunkEmbeddingsIndex extends Disposable {
60
62
query : string ,
61
63
token : CancellationToken ,
62
64
) : Promise < FileChunkAndScore [ ] [ ] > {
65
+ const embeddingType = await raceCancellationError ( this . _availableEmbeddingTypesService . getPreferredType ( /*silent*/ false ) , token ) ;
66
+ if ( ! embeddingType ) {
67
+ throw new Error ( 'No embedding types available' ) ;
68
+ }
69
+
63
70
const [ queryEmbedding , fileChunksAndEmbeddings ] = await raceCancellationError ( Promise . all ( [
64
- this . computeEmbeddings ( query , token ) ,
65
- this . getEmbeddingsForFiles ( files . map ( file => new UrlContent ( file . uri , file . content ) ) , EmbeddingsComputeQos . Batch , token )
71
+ this . computeEmbeddings ( embeddingType , query , 'query' , token ) ,
72
+ this . getEmbeddingsForFiles ( embeddingType , files . map ( file => new UrlContent ( file . uri , file . content ) ) , EmbeddingsComputeQos . Batch , token )
66
73
] ) , token ) ;
67
74
68
75
return this . computeChunkScores ( fileChunksAndEmbeddings , queryEmbedding ) ;
69
76
}
70
77
71
- private async computeEmbeddings ( str : string , token : CancellationToken ) : Promise < Embedding > {
72
- const embeddings = await this . _embeddingsComputer . computeEmbeddings ( EmbeddingType . text3small_512 , [ str ] , { } , new TelemetryCorrelationId ( 'UrlChunkEmbeddingsIndex::computeEmbeddings' ) , token ) ;
78
+ private async computeEmbeddings ( embeddingType : EmbeddingType , str : string , inputType : EmbeddingInputType , token : CancellationToken ) : Promise < Embedding > {
79
+ const embeddings = await this . _embeddingsComputer . computeEmbeddings ( embeddingType , [ str ] , { inputType } , new TelemetryCorrelationId ( 'UrlChunkEmbeddingsIndex::computeEmbeddings' ) , token ) ;
73
80
return embeddings . values [ 0 ] ;
74
81
}
75
82
76
- private async getEmbeddingsForFiles ( files : readonly UrlContent [ ] , qos : EmbeddingsComputeQos , token : CancellationToken ) : Promise < ( readonly FileChunkWithEmbedding [ ] ) [ ] > {
83
+ private async getEmbeddingsForFiles ( embeddingType : EmbeddingType , files : readonly UrlContent [ ] , qos : EmbeddingsComputeQos , token : CancellationToken ) : Promise < ( readonly FileChunkWithEmbedding [ ] ) [ ] > {
77
84
if ( ! files . length ) {
78
85
return [ ] ;
79
86
}
@@ -88,7 +95,7 @@ export class UrlChunkEmbeddingsIndex extends Disposable {
88
95
}
89
96
90
97
const result = await Promise . all ( files . map ( async file => {
91
- const result = await this . getChunksAndEmbeddings ( authToken , file , batchInfo , qos , token ) ;
98
+ const result = await this . getChunksAndEmbeddings ( authToken , embeddingType , file , batchInfo , qos , token ) ;
92
99
if ( ! result ) {
93
100
return [ ] ;
94
101
}
@@ -107,13 +114,13 @@ export class UrlChunkEmbeddingsIndex extends Disposable {
107
114
) ;
108
115
}
109
116
110
- private async getChunksAndEmbeddings ( authToken : string , content : UrlContent , batchInfo : ComputeBatchInfo , qos : EmbeddingsComputeQos , token : CancellationToken ) : Promise < readonly FileChunkWithEmbedding [ ] | undefined > {
117
+ private async getChunksAndEmbeddings ( authToken : string , embeddingType : EmbeddingType , content : UrlContent , batchInfo : ComputeBatchInfo , qos : EmbeddingsComputeQos , token : CancellationToken ) : Promise < readonly FileChunkWithEmbedding [ ] | undefined > {
111
118
const existing = await raceCancellationError ( this . _cache . get ( content ) , token ) ;
112
119
if ( existing ) {
113
120
return existing ;
114
121
}
115
122
116
- const chunksAndEmbeddings = await raceCancellationError ( this . _chunkingEndpointClient . computeChunksAndEmbeddings ( authToken , EmbeddingType . text3small_512 , content , batchInfo , qos , new Map ( ) , new CallTracker ( 'UrlChunkEmbeddingsIndex::getChunksAndEmbeddings' ) , token ) , token ) ;
123
+ const chunksAndEmbeddings = await raceCancellationError ( this . _chunkingEndpointClient . computeChunksAndEmbeddings ( authToken , embeddingType , content , batchInfo , qos , new Map ( ) , new CallTracker ( 'UrlChunkEmbeddingsIndex::getChunksAndEmbeddings' ) , token ) , token ) ;
117
124
if ( chunksAndEmbeddings ) {
118
125
this . _cache . set ( content , chunksAndEmbeddings ) ;
119
126
}
0 commit comments