Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Onboard basic RAG preset #372

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export enum WORKFLOW_TYPE {
MULTIMODAL_SEARCH = 'Multimodal search',
HYBRID_SEARCH = 'Hybrid search',
SENTIMENT_ANALYSIS = 'Sentiment analysis',
RAG = 'Retrieval-augmented generation',
CUSTOM = 'Custom',
UNKNOWN = 'Unknown',
}
Expand All @@ -103,6 +104,7 @@ export enum PROCESSOR_TYPE {
SORT = 'sort',
TEXT_CHUNKING = 'text_chunking',
NORMALIZATION = 'normalization-processor',
COLLAPSE = 'collapse',
}

export enum MODEL_TYPE {
Expand Down Expand Up @@ -180,12 +182,17 @@ export const DELIMITER_OPTIONAL_FIELDS = ['delimiter'];
export const SHARED_OPTIONAL_FIELDS = ['max_chunk_limit', 'description', 'tag'];

/**
* QUERY PRESETS
* DEFAULT FIELD VALUES
*/
export const DEFAULT_TEXT_FIELD = 'my_text';
export const DEFAULT_VECTOR_FIELD = 'my_embedding';
export const DEFAULT_IMAGE_FIELD = 'my_image';
export const DEFAULT_LABEL_FIELD = 'label';
export const DEFAULT_LLM_RESPONSE_FIELD = 'llm_response';

/**
* QUERY PRESETS
*/
export const VECTOR_FIELD_PATTERN = `{{vector_field}}`;
export const TEXT_FIELD_PATTERN = `{{text_field}}`;
export const IMAGE_FIELD_PATTERN = `{{image_field}}`;
Expand Down
1 change: 1 addition & 0 deletions common/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ export type QuickConfigureFields = {
imageField?: string;
labelField?: string;
embeddingLength?: number;
llmResponseField?: string;
};

/**
Expand Down
43 changes: 43 additions & 0 deletions public/configs/search_response_processors/collapse_processor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { PROCESSOR_TYPE } from '../../../common';
import { Processor } from '../processor';

/**
* The collapse processor config. Used in search flows.
*/
export class CollapseProcessor extends Processor {
constructor() {
super();
this.type = PROCESSOR_TYPE.COLLAPSE;
this.name = 'Collapse Processor';
this.fields = [
{
id: 'field',
type: 'string',
},
];
this.optionalFields = [
{
id: 'context_prefix',
type: 'string',
},
{
id: 'tag',
type: 'string',
},
{
id: 'description',
type: 'string',
},
{
id: 'ignore_failure',
type: 'boolean',
value: false,
},
];
}
}
1 change: 1 addition & 0 deletions public/configs/search_response_processors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './ml_search_response_processor';
export * from './split_search_response_processor';
export * from './sort_search_response_processor';
export * from './normalization_processor';
export * from './collapse_processor';
2 changes: 1 addition & 1 deletion public/general_components/general-component-styles.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.multi-select-filter {
&--width {
width: 200px;
width: 300px;
}
}
2 changes: 1 addition & 1 deletion public/pages/workflow_detail/tools/tools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const inputTabs = [
},
{
id: TAB_ID.QUERY,
name: 'Run queries',
name: 'Run query',
disabled: false,
},
{
Expand Down
2 changes: 1 addition & 1 deletion public/pages/workflow_detail/workflow_detail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('WorkflowDetail Page with create ingestion option', () => {
expect(getByText('Visual')).toBeInTheDocument();
expect(getByText('JSON')).toBeInTheDocument();
expect(getByRole('tab', { name: 'Run ingestion' })).toBeInTheDocument();
expect(getByRole('tab', { name: 'Run queries' })).toBeInTheDocument();
expect(getByRole('tab', { name: 'Run query' })).toBeInTheDocument();
expect(getByRole('tab', { name: 'Errors' })).toBeInTheDocument();
expect(getByRole('tab', { name: 'Resources' })).toBeInTheDocument();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export function InputTransformModal(props: InputTransformModalProps) {
index: values.search.index.name,
body: JSON.stringify({
...JSON.parse(values.search.request as string),
search_pipeline: curSearchPipeline,
search_pipeline: curSearchPipeline || {},
}),
},
dataSourceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from '../../../../common';
import { formikToUiConfig } from '../../../utils';
import {
CollapseProcessor,
MLIngestProcessor,
MLSearchRequestProcessor,
MLSearchResponseProcessor,
Expand Down Expand Up @@ -290,6 +291,13 @@ export function ProcessorsList(props: ProcessorsListProps) {
);
},
},
{
name: 'Collapse Processor',
onClick: () => {
closePopover();
addProcessor(new CollapseProcessor().toObj());
},
},
],
},
]}
Expand Down
38 changes: 33 additions & 5 deletions public/pages/workflows/new_workflow/quick_configure_inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
COHERE_DIMENSIONS,
DEFAULT_IMAGE_FIELD,
DEFAULT_LABEL_FIELD,
DEFAULT_LLM_RESPONSE_FIELD,
DEFAULT_TEXT_FIELD,
DEFAULT_VECTOR_FIELD,
MODEL_STATE,
Expand Down Expand Up @@ -84,6 +85,13 @@ export function QuickConfigureInputs(props: QuickConfigureInputsProps) {
};
break;
}
case WORKFLOW_TYPE.RAG: {
defaultFieldValues = {
textField: DEFAULT_TEXT_FIELD,
llmResponseField: DEFAULT_LLM_RESPONSE_FIELD,
};
break;
}
case WORKFLOW_TYPE.CUSTOM:
default:
break;
Expand Down Expand Up @@ -143,10 +151,7 @@ export function QuickConfigureInputs(props: QuickConfigureInputsProps) {

return (
<>
{(props.workflowType === WORKFLOW_TYPE.SEMANTIC_SEARCH ||
props.workflowType === WORKFLOW_TYPE.MULTIMODAL_SEARCH ||
props.workflowType === WORKFLOW_TYPE.HYBRID_SEARCH ||
props.workflowType === WORKFLOW_TYPE.SENTIMENT_ANALYSIS) && (
{props.workflowType !== WORKFLOW_TYPE.CUSTOM ? (
<>
<EuiSpacer size="m" />
<EuiAccordion
Expand All @@ -159,12 +164,16 @@ export function QuickConfigureInputs(props: QuickConfigureInputsProps) {
label={
props.workflowType === WORKFLOW_TYPE.SENTIMENT_ANALYSIS
? 'Model'
: props.workflowType === WORKFLOW_TYPE.RAG
? 'Large language model'
: 'Embedding model'
}
isInvalid={false}
helpText={
props.workflowType === WORKFLOW_TYPE.SENTIMENT_ANALYSIS
? 'The sentiment analysis model'
: props.workflowType === WORKFLOW_TYPE.RAG
? 'The large language model to generate user-friendly responses'
: 'The model to generate embeddings'
}
>
Expand Down Expand Up @@ -209,6 +218,8 @@ export function QuickConfigureInputs(props: QuickConfigureInputsProps) {
helpText={`The name of the text document field to be ${
props.workflowType === WORKFLOW_TYPE.SENTIMENT_ANALYSIS
? 'analyzed'
: props.workflowType === WORKFLOW_TYPE.RAG
? 'used as context to the large language model (LLM)'
: 'embedded'
}`}
>
Expand Down Expand Up @@ -297,9 +308,26 @@ export function QuickConfigureInputs(props: QuickConfigureInputsProps) {
/>
</EuiCompressedFormRow>
)}
{props.workflowType === WORKFLOW_TYPE.RAG && (
<EuiCompressedFormRow
label={'LLM response field'}
isInvalid={false}
helpText="The name of the field containing the large language model (LLM) response"
>
<EuiCompressedFieldText
value={fieldValues?.llmResponseField || ''}
onChange={(e) => {
setFieldValues({
...fieldValues,
llmResponseField: e.target.value,
});
}}
/>
</EuiCompressedFormRow>
)}
</EuiAccordion>
</>
)}
) : undefined}
</>
);
}
Loading
Loading