Skip to content

Commit

Permalink
Added conversation search default use case with RAG tool (opensearch-…
Browse files Browse the repository at this point in the history
…project#732)

Added conversation search use case with RAG tool

Signed-off-by: owaiskazi19 <[email protected]>
  • Loading branch information
owaiskazi19 authored Jun 10, 2024
1 parent 53126cb commit 9704727
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "${{template.name}}",
"description": "${{template.description}}",
"use_case": "SEMANTIC_SEARCH",
"use_case": "CONVERSATION_SEARCH",
"version": {
"template": "1.0.0",
"compatibility": [
Expand Down

0 comments on commit 9704727

Please sign in to comment.