Create a Generative AI Slack Chat Assistant Utilizing Amazon Bedrock and Amazon Kendra

Create a Generative AI Slack Chat Assistant Utilizing Amazon Bedrock and Amazon KendraMore Info

In today’s data-driven business landscape, employees and stakeholders often struggle to swiftly find the information they need. This search for answers can lead to decreased productivity and increased frustration. A generative AI Slack chat assistant can alleviate these issues by offering users an intelligent interface to access information seamlessly. Leveraging the capabilities of natural language processing and generation, the chat assistant can comprehend user queries, extract relevant information from multiple sources, and deliver personalized responses.

By harnessing the power of generative AI along with Amazon Web Services (AWS) tools such as Amazon Bedrock, Amazon Kendra, and Amazon Lex, this solution presents a sample architecture for creating a smart Slack chat assistant. This assistant enhances information access, improves user experiences, and boosts productivity within organizations.

Why Choose Amazon Kendra for Your RAG Application?

Amazon Kendra is a fully managed service that offers advanced semantic search capabilities, enabling high-accuracy document and passage ranking. It allows rapid development of generative AI applications using enterprise data, ensuring that the most pertinent content is retrieved for optimal Retrieval Augmented Generation (RAG) outcomes. The quality of responses from large language models (LLMs) is significantly better when utilizing Amazon Kendra compared to traditional keyword-based search solutions.

With easy-to-use deep learning search models pre-trained across 14 domains, Amazon Kendra requires no machine learning expertise. It can index content from a variety of sources such as databases, content management systems, file shares, and web pages.

Furthermore, the FAQ feature in Amazon Kendra enhances the overall retrieval capabilities, allowing the RAG system to toggle between prewritten FAQ responses and dynamically generated answers by querying the broader knowledge base. This integration ensures that the model can access a comprehensive knowledge base when crafting responses and improves response quality while decreasing the language model’s workload for generating standard answers from scratch.

This solution allows for customizations in model selection, prompt engineering, and FAQ additions without delving into the complexities of word embeddings or document chunking typically associated with RAG implementations.

Solution Overview

The chat assistant is intended to help users by responding to their inquiries and providing information on various topics. It serves as an internal Slack tool for employees and stakeholders seeking quick access to necessary information.

The architecture incorporates Amazon Lex for intent detection, AWS Lambda for processing queries, Amazon Kendra for searching FAQs and web content, and Amazon Bedrock for generating contextually relevant responses powered by LLMs. By integrating these services, the chat assistant can interpret natural language queries, extract pertinent information from diverse data sources, and deliver human-like responses tailored to user needs. This solution exemplifies the advantages of generative AI in creating intelligent virtual assistants that streamline workflows and enrich user experiences.

Architecture Diagram

The following diagram depicts a RAG approach wherein users submit queries via the Slack application and receive generated responses based on data indexed in Amazon Kendra. In this example, we utilize the Amazon Kendra Web Crawler as the data source and include FAQs stored on Amazon Simple Storage Service (Amazon S3). For a comprehensive list of supported data source connectors for Amazon Kendra, please refer to this blog post.

The step-by-step workflow of the architecture is outlined below:

  1. A user submits a query, such as “What is the AWS Well-Architected Framework?” through the Slack app.
  2. The query is processed by Amazon Lex, which identifies the user’s intent.
  3. Currently, two intents are configured in Amazon Lex: Welcome and FallbackIntent.
  4. The welcome intent is programmed to greet users when they input a greeting like “hi” or “hello,” responding with, “Hello! I can help you with queries based on the documents provided. Ask me a question.”
  5. The fallback intent is executed through a Lambda function.

The Lambda function searches Amazon Kendra FAQs via the search_Kendra_FAQ method, taking the user’s query and Amazon Kendra index ID as inputs. If a match with a high confidence score is found, the FAQ answer is returned to the user.

def search_Kendra_FAQ(question, kendra_index_id):
    """This function takes in the question from the user, and checks if the question exists in the Kendra FAQs.
    :param question: The question the user is asking that was asked via the frontend input text box.
    :param kendra_index_id: The kendra index containing the documents and FAQs
    :return: If found in FAQs, returns the answer along with any relevant links. If not, returns False and then calls kendra_retrieve_document function.
    """
    kendra_client = boto3.client('kendra')
    response = kendra_client.query(IndexId=kendra_index_id, QueryText=question, QueryResultTypeFilter='QUESTION_ANSWER')
    for item in response['ResultItems']:
        score_confidence = item['ScoreAttributes']['ScoreConfidence']
        # Only using FAQ answers that have a very high confidence score
        if score_confidence == 'VERY_HIGH' and len(item['AdditionalAttributes']) > 1:
            text = item['AdditionalAttributes'][1]['Value']['TextWithHighlightsValue']['Text']
            url = "None"
            if item['DocumentURI'] != '':
                url = item['DocumentURI']
            return (text, url)
    return (False, False)

If no suitable match is found, relevant documents from Amazon Kendra with a high confidence score will be retrieved through the kendra_retrieve_document method and forwarded to Amazon Bedrock to generate a context-based response.

def kendra_retrieve_document(question, kendra_index_id):
    """This function takes in the question from the user, and retrieves relevant passages based on default PageSize of 10.
    :param question: The question the user is asking that was asked via the frontend input text box.
    :param kendra_index_id: The kendra index containing the documents and FAQs
    :return: Returns the context to be sent to the LLM and document URIs to be returned as relevant data sources.
    """
    kendra_client = boto3.client('kendra')
    documents = kendra_client.retrieve(IndexId=kendra_index_id, QueryText=question)
    text = ""
    uris = set()
    if len(documents['ResultItems']) > 0:
        for i in range(len(documents['ResultItems'])):
            score_confidence = documents['ResultItems'][i]['ScoreAttributes']['ScoreConfidence']
            if score_confidence == 'VERY_HIGH' or score_confidence == 'HIGH':
                text += documents['ResultItems'][i]['DocumentExcerpt']['Text']
                uris.add(documents['ResultItems'][i]['DocumentURI'])
    return (text, uris)

This assistant is a great way to improve productivity within organizations, and for further learning on this topic, visit this authoritative resource or explore excellent job opportunities at Amazon.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *