Generative AI  

Create Amazon Bedrock Knowledge Base with Kendra GenAI Index

Introduction

Building upon the article "Create an Amazon Kendra GenAI index with SharePoint Online," this article demonstrates how to enhance your enterprise search capabilities using Amazon Bedrock Knowledge Bases. By connecting Bedrock Knowledge Base with a Kendra GenAI index, organizations can transform traditional document searches into interactive, AI-powered conversations that provide contextually relevant answers with source citations. This solution is particularly valuable for enterprises seeking to make their SharePoint documentation more accessible, enabling use cases such as automated customer support, internal knowledge discovery, and intelligent document querying.

Prerequisites

  1. An AWS account with administrator access or appropriate IAM permissions.
    1. Amazon Bedrock
    2. Amazon Kendra
    3. IAM role creation
  2. Amazon Bedrock model access is enabled for at least one of these foundation models.
    1. Claude (Anthropic)
    2. Titan Text
    3. Other supported Bedrock models
  3. A configured Amazon Kendra GenAI index with SharePoint Online (as detailed in "Create an Amazon Kendra GenAI index with SharePoint Online").
  4. AWS Region where both Amazon Bedrock and Amazon Kendra services are available.
  5. Install or update to the latest version of the AWS CLI.
  6. Get credentials to grant programmatic access.

Create a Knowledge Base in Amazon Bedrock

Perform the following steps to create a knowledge base in Amazon Bedrock to connect with Kendra GenAI index using AWS CLI.

  • Launch Windows command prompt.
  • Create a kb-trust-policy.json file and add the following JSON. Replace <account-id> with the appropriate value.
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "AmazonBedrockKnowledgeBaseTrustPolicy",
          "Effect": "Allow",
          "Principal": {
            "Service": "bedrock.amazonaws.com"
          },
          "Action": "sts:AssumeRole",
          "Condition": {
            "StringEquals": {
              "aws:SourceAccount": "<account-id>"
            },
            "ArnLike": {
              "aws:SourceArn": "arn:aws:bedrock:us-east-1:<account-id>:knowledge-base/*"
            }
          }
        }
      ]
    }
    
    
  • Enter the following command to create a role for the knowledge base.
    aws iam create-role ^
      --role-name AmazonBedrockExecutionRoleForKnowledgeBase_kendrarole ^
      --assume-role-policy-document file://kb-trust-policy.json
    
  • Create a kb-permission-policy.json file and add the following JSON. Replace <account-id>, <region> and <kendra-index-id> with appropriate values.
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "AmazonBedrockKnowledgeBaseKendraIndexAccessStatement",
          "Effect": "Allow",
          "Action": [
            "kendra:Retrieve",
            "kendra:DescribeIndex"
          ],
          "Resource": [
            "arn:aws:kendra:<region>:<account-id>:index/<kendra-index-id>"
          ]
        }
      ]
    }
    
  • Enter the following command to attach the permission policy to the knowledge base role.
    aws iam put-role-policy ^
      --role-name AmazonBedrockExecutionRoleForKnowledgeBase_kendrarole ^
      --policy-name AmazonBedrockExecutionRoleForKnowledgeBase_kendrapolicy ^
      --policy-document file://kb-permission-policy.json
    
  • Create a kb-configuration.json file and add the following JSON. Replace <account-id>, <region> and <kendra-index-id> with appropriate values.
    {
      "type": "KENDRA",
      "kendraKnowledgeBaseConfiguration": {
        "kendraIndexArn": "arn:aws:kendra:<region>:<account-id>:index/<kendra-index-id>"
      }
    }
    
  • Enter the following command to create the knowledge base. Replace <account-id> with the appropriate value.
    aws bedrock-agent create-knowledge-base ^
      --name "spo-knowledge-base-kendra-genai-index" ^
      --description "Knowledge base backed by Kendra Gen AI Index" ^
      --role-arn "arn:aws:iam::<account-id>:role/AmazonBedrockExecutionRoleForKnowledgeBase_kendrarole" ^
      --knowledge-base-configuration file://kb-configuration.json
    

Validate the knowledge base

Perform the following steps to validate the newly created knowledge base using the AWS Console.

  1. Navigate to the Amazon Bedrock service in the AWS Console.
  2. Select Knowledge Bases in the navigation pane.
  3. Select the newly created knowledge base. On the right-hand side, you will see the "Test Knowledge Base" section. Click on Select model.
  4. Choose any model based on your requirement. Click Apply.
  5. Enter the prompt, and you could see the response generated from the knowledge base.

Summary

This article describes how to create and configure an Amazon Bedrock Knowledge Base with Kendra GenAI index using AWS CLI.