@@ -104,9 +104,9 @@ function toTemplateNodes(
104
104
edges : ReactFlowEdge [ ]
105
105
) : TemplateNode [ ] | undefined {
106
106
if ( flowNode . data . baseClasses ?. includes ( COMPONENT_CLASS . ML_TRANSFORMER ) ) {
107
- return toIngestPipelineNodes ( flowNode ) ;
107
+ return transformerToTemplateNodes ( flowNode ) ;
108
108
} else if ( flowNode . data . baseClasses ?. includes ( COMPONENT_CLASS . INDEXER ) ) {
109
- return [ toIndexerNode ( flowNode , prevNodes , edges ) ] ;
109
+ return [ indexerToTemplateNode ( flowNode , prevNodes , edges ) ] ;
110
110
}
111
111
}
112
112
@@ -121,7 +121,9 @@ function toTemplateEdge(flowEdge: ReactFlowEdge): TemplateEdge {
121
121
// ingest pipeline with a processor specific to the final class of the node.
122
122
// Optionally prepend a register pretrained model step if the selected model
123
123
// is a pretrained and undeployed one.
124
- function toIngestPipelineNodes ( flowNode : ReactFlowComponent ) : TemplateNode [ ] {
124
+ function transformerToTemplateNodes (
125
+ flowNode : ReactFlowComponent
126
+ ) : TemplateNode [ ] {
125
127
// TODO a few improvements to make here:
126
128
// 1. Consideration of multiple ingest processors and how to collect them all, and finally create
127
129
// a single ingest pipeline with all of them, in the same order as done on the UI
@@ -143,18 +145,14 @@ function toIngestPipelineNodes(flowNode: ReactFlowComponent): TemplateNode[] {
143
145
| RegisterPretrainedModelNode
144
146
| undefined ;
145
147
if ( model . category === MODEL_CATEGORY . PRETRAINED ) {
146
- const pretrainedModelMap = { } as {
147
- [ modelName : string ] : PretrainedSentenceTransformer ;
148
- } ;
149
- [
148
+ const pretrainedModel = [
150
149
ROBERTA_SENTENCE_TRANSFORMER ,
151
150
MPNET_SENTENCE_TRANSFORMER ,
152
151
BERT_SENTENCE_TRANSFORMER ,
153
- ] . map ( ( transformer ) => {
154
- pretrainedModelMap [ transformer . name ] = transformer ;
155
- } ) ;
156
- // the model ID in the form will be the unique name of the pretrained model
157
- const pretrainedModel = pretrainedModelMap [ modelId ] ;
152
+ ] . find (
153
+ // the model ID in the form will be the unique name of the pretrained model
154
+ ( model ) => model . name === modelId
155
+ ) as PretrainedSentenceTransformer ;
158
156
registerModelStep = {
159
157
id : REGISTER_LOCAL_PRETRAINED_MODEL_STEP_TYPE ,
160
158
type : REGISTER_LOCAL_PRETRAINED_MODEL_STEP_TYPE ,
@@ -168,73 +166,46 @@ function toIngestPipelineNodes(flowNode: ReactFlowComponent): TemplateNode[] {
168
166
} as RegisterPretrainedModelNode ;
169
167
}
170
168
171
- // If we have a register model step, add it first, and use
172
- // the produced model ID in the ingest pipeline step
173
- if ( registerModelStep !== undefined ) {
174
- return [
175
- registerModelStep ,
176
- {
177
- id : flowNode . data . id ,
178
- type : CREATE_INGEST_PIPELINE_STEP_TYPE ,
179
- previous_node_inputs : {
180
- [ REGISTER_LOCAL_PRETRAINED_MODEL_STEP_TYPE ] : 'model_id' ,
181
- } ,
182
- user_inputs : {
183
- pipeline_id : ingestPipelineName ,
184
- model_id : `\${{${ REGISTER_LOCAL_PRETRAINED_MODEL_STEP_TYPE } .model_id}}` ,
185
- input_field : inputField ,
186
- output_field : vectorField ,
187
- configurations : {
188
- description :
189
- 'An ingest pipeline with a text embedding processor.' ,
190
- processors : [
191
- {
192
- text_embedding : {
193
- model_id : `\${{${ REGISTER_LOCAL_PRETRAINED_MODEL_STEP_TYPE } .model_id}}` ,
194
- field_map : {
195
- [ inputField ] : vectorField ,
196
- } ,
197
- } ,
198
- } as TextEmbeddingProcessor ,
199
- ] ,
200
- } ,
201
- } ,
202
- } as CreateIngestPipelineNode ,
203
- ] ;
204
- } else {
205
- return [
206
- {
207
- id : flowNode . data . id ,
208
- type : CREATE_INGEST_PIPELINE_STEP_TYPE ,
209
- user_inputs : {
210
- pipeline_id : ingestPipelineName ,
211
- model_id : modelId ,
212
- input_field : inputField ,
213
- output_field : vectorField ,
214
- configurations : {
215
- description :
216
- 'An ingest pipeline with a text embedding processor.' ,
217
- processors : [
218
- {
219
- text_embedding : {
220
- model_id : modelId ,
221
- field_map : {
222
- [ inputField ] : vectorField ,
223
- } ,
224
- } ,
225
- } as TextEmbeddingProcessor ,
226
- ] ,
227
- } ,
228
- } ,
229
- } as CreateIngestPipelineNode ,
230
- ] ;
231
- }
169
+ // The model ID depends on if we are consuming it from a previous pretrained model step,
170
+ // or directly from the user
171
+ const finalModelId =
172
+ registerModelStep !== undefined
173
+ ? `\${{${ REGISTER_LOCAL_PRETRAINED_MODEL_STEP_TYPE } .model_id}}`
174
+ : modelId ;
175
+
176
+ const createIngestPipelineStep = {
177
+ id : flowNode . data . id ,
178
+ type : CREATE_INGEST_PIPELINE_STEP_TYPE ,
179
+ user_inputs : {
180
+ pipeline_id : ingestPipelineName ,
181
+ model_id : finalModelId ,
182
+ input_field : inputField ,
183
+ output_field : vectorField ,
184
+ configurations : {
185
+ description : 'An ingest pipeline with a text embedding processor.' ,
186
+ processors : [
187
+ {
188
+ text_embedding : {
189
+ model_id : finalModelId ,
190
+ field_map : {
191
+ [ inputField ] : vectorField ,
192
+ } ,
193
+ } ,
194
+ } as TextEmbeddingProcessor ,
195
+ ] ,
196
+ } ,
197
+ } ,
198
+ } as CreateIngestPipelineNode ;
199
+
200
+ return registerModelStep !== undefined
201
+ ? [ registerModelStep , createIngestPipelineStep ]
202
+ : [ createIngestPipelineStep ] ;
232
203
}
233
204
}
234
205
}
235
206
236
207
// General fn to convert an indexer node to a final CreateIndexNode template node.
237
- function toIndexerNode (
208
+ function indexerToTemplateNode (
238
209
flowNode : ReactFlowComponent ,
239
210
prevNodes : ReactFlowComponent [ ] ,
240
211
edges : ReactFlowEdge [ ]
0 commit comments