Amazon Bedrock's knowledge base simplifies questions for a single document

Machine Learning


At AWS re:Invent 2023, we announced the general availability of the Amazon Bedrock knowledge base. Amazon Bedrock's Knowledge Base enables you to securely connect Amazon Bedrock's Foundation Model (FM) to your enterprise data for fully managed Acquisition Extension Generation (RAG).

In previous posts, we discussed new features such as support for hybrid search, metadata filtering to improve retrieval accuracy, and how Amazon Bedrock's knowledge base manages end-to-end RAG workflows.

Today, we're introducing a new feature to Amazon Bedrock's knowledge base that lets you chat with documents without any setup. This new feature makes it easier for businesses to use enterprise data by securely interrogating a single document without the overhead of setting up a vector database and ingesting the data. . Just provide the relevant data files as input and select the FM to get started.

But before we get into the details of this feature, let's start with the basics: what RAG is, its benefits, and how this new feature enables you to acquire and generate content tailored to your temporary needs. Let's understand.

What is search extension generation?

FM-powered artificial intelligence (AI) assistants have limitations, such as providing outdated information or struggling with context outside of training data. RAGs address these issues by allowing FMs to cross-reference authoritative knowledge sources before generating a response.

With RAG, when a user asks a question, the system retrieves relevant context from a curated knowledge base, such as company documentation. You provide this context to the FM, which uses it to generate more informed and accurate responses. RAG overcomes the limitations of FM by enriching it with the organization's own knowledge, allowing the chatbot and his AI assistant to create modern, context-specific software tailored to business needs without having to retrain his entire FM. Allow us to provide you with information. At AWS, we recognize the potential of RAGs and through the Amazon Bedrock knowledge base, we have worked to simplify RAG deployment and provide a fully managed RAG experience for him.

Short-term and immediate information needs

A knowledge base does all the heavy lifting and serves as a large, persistent store of enterprise knowledge, but it also allows temporary access to data for specific tasks or analysis within isolated user sessions. Access may be required. Traditional RAG approaches are not optimized for such short-lived, session-based data access scenarios.

Companies pay to store and manage their data. This can make RAGs less cost-effective for organizations with highly dynamic or temporary information requirements, especially if the data is only needed for specific isolated tasks or analyses.

Ask a question about one document without setup

This new ability to chat with documents within Amazon Bedrock's knowledge base addresses the challenges mentioned above. Together with FM, Amazon Bedrock provides a zero-setup method for using a single document for content retrieval and generation-related tasks. This new feature makes it easier to use enterprise data by allowing you to ask questions about your data without the overhead of setting up a vector database and ingesting the data.

Documents can now be manipulated in real-time without any prior data ingestion or database configuration. You do not need to perform any further data preparation steps before querying the data.

This zero-setup approach makes it easy to use your enterprise information assets with generative AI using Amazon Bedrock.

Use cases and benefits

Consider a recruitment agency that needs to analyze resumes and match candidates with suitable job opportunities based on their experience and skills. Previously, you had to set up a knowledge base and call a data ingestion workflow to ensure that only authorized recruiters could access the data. Additionally, you must manage cleanup when the data is no longer needed for a session or candidate. You end up paying more for vector database storage and management than you do for actual FM usage. This new feature in Amazon Bedrock's knowledge base enables recruiters to quickly and temporally analyze resumes and match candidates with the right employment opportunities based on their experience and skill set. .

As another example, consider a product manager at a technology company who needs to quickly analyze customer feedback and support tickets to identify common problems and areas for improvement. With this new feature, you can simply upload your documents and get instant insights. For example, you can ask, “What are the requirements for a mobile app?” or “What are the common pain points that customers raise about our onboarding process?” This feature allows you to quickly integrate this information without tedious data preparation or administrative overhead. You can also request an overview or key points, such as “What's important about this requirements document?”

The benefits of this feature extend beyond cost savings and operational efficiency. This new feature in Amazon Bedrock's knowledge base protects your proprietary data by eliminating the need for vector databases and data ingestion, making it accessible only within the context of an isolated user session.

Now that we have discussed the benefits of the feature and the use cases it enables, let's explore how to get started using this new feature from the Amazon Bedrock knowledge base.

Chat with documentation in the Amazon Bedrock knowledge base

There are multiple options to start using this feature.

  • Amazon Bedrock Console
  • amazon bedrock RetrieveAndGenerate API (SDK)

Let's take a look at how to get started using the Amazon Bedrock console.

  1. You can find it in the Amazon Bedrock console at the following location: orchestration In the navigation pane, select knowledge base.
  2. choose chat with docs.
  3. under modelchoose Please select a model.
  4. Please select a model. This example uses the Claude 3 Sonnet model (only Sonnet is supported at launch).
  5. choose apply.
  6. under data, you can either upload the document you want to chat about or specify the location of the Amazon Simple Storage Service (Amazon S3) bucket that contains the file. In this post, we will upload a document from our computer.

Supported file formats are PDF, MD (Markdown), TXT, DOCX, HTML, CSV, XLS, and XLSX. Make sure the file size does not exceed 10 MB and contains no more than 20,000 tokens.a token is considered a unit of text, such as a word, subword, number, or symbol, that is treated as a single entity. Due to preset ingestion token limits, we recommend using files smaller than 10MB. However, text-heavy files that are much smaller than 10 MB may violate the token limit.

Your document is now ready to chat.

You can chat with your documents in real time as shown in the following screenshot.

To customize your prompt, enter your prompt below. system prompt.

Similarly, AWS SDKs can be used in the following ways: retrieve_and_generate APIs for major coding languages. The following example uses the AWS SDK for Python (Boto3).

import boto3

bedrock_client = boto3.client(service_name="bedrock-agent-runtime")
model_id = "your_model_id_here"    # Replace with your modelID
document_uri = "your_s3_uri_here"  # Replace with your S3 URI

def retrieveAndGenerate(input_text, sourceType, model_id, document_s3_uri=None, data=None):
    region = 'us-west-2'  
    model_arn = f'arn:aws:bedrock:{region}::foundation-model/{model_id}'

    if sourceType == "S3":
        return bedrock_client.retrieve_and_generate(
            input={'text': input_text},
            retrieveAndGenerateConfiguration={
                'type': 'EXTERNAL_SOURCES',
                'externalSourcesConfiguration': {
                    'modelArn': model_arn,
                    'sources': [
                        {
                            "sourceType": sourceType,
                            "s3Location": {
                                "uri": document_s3_uri  
                            }
                        }
                    ]
                }
            }
        )
        
    else:
        return bedrock_client.retrieve_and_generate(
            input={'text': input_text},
            retrieveAndGenerateConfiguration={
                'type': 'EXTERNAL_SOURCES',
                'externalSourcesConfiguration': {
                    'modelArn': model_arn,
                    'sources': [
                        {
                            "sourceType": sourceType,
                            "byteContent": {
                                "identifier": "testFile.txt",
                                "contentType": "text/plain",
                                "data": data  
                            }
                        }
                    ]
                }
            }
        )

response = retrieveAndGenerate(
                                input_text="What is the main topic of this document?",
                                sourceType="S3", 
                                model_id=model_id,
                                document_s3_uri=document_uri
                              )
                    
print(response['output']['text'])

conclusion

In this post, we explained how Amazon Bedrock's knowledge base simplifies asking questions about a single document. He explored the core concepts behind RAG, the challenges this new feature addresses, and the different use cases RAG enables across different roles and industries. It also shows how to configure and use this feature using the Amazon Bedrock console and AWS SDKs, demonstrating the simplicity of this feature and providing a zero-setup solution to collect information from a single document without setting up a vector database. Showed flexibility. .

To further explore the capabilities of Amazon Bedrock's knowledge base, see the following resources:

Share and learn with the Community.aws Generative AI community.


About the author


Suman Debnath is the lead developer advocate for machine learning at Amazon Web Services. He frequently speaks at his AI/ML conferences, events, and meetups around the world. He has a passion for large-scale distributed systems and is an avid fan of Python.


Sebastian Munera He is a software engineer on the Amazon Bedrock Knowledge Bases team at AWS, focused on building customer solutions that leverage Generative AI and RAG applications. He has previously worked on building generative AI-based solutions for customers to streamline processes and low-code/no-code applications. In his spare time, he enjoys running, lifting, and tinkering with technology.



Source link

Leave a Reply

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