From f79709cc6733148ea73bc76cda7f136c29a8edec Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:22:34 -0700 Subject: [PATCH] [Backport 2.x] Added conversation search default use case with RAG tool (#735) Added conversation search default use case with RAG tool (#732) Added conversation search use case with RAG tool (cherry picked from commit 970472763a5ddac312259325c9ae01911dc015a3) Signed-off-by: owaiskazi19 Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- CHANGELOG.md | 2 + .../flowframework/common/DefaultUseCases.java | 8 + ...nversational-search-rag-tool-defaults.json | 35 +++ ...search-with-bedrock-rag-tool-template.json | 218 ++++++++++++++++++ ...nal-search-with-cohere-model-template.json | 2 +- 5 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/defaults/conversational-search-rag-tool-defaults.json create mode 100644 src/main/resources/substitutionTemplates/conversational-search-with-bedrock-rag-tool-template.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 17e37ff0c..a8656ca18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) - Add Workflow Step for Reindex from source index to destination ([#718](https://github.com/opensearch-project/flow-framework/pull/718)) - Add param to delete workflow API to clear status even if resources exist ([#719](https://github.com/opensearch-project/flow-framework/pull/719)) - Add additional default use cases ([#731](https://github.com/opensearch-project/flow-framework/pull/731)) +- Add conversation search default use case with RAG tool ([#732](https://github.com/opensearch-project/flow-framework/pull/732)) + ### Bug Fixes - Add user mapping to Workflow State index ([#705](https://github.com/opensearch-project/flow-framework/pull/705)) diff --git a/src/main/java/org/opensearch/flowframework/common/DefaultUseCases.java b/src/main/java/org/opensearch/flowframework/common/DefaultUseCases.java index 7b8d06f1a..a982fc9c2 100644 --- a/src/main/java/org/opensearch/flowframework/common/DefaultUseCases.java +++ b/src/main/java/org/opensearch/flowframework/common/DefaultUseCases.java @@ -155,6 +155,14 @@ public enum DefaultUseCases { "defaults/semantic-search-with-reindex-defaults.json", "substitutionTemplates/semantic-search-with-reindex-template.json", List.of(CREATE_CONNECTOR_CREDENTIAL_KEY, REINDEX_SOURCE_INDEX) + ), + + /** defaults file and substitution ready template for conversational search with bedrock chat model*/ + CONVERSATIONAL_SEARCH_WITH_BEDROCK_DEPLOY( + "conversational-search-with-bedrock-rag-tool", + "defaults/conversational-search-rag-tool-defaults.json", + "substitutionTemplates/conversational-search-with-bedrock-rag-tool-template.json", + List.of(CREATE_CONNECTOR_CREDENTIAL_ACCESS_KEY, CREATE_CONNECTOR_CREDENTIAL_SECRET_KEY, CREATE_CONNECTOR_CREDENTIAL_SESSION_TOKEN) ); private final String useCaseName; diff --git a/src/main/resources/defaults/conversational-search-rag-tool-defaults.json b/src/main/resources/defaults/conversational-search-rag-tool-defaults.json new file mode 100644 index 000000000..c69d3eb17 --- /dev/null +++ b/src/main/resources/defaults/conversational-search-rag-tool-defaults.json @@ -0,0 +1,35 @@ +{ + "template.name": "deploy-bedrock-chat-model", + "template.description": "A template to deploy a Bedrock chat model", + "create_bedrock_connector.name": "Amazon Bedrock Connector: Claude Instant V1", + "create_bedrock_connector.description": "The connector to bedrock Claude model", + "create_bedrock_connector.protocol": "aws_sigv4", + "create_bedrock_connector.actions.url": "https://bedrock-runtime.us-west-2.amazonaws.com/model/anthropic.claude-instant-v1/invoke", + "create_bedrock_connector.actions.request_body": "{\"prompt\":\"${parameters.prompt}\", \"max_tokens_to_sample\":${parameters.max_tokens_to_sample}, \"temperature\":${parameters.temperature}, \"anthropic_version\":\"${parameters.anthropic_version}\" }", + "create_bedrock_connector.credential.access_key": "", + "create_bedrock_connector.credential.secret_key": "", + "create_bedrock_connector.credential.session_token": "", + "create_bedrock_connector.region": "us-west-2", + "create_embedding_connector.name": "Amazon Bedrock Connector: embedding", + "create_embedding_connector.description": "The connector to bedrock Titan embedding model", + "create_embedding_connector.protocol": "aws_sigv4", + "create_embedding_connector.actions.url": "https://bedrock-runtime.us-west-2.amazonaws.com/model/amazon.titan-embed-text-v2:0/invoke", + "create_embedding_connector.actions.request_body": "{ \"inputText\": \"${parameters.inputText}\" }", + "register_bedrock_model.name": "anthropic.claude-v2", + "register_bedrock_model.description": "bedrock-chat-model", + "register_bedrock_embedding_model.name": "Bedrock embedding model v2", + "register_bedrock_embedding_model.description": "Bedrock embedding model v2", + "create_ingest_pipeline.pipeline_id": "nlp-ingest-pipeline", + "create_ingest_pipeline.description": "A neural ingest pipeline", + "text_embedding.field_map.input": "passage_text", + "text_embedding.field_map.output": "passage_embedding", + "create_index.name": "my-nlp-index", + "create_index.mappings.method.engine": "lucene", + "create_index.mappings.method.space_type": "l2", + "create_index.mappings.method.name": "hnsw", + "text_embedding.field_map.output.dimension": "1024", + "rag_tool.parameters.prompt": "\n\nHuman:You are a professional data analysist. You will always answer question based on the given context first. If the answer is not directly shown in the context, you will analyze the data and find the answer. If you don't know the answer, just say don't know. \n\n Context:\n${parameters.output_field:-}\n\n\nHuman:${parameters.question}\n\nAssistant:", + "root_agent.parameters.parameters": "Answer the question as best you can.", + "root_agent.name": "Root agent", + "root_agent.description": "this is the root agent" +} diff --git a/src/main/resources/substitutionTemplates/conversational-search-with-bedrock-rag-tool-template.json b/src/main/resources/substitutionTemplates/conversational-search-with-bedrock-rag-tool-template.json new file mode 100644 index 000000000..0c15a84d7 --- /dev/null +++ b/src/main/resources/substitutionTemplates/conversational-search-with-bedrock-rag-tool-template.json @@ -0,0 +1,218 @@ +{ + "name": "${{template.name}}", + "description": "${{template.description}}", + "use_case": "CONVERSATION_SEARCH", + "version": { + "template": "1.0.0", + "compatibility": [ + "2.12.0", + "3.0.0" + ] + }, + "workflows": { + "provision": { + "nodes": [ + { + "id": "create_bedrock_connector", + "type": "create_connector", + "user_inputs": { + "name": "${{create_bedrock_connector.name}}", + "description": "Test connector for Amazon Bedrock", + "version": "1", + "protocol": "${{create_bedrock_connector.protocol}}", + "credential": { + "access_key": "${{create_bedrock_connector.credential.access_key}}", + "secret_key": "${{create_bedrock_connector.credential.secret_key}}", + "session_token": "${{create_bedrock_connector.credential.session_token}}" + }, + "parameters": { + "max_tokens_to_sample": "8000", + "service_name": "bedrock", + "temperature": "1.0E-4", + "response_filter": "$.completion", + "region": "${{create_bedrock_connector.region}}", + "anthropic_version": "bedrock-2023-05-31" + }, + "actions": [ + { + "action_type": "PREDICT", + "method": "POST", + "url": "${{create_bedrock_connector.actions.url}}", + "headers": { + "x-amz-content-sha256": "required", + "content-type": "application/json" + }, + "request_body": "${{create_bedrock_connector.actions.request_body}}" + } + ] + } + }, + { + "id": "create_embedding_connector", + "type": "create_connector", + "user_inputs": { + "name": "${{create_embedding_connector.name}}", + "description": "${{create_embedding_connector.description}}", + "version": "1", + "protocol": "${{create_embedding_connector.protocol}}", + "credential": { + "access_key": "${{create_bedrock_connector.credential.access_key}}", + "secret_key": "${{create_bedrock_connector.credential.secret_key}}", + "session_token": "${{create_bedrock_connector.credential.session_token}}" + }, + "parameters": { + "service_name": "bedrock", + "model": "amazon.titan-embed-text-v2:0", + "region": "us-west-2", + "anthropic_version": "bedrock-2023-05-31" + }, + "actions": [ + { + "action_type": "PREDICT", + "method": "POST", + "url": "${{create_embedding_connector.actions.url}}", + "headers": { + "x-amz-content-sha256": "required", + "content-type": "application/json" + }, + "request_body": "${{create_embedding_connector.actions.request_body}}", + "pre_process_function": "connector.pre_process.bedrock.embedding", + "post_process_function": "connector.post_process.bedrock.embedding" + } + ] + } + }, + + { + "id": "register_bedrock_model", + "type": "register_remote_model", + "previous_node_inputs": { + "create_bedrock_connector": "connector_id" + }, + "user_inputs": { + "name": "${{register_bedrock_model.name}}", + "function_name": "remote", + "description": "${{register_bedrock_model.description}}", + "deploy": true + } + }, + { + "id": "register_bedrock_embedding_model", + "type": "register_remote_model", + "previous_node_inputs": { + "create_embedding_connector": "connector_id" + }, + "user_inputs": { + "name": "${{register_bedrock_embedding_model.name}}", + "description": "${{register_bedrock_embedding_model.description}}", + "function_name": "remote", + "deploy": true + } + }, + { + "id": "create_ingest_pipeline", + "type": "create_ingest_pipeline", + "previous_node_inputs": { + "register_bedrock_embedding_model": "model_id" + }, + "user_inputs": { + "pipeline_id": "${{create_ingest_pipeline.pipeline_id}}", + "configurations": { + "description": "${{create_ingest_pipeline.description}}", + "processors": [ + { + "text_embedding": { + "model_id": "${{register_bedrock_embedding_model.model_id}}", + "field_map": { + "${{text_embedding.field_map.input}}": "${{text_embedding.field_map.output}}" + } + } + } + ] + } + } + }, + { + "id": "create_index", + "type": "create_index", + "previous_node_inputs": { + "create_ingest_pipeline": "pipeline_id" + }, + "user_inputs": { + "index_name": "${{create_index.name}}", + "configurations": { + "settings": { + "index": { + "default_pipeline": "${{create_ingest_pipeline.pipeline_id}}", + "knn": "true" + } + }, + "mappings": { + "properties": { + "${{text_embedding.field_map.input}}": { + "type": "text" + }, + "${{text_embedding.field_map.output}}": { + "type": "knn_vector", + "method": { + "engine": "${{create_index.mappings.method.engine}}", + "space_type": "${{create_index.mappings.method.space_type}}", + "name": "${{create_index.mappings.method.name}}", + "parameters": {} + }, + "dimension": "${{text_embedding.field_map.output.dimension}}" + } + } + } + } + } + }, + { + "id": "rag_tool", + "type": "create_tool", + "previous_node_inputs": { + "register_bedrock_model": "model_id", + "register_bedrock_embedding_model": "model_id" + }, + "user_inputs": { + "type": "RAGTool", + "name": "RAGTool", + "parameters": { + "inference_model_id": "${{register_bedrock_model.model_id}}", + "embedding_model_id": "${{register_bedrock_embedding_model.model_id}}", + "index": "${{create_index.name}}", + "embedding_field": "${{text_embedding.field_map.output}}", + "source_field": "[\"${{text_embedding.field_map.input}}\"]", + "query_type": "neural", + "input": "${parameters.question}", + "prompt": "${{rag_tool.parameters.prompt}}", + "include_output_in_agent_response": true + } + } + }, + { + "id": "root_agent", + "type": "register_agent", + "previous_node_inputs": { + "rag_tool": "tools" + }, + "user_inputs": { + "parameters": { + "prompt": "${{root_agent.parameters.parameters}}" + }, + "app_type": "chatbot", + "name": "${{root_agent.name}}", + "description": "${{root_agent.description}}", + "tools_order": [ + "rag_tool" + ], + "memory": { + "type": "conversation_index" + }, + "type": "flow" + } + } + ] + } + } +} diff --git a/src/main/resources/substitutionTemplates/conversational-search-with-cohere-model-template.json b/src/main/resources/substitutionTemplates/conversational-search-with-cohere-model-template.json index 9c919f553..bfac79265 100644 --- a/src/main/resources/substitutionTemplates/conversational-search-with-cohere-model-template.json +++ b/src/main/resources/substitutionTemplates/conversational-search-with-cohere-model-template.json @@ -1,7 +1,7 @@ { "name": "${{template.name}}", "description": "${{template.description}}", - "use_case": "SEMANTIC_SEARCH", + "use_case": "CONVERSATION_SEARCH", "version": { "template": "1.0.0", "compatibility": [