Skip to content

Commit fc83dad

Browse files
committed
Finish onboarding and edge case handling
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent f215a29 commit fc83dad

File tree

6 files changed

+87
-43
lines changed

6 files changed

+87
-43
lines changed

public/pages/workflow_detail/prototype/ingestor.tsx

+15-17
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,24 @@ import {
1616
USE_CASE,
1717
Workflow,
1818
getIndexName,
19-
getSemanticSearchValues,
19+
getNeuralSearchValues,
2020
} from '../../../../common';
2121
import { ingest, useAppDispatch } from '../../../store';
2222
import { getCore } from '../../../services';
23-
import { getFormattedJSONString } from './utils';
23+
import {
24+
NeuralSparseValues,
25+
SemanticSearchValues,
26+
WorkflowValues,
27+
getFormattedJSONString,
28+
} from './utils';
2429

2530
interface IngestorProps {
2631
workflow: Workflow;
2732
}
2833

29-
type WorkflowValues = {
30-
modelId: string;
31-
};
32-
33-
type SemanticSearchValues = WorkflowValues & {
34-
inputField: string;
35-
vectorField: string;
36-
};
37-
3834
type DocGeneratorFn = (
3935
queryText: string,
40-
workflowValues: SemanticSearchValues
36+
workflowValues: SemanticSearchValues | NeuralSparseValues
4137
) => {};
4238

4339
/**
@@ -188,8 +184,9 @@ function getDocGeneratorFn(workflow: Workflow): DocGeneratorFn {
188184
let fn;
189185
switch (workflow.use_case) {
190186
case USE_CASE.SEMANTIC_SEARCH:
187+
case USE_CASE.NEURAL_SPARSE_SEARCH:
191188
default: {
192-
fn = () => generateSemanticSearchDoc;
189+
fn = () => generateNeuralSearchDoc;
193190
}
194191
}
195192
return fn;
@@ -200,17 +197,18 @@ function getWorkflowValues(workflow: Workflow): WorkflowValues {
200197
let values;
201198
switch (workflow.use_case) {
202199
case USE_CASE.SEMANTIC_SEARCH:
200+
case USE_CASE.NEURAL_SPARSE_SEARCH:
203201
default: {
204-
values = getSemanticSearchValues(workflow);
202+
values = getNeuralSearchValues(workflow);
205203
}
206204
}
207205
return values;
208206
}
209207

210-
// utility fn to generate a document suited for semantic search
211-
function generateSemanticSearchDoc(
208+
// utility fn to generate a document suited for neural search use cases
209+
function generateNeuralSearchDoc(
212210
docValue: string,
213-
workflowValues: SemanticSearchValues
211+
workflowValues: SemanticSearchValues | NeuralSparseValues
214212
): {} {
215213
return {
216214
[workflowValues.inputField]: docValue,

public/pages/workflow_detail/prototype/query_executor.tsx

+38-15
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,24 @@ import {
1616
USE_CASE,
1717
Workflow,
1818
getIndexName,
19-
getSemanticSearchValues,
19+
getNeuralSearchValues,
2020
} from '../../../../common';
2121
import { searchIndex, useAppDispatch } from '../../../store';
2222
import { getCore } from '../../../services';
23-
import { getFormattedJSONString } from './utils';
23+
import {
24+
NeuralSparseValues,
25+
SemanticSearchValues,
26+
WorkflowValues,
27+
getFormattedJSONString,
28+
} from './utils';
2429

2530
interface QueryExecutorProps {
2631
workflow: Workflow;
2732
}
2833

29-
type WorkflowValues = {
30-
modelId: string;
31-
};
32-
33-
type SemanticSearchValues = WorkflowValues & {
34-
inputField: string;
35-
vectorField: string;
36-
};
37-
3834
type QueryGeneratorFn = (
3935
queryText: string,
40-
workflowValues: SemanticSearchValues
36+
workflowValues: SemanticSearchValues | NeuralSparseValues
4137
) => {};
4238

4339
/**
@@ -187,9 +183,13 @@ export function QueryExecutor(props: QueryExecutorProps) {
187183
function getQueryGeneratorFn(workflow: Workflow): QueryGeneratorFn {
188184
let fn;
189185
switch (workflow.use_case) {
190-
case USE_CASE.SEMANTIC_SEARCH:
191-
default: {
186+
case USE_CASE.SEMANTIC_SEARCH: {
192187
fn = () => generateSemanticSearchQuery;
188+
break;
189+
}
190+
case USE_CASE.NEURAL_SPARSE_SEARCH:
191+
default: {
192+
fn = () => generateNeuralSparseQuery;
193193
}
194194
}
195195
return fn;
@@ -201,7 +201,7 @@ function getWorkflowValues(workflow: Workflow): WorkflowValues {
201201
switch (workflow.use_case) {
202202
case USE_CASE.SEMANTIC_SEARCH:
203203
default: {
204-
values = getSemanticSearchValues(workflow);
204+
values = getNeuralSearchValues(workflow);
205205
}
206206
}
207207
return values;
@@ -213,6 +213,7 @@ function generateSemanticSearchQuery(
213213
workflowValues: SemanticSearchValues
214214
): {} {
215215
return {
216+
// TODO: can make this configurable
216217
_source: {
217218
excludes: [`${workflowValues.vectorField}`],
218219
},
@@ -221,13 +222,35 @@ function generateSemanticSearchQuery(
221222
[workflowValues.vectorField]: {
222223
query_text: queryText,
223224
model_id: workflowValues.modelId,
225+
// TODO: expose k as configurable
224226
k: 5,
225227
},
226228
},
227229
},
228230
};
229231
}
230232

233+
// utility fn to generate a neural sparse search query
234+
function generateNeuralSparseQuery(
235+
queryText: string,
236+
workflowValues: NeuralSparseValues
237+
): {} {
238+
return {
239+
// TODO: can make this configurable
240+
_source: {
241+
excludes: [`${workflowValues.vectorField}`],
242+
},
243+
query: {
244+
neural_sparse: {
245+
[workflowValues.vectorField]: {
246+
query_text: queryText,
247+
model_id: workflowValues.modelId,
248+
},
249+
},
250+
},
251+
};
252+
}
253+
231254
function processHits(hits: any[]): {}[] {
232255
return hits.map((hit) => hit._source);
233256
}

public/pages/workflow_detail/prototype/utils.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@
44
*/
55

66
/**
7-
* Shared utility fns used in the prototyping page.
7+
* Shared utility fns and constants used in the prototyping page.
88
*/
99

10+
// UTILITY FNS
1011
export function getFormattedJSONString(obj: {}): string {
1112
return Object.values(obj).length > 0 ? JSON.stringify(obj, null, '\t') : '';
1213
}
14+
15+
// CONSTANTS
16+
export type WorkflowValues = {
17+
modelId: string;
18+
};
19+
20+
export type SemanticSearchValues = WorkflowValues & {
21+
inputField: string;
22+
vectorField: string;
23+
};
24+
25+
export type NeuralSparseValues = SemanticSearchValues;

public/pages/workflow_detail/utils/data_extractor_utils.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ export function getIndexName(workflow: Workflow): string | undefined {
3333
}
3434
}
3535

36-
export function getSemanticSearchValues(
36+
// Returns values for neural search use cases. Note many of them
37+
// persist the same values to use during ingest and search, so we keep the naming general
38+
export function getNeuralSearchValues(
3739
workflow: Workflow
3840
): { modelId: string; inputField: string; vectorField: string } {
3941
const modelId = getModelId(workflow) as string;

public/pages/workflow_detail/utils/workflow_to_template_utils.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ function transformerToTemplateNodes(
154154
const modelId = model.id;
155155
const ingestPipelineName = generateId('ingest_pipeline');
156156

157+
// register model workflow step type is different per use case
158+
const registerModelStepType =
159+
flowNode.data.type === COMPONENT_CLASS.TEXT_EMBEDDING_TRANSFORMER
160+
? REGISTER_LOCAL_PRETRAINED_MODEL_STEP_TYPE
161+
: REGISTER_LOCAL_SPARSE_ENCODING_MODEL_STEP_TYPE;
162+
157163
let registerModelStep = undefined as
158164
| RegisterPretrainedModelNode
159165
| undefined;
@@ -170,15 +176,9 @@ function transformerToTemplateNodes(
170176
(model) => model.name === modelId
171177
) as PretrainedSentenceTransformer;
172178

173-
// workflow step type is different per use case
174-
const stepType =
175-
flowNode.data.type === COMPONENT_CLASS.TEXT_EMBEDDING_TRANSFORMER
176-
? REGISTER_LOCAL_PRETRAINED_MODEL_STEP_TYPE
177-
: REGISTER_LOCAL_SPARSE_ENCODING_MODEL_STEP_TYPE;
178-
179179
registerModelStep = {
180-
id: stepType,
181-
type: stepType,
180+
id: registerModelStepType,
181+
type: registerModelStepType,
182182
user_inputs: {
183183
name: pretrainedModel.name,
184184
description: pretrainedModel.description,
@@ -193,7 +193,7 @@ function transformerToTemplateNodes(
193193
// or directly from the user
194194
const finalModelId =
195195
registerModelStep !== undefined
196-
? `\${{${REGISTER_LOCAL_PRETRAINED_MODEL_STEP_TYPE}.model_id}}`
196+
? `\${{${registerModelStepType}.model_id}}`
197197
: modelId;
198198

199199
// processor is different per use case
@@ -236,6 +236,12 @@ function transformerToTemplateNodes(
236236
},
237237
},
238238
} as CreateIngestPipelineNode;
239+
if (registerModelStep !== undefined) {
240+
createIngestPipelineStep.previous_node_inputs = {
241+
...createIngestPipelineStep.previous_node_inputs,
242+
[registerModelStepType]: 'model_id',
243+
};
244+
}
239245

240246
return registerModelStep !== undefined
241247
? [registerModelStep, createIngestPipelineStep]

public/pages/workflows/workflow_list/columns.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const columns = (actions: any[]) => [
1616
{
1717
field: 'name',
1818
name: 'Name',
19+
width: '20%',
1920
sortable: true,
2021
render: (name: string, workflow: Workflow) => (
2122
<EuiLink href={`${PLUGIN_ID}#/workflows/${workflow.id}`}>{name}</EuiLink>
@@ -29,6 +30,7 @@ export const columns = (actions: any[]) => [
2930
{
3031
field: 'use_case',
3132
name: 'Type',
33+
width: '30%',
3234
sortable: true,
3335
},
3436
{

0 commit comments

Comments
 (0)