Retrieve data and generate AI responses with knowledge bases - Amazon Bedrock

Retrieve data and generate AI responses with knowledge bases

You can integrate proprietary information into your generative-AI applications with Amazon Bedrock knowledge bases. Using the Retrieval Augment Generation (RAG) technique, a knowledge base searches your data to find the most useful information and then uses it to answer natural language questions.

After you set up a knowledge base, you can then take advantage of the knowledge base in the following ways:

  • Configure your RAG application to use the RetrieveAndGenerate API to query your knowledge base and generate responses from the information it retrieves. You can also call the Retrieve API to query your knowledge base with information retrieved directly from the knowledge base.

  • Associate your knowledge base with an agent (for more information, see Automate tasks in your application using conversational agents) to add RAG capability to the agent by helping it reason through the steps it can take to help end users.

A knowledge base can be used not only to answer user queries, and analyze documents, but also to augment prompts provided to foundation models by providing context to the prompt. When answering user queries, the knowledge base retains conversation context. The knowledge base also grounds answers in citations so that users can find further information by looking up the exact text that a response is based on and also check that the response makes sense and is factually correct.

You take the following steps to set up and use your knowledge base.

  1. Gather source documents to add to your knowledge base.

  2. Store your source documents in a supported data source.

  3. (Optional if using Amazon S3 to store your source documents) Create a metadata file for each source document to allow for filtering of results during knowledge base query.

  4. (Optional) Set up your own supported vector store to index the vector embeddings representation of your data. You can use the Amazon Bedrock console to create an Amazon OpenSearch Serverless vector store for you.

  5. Create and configure your knowledge base. You must enable model access to use a model that's supported for knowledge bases.

    If you use the Amazon Bedrock API, take note of your model Amazon Resource Name (ARN) that's required for converting your data into vector embeddings and for knowledge base retrieval and generation. Copy the model ID for your chosen model for knowledge bases and construct the model ARN using the model (resource) ID, following the provided ARN examples for your model resource type.

    If you use the Amazon Bedrock console, you are not required to construct a model ARN, as you can select an available model as part of the steps for creating a knowledge base.

  6. Set up your application or agent to query the knowledge base and return augmented responses.