Skip to content

How to reduce input token usage for Bedrock Knowledge base chatbot?

0

I'm trying to create a RAG-based chatbot for answering known trouble shooting issues. For my knowledge base, I have a document of Q&A pairs separated by a space stored in an S3 bucket. I created an Agent using the Amazon Nova Micro model connected to a Bedrock knowledge base. The Bedrock knowledge base uses the default Bedrock parser and default chunking strategies, Titan Text Embeddings V2 for embedding, and an S3 Vector bucket storage.

Through testing and viewing the traces of my chatbot, the input token usage seems high considering my questions may only be around 10 words and each Q&A pair in the document for the knowledge base is around 50 words max.

How can I optimize the input token usage for my RAG chatbot? Are there suggestions for Q&A formatting, parsing/chunking, etc.? Is there a way to only retrieve relevant Q&A pairs to reduce input token usage, assuming this may also be a factor?

1 Answer
0

To reduce input token usage for your Bedrock Knowledge base chatbot, you can implement several optimization strategies:

  1. Configure your knowledge base retrieval settings:
  • Use the "numberOfResults" parameter to limit the number of document chunks retrieved from your knowledge base. This directly impacts token usage since fewer chunks mean fewer tokens sent to the model.
  • Test different values to find the optimal balance between accuracy and token usage.
  1. Optimize your chunking strategy:
  • Review your current default chunking settings. The chunk size significantly impacts token usage - smaller chunks can reduce tokens but might affect context quality.
  • Test various chunk sizes to determine the optimal value for your specific Q&A content.
  1. Implement prompt caching:
  • Amazon Bedrock offers prompt caching that allows you to cache relevant portions of your prompt to save on input token costs.
  • This feature reduces compute resources by skipping recomputation for cached prefixes.
  1. Format your Q&A content efficiently:
  • Structure your Q&A pairs concisely to minimize unnecessary text.
  • Remove redundant information or boilerplate text that appears in multiple entries.
  1. Limit conversation history:
  • If your chatbot maintains conversation history, test with different numbers of Q&A history pairs (2-5) and select the optimal value.
  • Each previous Q&A pair adds to your token count, so only keep what's necessary for context.
  1. Input validation and limits:
  • Implement strict input validation rules for user prompts.
  • Define maximum input lengths to prevent unnecessarily long queries.

By implementing these strategies, you should be able to significantly reduce your input token usage while maintaining the effectiveness of your RAG-based chatbot.
Sources
Cache Prompts Between Requests - Amazon Bedrock Prompt Caching - AWS
Troubleshoot latency and optimize Amazon Bedrock Agent performance | AWS re:Post
Optimizing costs of generative AI applications on AWS | AWS Machine Learning Blog
Hardening the RAG chatbot architecture powered by Amazon Bedrock: Blueprint for secure design and anti-pattern mitigation | AWS Security Blog

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.