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

Add presets for quick config fields #328

Merged
merged 2 commits into from
Aug 29, 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
33 changes: 33 additions & 0 deletions public/pages/workflows/new_workflow/quick_configure_inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ interface QuickConfigureInputsProps {
setFields(fields: QuickConfigureFields): void;
}

const DEFAULT_TEXT_FIELD = 'my_text';
const DEFAULT_VECTOR_FIELD = 'my_embedding';
const DEFAULT_IMAGE_FIELD = 'my_image';

// Dynamic component to allow optional input configuration fields for different use cases.
// Hooks back to the parent component with such field values
export function QuickConfigureInputs(props: QuickConfigureInputsProps) {
Expand All @@ -50,6 +54,35 @@ export function QuickConfigureInputs(props: QuickConfigureInputsProps) {
// Local field values state
const [fieldValues, setFieldValues] = useState<QuickConfigureFields>({});

// on initial load, and when there are any deployed models found, set
// defaults for the field values for certain workflow types
useEffect(() => {
let defaultFieldValues = {} as QuickConfigureFields;
if (
props.workflowType === WORKFLOW_TYPE.SEMANTIC_SEARCH ||
props.workflowType === WORKFLOW_TYPE.MULTIMODAL_SEARCH ||
props.workflowType === WORKFLOW_TYPE.HYBRID_SEARCH
) {
defaultFieldValues = {
textField: DEFAULT_TEXT_FIELD,
vectorField: DEFAULT_VECTOR_FIELD,
};
}
if (props.workflowType === WORKFLOW_TYPE.MULTIMODAL_SEARCH) {
defaultFieldValues = {
...defaultFieldValues,
imageField: DEFAULT_IMAGE_FIELD,
};
}
if (deployedModels.length > 0) {
defaultFieldValues = {
...defaultFieldValues,
embeddingModelId: deployedModels[0].id,
};
}
setFieldValues(defaultFieldValues);
}, [deployedModels]);

// Hook to update the parent field values
useEffect(() => {
props.setFields(fieldValues);
Expand Down
26 changes: 25 additions & 1 deletion public/pages/workflows/new_workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ function fetchHybridSearchMetadata(): UIState {
});
baseState.config.search.request.value = customStringify(TERM_QUERY);
baseState.config.search.enrichResponse.processors = [
new NormalizationProcessor().toObj(),
injectDefaultWeightsInNormalizationProcessor(
new NormalizationProcessor().toObj()
),
];
baseState.config.search.enrichRequest.processors = [
injectQueryTemplateInProcessor(
Expand Down Expand Up @@ -217,3 +219,25 @@ function injectQueryTemplateInProcessor(
);
return processorConfig;
}

// set default weights for a normalization processor. assumes there is 2 queries, and equally
// balances the weight. We don't hardcode in the configuration, since we don't want to set
// invalid defaults for arbitrary use cases (e.g., more than 2 queries). In this case, we
// are already setting 2 queries by default, so we can make this assumption.
function injectDefaultWeightsInNormalizationProcessor(
processorConfig: IProcessorConfig
): IProcessorConfig {
processorConfig.optionalFields = processorConfig.optionalFields?.map(
(optionalField) => {
let updatedField = optionalField;
if (optionalField.id === 'weights') {
updatedField = {
...updatedField,
value: '0.5, 0.5',
};
}
return updatedField;
}
);
return processorConfig;
}
Loading