aws-samples / bedrock-claude-chat

AWS-native chatbot using Bedrock + Claude (+Mistral)
MIT No Attribution
872 stars 315 forks source link

[BUG] RAG with KnowledgeBase DB doesn't seem to work #537

Closed Peter-Lankton closed 1 month ago

Peter-Lankton commented 1 month ago

Describe the bug

KnowledgeBase Bedrock doesn't seem to be working with CDK Deploy and updating cdk.json on branch 'v1'.

To Reproduce

I followed the directions for CDK deploy and updated the cdk.json file for "useBedrockKnowledgeBaseForRag": true but when I log into my AWS Account I don't see that a KnowledgeDB has been provisioned under BedrockKnowledgeBase, after running cdk deploy.

I also have "mistralEnabled:true", so not sure if that could be the reason as well...

Additionally, whenever I add my S3 URL for syncing to presumably BedrockKnowledge it 'syncs' but doesn't create a KnowledgeDB either-- It also doesn't create one with the 'upload files' either.

Which brings me to the issue of when chatting with a bot created with an S3 or uploaded files I get a persistent 'An error occurred while responding' message in my chat.

However, if I create a bot without any uploaded files or s3 url then the chat still works, just not a RAG based one.

Update: Tried it with "mistralEnabled:False" and the KnowledgeBase DB was provisioned but the RAG functionality still doesn't seem to work.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Logs from sync failure An error occurred while synchronizing Knowledge. Please check the following message: {"SdkHttpMetadata":{"AllHttpHeaders":{"x-amzn-RequestId":["abe8850e-2358-4bcf-bf5a-d622b828d44c"],"Content-Length":["5136"],"Date":["Tue, 17 Sep 2024 19:59:03 GMT"],"Content-Type":["application/x-amz-json-1.1"]},"HttpHeaders":{"Content-Length":"5136","Content-Type":"application/x-amz-json-1.1","Date":"Tue, 17 Sep 2024 19:59:03 GMT","x-amzn-RequestId":"abe8850e-2358-4bcf-bf5a-d622b828d44c"},"HttpStatusCode":200},"SdkResponseMetadata":{"RequestId":"abe8850e-2358-4bcf-bf5a-d622b828d44c"},"Build":{"Arn":"arn:aws:codebuild:us-east-1::build/BedrockKnowledgeBaseCodebui-fKfwiQY9GZbi:0af204b1-421b-4333-bf51-ba5cb38d92d4","Artifacts":{"Location":""},"BuildComplete":true,"BuildNumber":1,"BuildStatus":"FAILED","Cache":{"Type":"NO_CACHE"},"CurrentPhase":"COMPLETED","EncryptionKey":"arn:aws:kms:us-east-1::alias/aws/s3","EndTime":1726603140271,"Environment":{"ComputeType":"BUILD_GENERAL1_SMALL","EnvironmentVariables":[{"Name":"KNOWLEDGE","Type":"PLAINTEXT","Value":"{\"sitemap_urls\":{\"L\":[]},\"s3_urls\":{\"L\":[{\"S\":\"s/\"}]},\"filenames\":{\"L\":[]},\"source_urls\":{\"L\":[]}}"},{"Name":"PK","Type":"PLAINTEXT","Value":""},{"Name":"SK","Type":"PLAINTEXT","Value":""},{"Name":"BEDROCK_KNOWLEDGE_BASE","Type":"PLAINTEXT","Value":"{\"chunking_strategy\":{\"S\":\"default\"},\"max_tokens\":{\"NULL\":true},\"search_params\":{\"M\":{\"max_results\":{\"N\":\"20\"},\"search_type\":{\"S\":\"hybrid\"}}},\"overlap_percentage\":{\"NULL\":true},\"data_source_ids\":{\"NULL\":true},\"open_search\":{\"M\":{\"analyzer\":{\"NULL\":true}}},\"knowledge_base_id\":{\"NULL\":true},\"embeddings_model\":{\"S\":\"titan_v1\"}}"},{"Name":"BEDROCK_CLAUDE_CHAT_DOCUMENT_BUCKET_NAME","Type":"PLAINTEXT","Value":"bedrockchatstack-documentbucketae41e5a9-o748lw7yj94a"}],"Image":"aws/codebuild/standard:7.0","ImagePullCredentialsType":"CODEBUILD","PrivilegedMode":true,"Type":"LINUX_CONTAINER"},"Id":"BedrockKnowledgeBaseCodebui-fKfwiQY9GZbi:0af204b1-421b-4333-bf51-ba5cb38d92d4","Initiator":"states/EmbeddingStateMachine79E88DC2-SQ7YMpu83nBt","Logs":{"CloudWatchLogsArn":"arn:aws:logs:us-east-1::log-group:/aws/codebuild/BedrockKnowledgeBaseCodebui-fKfwiQY9GZbi:log-stream:0af204b1-421b-4333-bf51-ba5cb38d92d4","DeepLink":"","GroupName":"/aws/codebuild/BedrockKnowledgeBaseCodebui-fKfwiQY9GZbi","StreamName":"0af204b1-421b-4333-bf51-ba5cb38d92d4"},"Phases":[{"DurationInSeconds":0,"EndTime":1726602997529,"PhaseStatus":"SUCCEEDED","PhaseType":"SUBMITTED","StartTime":1726602997469},{"DurationInSeconds":0,"EndTime":1726602998224,"PhaseStatus":"SUCCEEDED","PhaseType":"QUEUED","StartTime":1726602997529},{"Contexts":[{"Message":"","StatusCode":""}],"DurationInSeconds":10,"EndTime":1726603009011,"PhaseStatus":"SUCCEEDED","PhaseType":"PROVISIONING","StartTime":1726602998224},{"Contexts":[{"Message":"","StatusCode":""}],"DurationInSeconds":16,"EndTime":1726603025936,"PhaseStatus":"SUCCEEDED","PhaseType":"DOWNLOAD_SOURCE","StartTime":1726603009011},{"Contexts":[{"Message":"","StatusCode":""}],"DurationInSeconds":18,"EndTime":1726603044746,"PhaseStatus":"SUCCEEDED","PhaseType":"INSTALL","StartTime":1726603025936},{"Contexts":[{"Message":"","StatusCode":""}],"DurationInSeconds":0,"EndTime":1726603044781,"PhaseStatus":"SUCCEEDED","PhaseType":"PRE_BUILD","StartTime":1726603044746},{"Contexts":[{"Message":"Error while executing command: cdk deploy --require-approval never BrChatKbStack$BOT_ID. Reason: exit status 1","StatusCode":"COMMAND_EXECUTION_ERROR"}],"DurationInSeconds":94,"EndTime":1726603139746,"PhaseStatus":"FAILED","PhaseType":"BUILD","StartTime":1726603044781},{"Contexts":[{"Message":"","StatusCode":""}],"DurationInSeconds":0,"EndTime":1726603139782,"PhaseStatus":"SUCCEEDED","PhaseType":"POST_BUILD","StartTime":1726603139746},{"Contexts":[{"Message":"","StatusCode":""}],"DurationInSeconds":0,"EndTime":1726603139981,"PhaseStatus":"SUCCEEDED","PhaseType":"UPLOAD_ARTIFACTS","StartTime":1726603139782},{"Contexts":[{"Message":"","StatusCode":""}],"DurationInSeconds":0,"EndTime":1726603140271,"PhaseStatus":"SUCCEEDED","PhaseType":"FINALIZING","StartTime":1726603139981},{"PhaseType":"COMPLETED","StartTime":1726603140271}],"ProjectName":"BedrockKnowledgeBaseCodebui-fKfwiQY9GZbi","QueuedTimeoutInMinutes":480,"SecondarySourceVersions":[],"SecondarySources":[],"ServiceRole":"arn:aws:iam::481665089962:role/BedrockChatStack-BedrockKnowledgeBaseCodebuildProje-kQr6lEy6kH7k","Source":{"Buildspec":"{\n \"version\": \"0.2\",\n \"phases\": {\n \"install\": {\n \"runtime-versions\": {\n \"nodejs\": \"18\"\n },\n \"commands\": [\n \"npm install -g aws-cdk\"\n ],\n \"on-failure\": \"ABORT\"\n },\n \"build\": {\n \"commands\": [\n \"cd cdk\",\n \"npm ci\",\n \"export BOT_ID=$(echo $SK | awk -F'#' '{print $3}')\",\n \"sed -i 's|bin/bedrock-chat.ts|bin/bedrock-knowledge-base.ts|' cdk.json\",\n \"cdk deploy --require-approval never BrChatKbStack$BOT_ID\"\n ]\n }\n }\n}","InsecureSsl":false,"Location":"bedrockchatstack-sourcebucketforcodebuildbc729025-oeeeoowsuivi/","Type":"S3"},"StartTime":1726602997469,"TimeoutInMinutes":45}}

Peter-Lankton commented 1 month ago

Update:

In case anyone else experiences this issue...

I resolved it by doing the following:

  1. Disable Mistral
  2. Deploy the app
  3. Upload one document for the creation of the Knowledge DB to be used with RAG
  4. Go to AWS Bedrock
  5. Copy the S3 bucket linked
  6. open terminal; cd into wherever your RAG documents are then aws s3 . --recursively s3://<copied-bucket-from-step-5>

Now the app has the Knowledge DB with your docs.

Additional Tip for Cost Management:

By default the knowledge db is provisioned with 10 OCUs for indexing and 10 OCUs for searching which is the max and is about 1000 USD a month...

However, you can go to AWS open search > server less > dashboard > configure units > set both to 2 OCUs which should lower bill to 350 USD a month!

If you don't then by default you might end up paying 700 USD.

But, per this article https://aws.amazon.com/about-aws/whats-new/2024/06/amazon-opensearch-serverless-entry-cost-half-collection-types/

It should be able to get the price lower... I'll play around with deleting docs (~5 GB) to see what to get the cheaper half collection types implemented for those other cost conscious solo founders out there...

statefb commented 1 month ago

When the option to use the Knowledge Base (KB) is enabled, the KB instance is created at a different timing than the application deployment. Specifically, it is created simultaneously when you create a bot, so please be aware of this. It should not be related to whether Mistral is enabled or disabled. If you still experience any issues after the "sync is complete," we would appreciate it if you could report the details again.

Peter-Lankton commented 1 month ago

When the option to use the Knowledge Base (KB) is enabled, the KB instance is created at a different timing than the application deployment. Specifically, it is created simultaneously when you create a bot, so please be aware of this. It should not be related to whether Mistral is enabled or disabled. If you still experience any issues after the "sync is complete," we would appreciate it if you could report the details again.

ah ok that makes sense. thank you for clarifying I'll close issue