Skip to content

Commit 1636461

Browse files
committed
Add new RAG + hybrid search preset
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent a525583 commit 1636461

File tree

6 files changed

+57
-6
lines changed

6 files changed

+57
-6
lines changed

common/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export enum WORKFLOW_TYPE {
168168
HYBRID_SEARCH = 'Hybrid Search',
169169
RAG = 'RAG with Lexical Retrieval',
170170
VECTOR_SEARCH_WITH_RAG = 'RAG with Vector Retrieval',
171+
HYBRID_SEARCH_WITH_RAG = 'RAG with Hybrid Search',
171172
CUSTOM = 'Custom Search',
172173
UNKNOWN = 'Unknown',
173174
}

common/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export function isVectorSearchUseCase(workflow: Workflow | undefined): boolean {
5252
WORKFLOW_TYPE.MULTIMODAL_SEARCH,
5353
WORKFLOW_TYPE.SEMANTIC_SEARCH,
5454
WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG,
55+
WORKFLOW_TYPE.HYBRID_SEARCH_WITH_RAG,
5556
].includes(workflow?.ui_metadata?.type)
5657
);
5758
}

public/pages/workflows/new_workflow/quick_configure_modal.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ export function QuickConfigureModal(props: QuickConfigureModalProps) {
142142
// if a RAG workflow, require an LLM
143143
if (
144144
workflowType === WORKFLOW_TYPE.RAG ||
145-
workflowType === WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG
145+
workflowType === WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG ||
146+
workflowType === WORKFLOW_TYPE.HYBRID_SEARCH_WITH_RAG
146147
) {
147148
tempFormValues = {
148149
...tempFormValues,
@@ -299,7 +300,9 @@ export function QuickConfigureModal(props: QuickConfigureModalProps) {
299300
)}
300301
{(props.workflow?.ui_metadata?.type === WORKFLOW_TYPE.RAG ||
301302
props.workflow?.ui_metadata?.type ===
302-
WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG) &&
303+
WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG ||
304+
props.workflow?.ui_metadata?.type ===
305+
WORKFLOW_TYPE.HYBRID_SEARCH_WITH_RAG) &&
303306
!isEmpty(deployedModels) && (
304307
<EuiFlexItem>
305308
<ModelField
@@ -482,7 +485,8 @@ function injectQuickConfigureFields(
482485
}
483486
break;
484487
}
485-
case WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG: {
488+
case WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG:
489+
case WORKFLOW_TYPE.HYBRID_SEARCH_WITH_RAG: {
486490
if (!isEmpty(quickConfigureFields) && workflow.ui_metadata?.config) {
487491
workflow.ui_metadata.config = updateIngestProcessors(
488492
workflow.ui_metadata.config,

public/pages/workflows/new_workflow/quick_configure_optional_fields.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ export function QuickConfigureOptionalFields(
8888
};
8989
break;
9090
}
91-
case WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG: {
91+
case WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG:
92+
case WORKFLOW_TYPE.HYBRID_SEARCH_WITH_RAG: {
9293
defaultFieldValues = {
9394
textField: DEFAULT_TEXT_FIELD,
9495
vectorField: DEFAULT_VECTOR_FIELD,
@@ -201,7 +202,8 @@ export function QuickConfigureOptionalFields(
201202
{(props.workflowType === WORKFLOW_TYPE.SEMANTIC_SEARCH ||
202203
props.workflowType === WORKFLOW_TYPE.MULTIMODAL_SEARCH ||
203204
props.workflowType === WORKFLOW_TYPE.HYBRID_SEARCH ||
204-
props.workflowType === WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG) && (
205+
props.workflowType === WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG ||
206+
props.workflowType === WORKFLOW_TYPE.HYBRID_SEARCH_WITH_RAG) && (
205207
<>
206208
<EuiCompressedFormRow
207209
fullWidth={true}
@@ -245,7 +247,8 @@ export function QuickConfigureOptionalFields(
245247
</>
246248
)}
247249
{(props.workflowType === WORKFLOW_TYPE.RAG ||
248-
props.workflowType === WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG) && (
250+
props.workflowType === WORKFLOW_TYPE.VECTOR_SEARCH_WITH_RAG ||
251+
props.workflowType === WORKFLOW_TYPE.HYBRID_SEARCH_WITH_RAG) && (
249252
<>
250253
<EuiCompressedFormRow
251254
fullWidth={true}

public/pages/workflows/new_workflow/utils.ts

+28
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export function enrichPresetWorkflowWithUiMetadata(
6464
uiMetadata = fetchVectorSearchWithRAGMetadata(workflowVersion);
6565
break;
6666
}
67+
case WORKFLOW_TYPE.HYBRID_SEARCH_WITH_RAG: {
68+
uiMetadata = fetchHybridSearchWithRAGMetadata(workflowVersion);
69+
break;
70+
}
6771
default: {
6872
uiMetadata = fetchEmptyMetadata();
6973
break;
@@ -278,6 +282,30 @@ export function fetchVectorSearchWithRAGMetadata(version: string): UIState {
278282
return baseState;
279283
}
280284

285+
export function fetchHybridSearchWithRAGMetadata(version: string): UIState {
286+
let baseState = fetchEmptyMetadata();
287+
baseState.type = WORKFLOW_TYPE.HYBRID_SEARCH_WITH_RAG;
288+
// Ingest config: knn index w/ an ML inference processor
289+
baseState.config.ingest.enrich.processors = [new MLIngestProcessor().toObj()];
290+
baseState.config.ingest.index.name.value = generateId('knn_index', 6);
291+
baseState.config.ingest.index.settings.value = customStringify({
292+
[`index.knn`]: true,
293+
});
294+
// Search config: match query => ML inference processor for generating embeddings
295+
// with hybrid search => ML inference processor for returning LLM-generated response of results
296+
baseState.config.search.request.value = customStringify(MATCH_QUERY_TEXT);
297+
baseState.config.search.enrichRequest.processors = [
298+
injectQueryTemplateInProcessor(
299+
new MLSearchRequestProcessor().toObj(),
300+
HYBRID_SEARCH_QUERY_MATCH_KNN
301+
),
302+
];
303+
baseState.config.search.enrichResponse.processors = [
304+
new MLSearchResponseProcessor().toObj(),
305+
];
306+
return baseState;
307+
}
308+
281309
// populate the `query_template` config value with a given query template
282310
// by default, we replace any vector pattern ("{{vector}}") with the unquoted
283311
// vector template placeholder (${vector}) so it becomes a proper template
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "RAG with Hybrid Search",
3+
"description": "Build a search application that uses retrieval-augmented generation (RAG) to retrieve relevant documents using hybrid search, pass them to large language models, and synthesize answers.",
4+
"version": {
5+
"template": "1.0.0",
6+
"compatibility": [
7+
"2.19.0",
8+
"3.0.0"
9+
]
10+
},
11+
"ui_metadata": {
12+
"type": "RAG with Hybrid Search"
13+
}
14+
}

0 commit comments

Comments
 (0)