(Go: >> BACK << -|- >> HOME <<)

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

Feature request: Option to disable cross encoder models #286

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

azaylamba
Copy link
Contributor
@azaylamba azaylamba commented Dec 23, 2023

Issue #222
Description of changes: Currently cross encoder models are used to rank the search results but the models available need to be hosted on Sagemaker which increases cost significantly. Having an option to disable cross encoder models would be helpful while exploring the chatbot so that Sagemaker costs can be avoided.

Added a config to enable/disable embeddings via Sagemaker which in turn derives cross encoding models.
Persisted enableSagemakerModels config so that it can be used directly instead of relying on sagemakerModels length.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…t the models available need to be hosted on Sagemaker which increases cost significantly. Having an option to disable cross encoder models would be helpful while exploring the chatbot so that Sagemaker costs can be avoided.

Added a config to enable/disable cross encoder models.
Also added options to selected embedding models, so that sagemakerModels are not created automatically.
Persisted enableSagemakerModels config so that it can be used directly instead of relying on sagemakerModels length.
Added basic feedback mechanism for responses generated by the chatbot.
The feedbacks are stored in DynamoDB which can be queried to do analysis as required by admin users.
In future we can add a UI page to display the feedbacks, but for now these are being stored and manual analysis would be required.
The feedbacks are not adding to the learning of the chatbot.
@azaylamba
Copy link
Contributor Author

@massi-ang could you please have a look?

@azaylamba
Copy link
Contributor Author

@bigadsoleiman I have resolved the merge conflicts in the latest commit.

@spugachev
Copy link
Contributor

@azaylamba We have migrated to AppSync. This PR has conflicts. Could you please fix this? And than we can merge

@azaylamba
Copy link
Contributor Author

@spugachev I couldn't find any conflicts in the PR. I have merged the main branch.

Note: I have not tested the changes after syncing with main due to some constraints with my AWS account. Any help in testing the changes is appreciated.

Copy link
Collaborator
@massi-ang massi-ang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On top of my comments on the changes, I would expect changes to the front end. If cross encoder models are not enabled the the menu should not be displayed.
Also, if cross encoder models are not selected, it should not be possible to enable hybrid search on the workspaces.

cli/magic-create.ts Outdated Show resolved Hide resolved
cli/magic-create.ts Outdated Show resolved Hide resolved
cli/magic-create.ts Outdated Show resolved Hide resolved
cli/magic-create.ts Outdated Show resolved Hide resolved
@azaylamba
Copy link
Contributor Author
azaylamba commented Jan 25, 2024

@massi-ang It seems syncing with main has caused some unwanted changes, as the original changes were made prior to AppSync migration. I will work on this.

@azaylamba azaylamba reopened this Feb 4, 2024
@azaylamba
Copy link
Contributor Author

@massi-ang I have addressed the review comments, please have a look.

Copy link
Collaborator
@massi-ang massi-ang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why there are 2 settings (Cross Encoder / Embeddings) , since if you enable embeddings models via SM, you can get Cross Encoder for free.

cli/magic-create.ts Outdated Show resolved Hide resolved
cli/magic-create.ts Outdated Show resolved Hide resolved
@azaylamba
Copy link
Contributor Author
azaylamba commented Feb 5, 2024

Can you explain why there are 2 settings (Cross Encoder / Embeddings) , since if you enable embeddings models via SM, you can get Cross Encoder for free.

@massi-ang I understand your point that if we enable embeddings models via SM, we can get cross encoder for free. I kept the settings separate to have more control for cross encoding and to make the intent clear in the backend code. Excluding execution of cross encoding code based on sagemaker models can be a little confusing there.
I think having two separate settings won't harm.

Please let me know if I am missing something.

@massi-ang
Copy link
Collaborator

I think the configuration should be simple and meaningful for the user not the backend. You could think of an alternative naming for the parameter if you think that could create confusion, or better, you could create a function called is_cross_encoding_enabled and use that in all your backend logic. In this way your code is self describing. In the function you can add a comment explaining why enabling embeddings is equivalent to enabling the cross encoder (with the current implementation). This approach provides an easy way to make the code evolve in the future.

@azaylamba
Copy link
Contributor Author

@massi-ang I have removed the prompt for crossEncodingEnabled and now it is being driven from the config enableEmbeddingModelsViaSagemaker. The reason I still kept crossEncodingEnabled in the config is because similar parameter (crossEncodersEnabled) is already being used in existing code.

@azaylamba
Copy link
Contributor Author

@massi-ang Would you be able to have a look at this again?

azaylamba and others added 4 commits February 24, 2024 12:58
Default embeddings models was not being set correctly. Also error was thrown related to suppression rules if sagemaker models were not enabled. Used props.config.llms.enableSagemakerModels config to add the NAG suppression rules.
@azaylamba
Copy link
Contributor Author

@massi-ang Please let me know if more changes are required on this one.

@toeteuf
Copy link
toeteuf commented Jul 11, 2024

@massi-ang I wanted to follow up on this PR submitted by @azaylamba that is still pending review. Your feedback and approval are crucial for us, we also would like this feature. Regards

@massi-ang
Copy link
Collaborator

Hi @azaylamba,
Please look at my comments and fix accordingly. Thanks.

Copy link
Collaborator
@massi-ang massi-ang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work but few fixes left

@@ -328,7 +341,7 @@ async function processCreateOptions(options: any): Promise<void> {
choices: embeddingModels.map((m) => ({ name: m.name, value: m })),
initial: options.defaultEmbedding || undefined,
skip(): boolean {
return !(this as any).state.answers.enableRag;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @azaylamba, are you able to address this comment?

props.config.rag.engines.aurora.enabled ||
props.config.rag.engines.opensearch.enabled
) {
if (props.config.llms.enableSagemakerModels) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be checking crossEncodingEnabled and not enableSageMakerModels

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but won't that be confusing that crossEncodingEnabled is driving the Sagemaker models instead of the config props.config.llms.enableSagemakerModels which is specific for sagemaker models?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right and props.config.llms.enableSagemakerModels is better

cli/magic-config.ts Outdated Show resolved Hide resolved
cli/magic-config.ts Show resolved Hide resolved
cli/magic-config.ts Outdated Show resolved Hide resolved
};
}
if (!config.rag.enableEmbeddingModelsViaSagemaker) {
config.rag.embeddingsModels = embeddingModels.filter(model => model.provider !== "sagemaker");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic should also be applied to the list of models shown in the UI when selecting the default embedding model.

@azaylamba
Copy link
Contributor Author

@massi-ang Addressed the review comments, please have a look.

cli/magic-config.ts Outdated Show resolved Hide resolved
lib/user-interface/react-app/src/common/types.ts Outdated Show resolved Hide resolved
Also removed duplicated config.
Copy link
Collaborator
@massi-ang massi-ang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last change and it seems to be all good.

props.config.rag.engines.aurora.enabled ||
props.config.rag.engines.opensearch.enabled
) {
if (props.config.rag.crossEncodingEnabled) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were right, props.config.llms.enableSagemakerModels is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the condition.

@azaylamba
Copy link
Contributor Author

@massi-ang Addressed the last review comment, please have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants