In Ingxenye 1 of this series, we presented a solution that used the I-Amazon Titan Multimodal Embeddings model to convert individual slides from a slide deck into embeddings. We stored the embeddings in a vector database and then used the Large Language-and-Vision Assistant (LLaVA 1.5-7b) model to generate text responses to user questions based on the most similar slide retrieved from the vector database. We used AWS services including I-Amazon Bedrock, I-Amazon SageMaker, Futhi Amazon OpenSearch Serverless kulesi sixazululo.
In this post, we demonstrate a different approach. We use the Anthropic Claude 3 Sonnet model to generate text descriptions for each slide in the slide deck. These descriptions are then converted into text embeddings using the I-Amazon Titan Text Embeddings model and stored in a vector database. Then we use the Claude 3 Sonnet model to generate answers to user questions based on the most relevant text description retrieved from the vector database.
You can test both approaches for your dataset and evaluate the results to see which approach gives you the best results. In Part 3 of this series, we evaluate the results of both methods.
Ukubukwa kwesisombululo
The solution provides an implementation for answering questions using information contained in text and visual elements of a slide deck. The design relies on the concept of Retrieval Augmented Generation (RAG). Traditionally, RAG has been associated with textual data that can be processed by large language models (LLMs). In this series, we extend RAG to include images as well. This provides a powerful search capability to extract contextually relevant content from visual elements like tables and graphs along with text.
Lesi sixazululo sihlanganisa izingxenye ezilandelayo:
- Amazon Titan Text Embeddings is a text embeddings model that converts natural language text, including single words, phrases, or even large documents, into numerical representations that can be used to power use cases such as search, personalization, and clustering based on semantic similarity.
- Claude 3 Sonnet is the next generation of state-of-the-art models from Anthropic. Sonnet is a versatile tool that can handle a wide range of tasks, from complex reasoning and analysis to rapid outputs, as well as efficient search and retrieval across vast amounts of information.
- OpenSearch Serverless is an on-demand serverless configuration for Amazon OpenSearch Service. We use OpenSearch Serverless as a vector database for storing embeddings generated by the Amazon Titan Text Embeddings model. An index created in the OpenSearch Serverless collection serves as the vector store for our RAG solution.
- Amazon OpenSearch Ingestion (OSI) is a fully managed, serverless data collector that delivers data to OpenSearch Service domains and OpenSearch Serverless collections. In this post, we use an OSI pipeline API to deliver data to the OpenSearch Serverless vector store.
The solution design consists of two parts: ingestion and user interaction. During ingestion, we process the input slide deck by converting each slide into an image, generating descriptions and text embeddings for each image. We then populate the vector data store with the embeddings and text description for each slide. These steps are completed prior to the user interaction steps.
In the user interaction phase, a question from the user is converted into text embeddings. A similarity search is run on the vector database to find a text description corresponding to a slide that could potentially contain answers to the user question. We then provide the slide description and the user question to the Claude 3 Sonnet model to generate an answer to the query. All the code for this post is available in the GitHub i-repo.
Umdwebo olandelayo ubonisa ukwakheka kokungenisa.
Ukugeleza komsebenzi kuqukethe izinyathelo ezilandelayo:
- Slides are converted to image files (one per slide) in JPG format and passed to the Claude 3 Sonnet model to generate text description.
- The data is sent to the Amazon Titan Text Embeddings model to generate embeddings. In this series, we use the slide deck Qeqesha futhi usebenzise i-Stable Diffusion usebenzisa i-AWS Trainium & AWS Inferentia from the AWS Summit in Toronto, June 2023 to demonstrate the solution. The sample deck has 31 slides, therefore we generate 31 sets of vector embeddings, each with 1536 dimensions. We add additional metadata fields to perform rich search queries using OpenSearch’s powerful search capabilities.
- The embeddings are ingested into an OSI pipeline using an API call.
- The OSI pipeline ingests the data as documents into an OpenSearch Serverless index. The index is configured as the sink for this pipeline and is created as part of the OpenSearch Serverless collection.
Umdwebo olandelayo ubonisa ukwakheka kokusebenzelana komsebenzisi.
Ukugeleza komsebenzi kuqukethe izinyathelo ezilandelayo:
- Umsebenzisi uhambisa umbuzo ohlobene nedekhi yesilayidi engenisiwe.
- The user input is converted into embeddings using the Amazon Titan Text Embeddings model accessed using Amazon Bedrock. An OpenSearch Service vector search is performed using these embeddings. We perform a k-nearest neighbor (k-NN) search to retrieve the most relevant embeddings matching the user query.
- The metadata of the response from OpenSearch Serverless contains a path to the image and description corresponding to the most relevant slide.
- A prompt is created by combining the user question and the image description. The prompt is provided to Claude 3 Sonnet hosted on Amazon Bedrock.
- Umphumela walokhu okucatshangwayo ubuyiselwa kumsebenzisi.
We discuss the steps for both stages in the following sections, and include details about the output.
Okudingekayo
Ukuze usebenzise isisombululo esinikezwe kulokhu okuthunyelwe, kufanele ube ne I-akhawunti ye-AWS kanye nokujwayelana nama-FM, i-Amazon Bedrock, i-SageMaker, ne-OpenSearch Service.
This solution uses the Claude 3 Sonnet and Amazon Titan Text Embeddings models hosted on Amazon Bedrock. Make sure that these models are enabled for use by navigating to the Ukufinyelela imodeli page on the Amazon Bedrock console.
If models are enabled, the Access status will state Ukufinyelela kunikeziwe.
If the models are not available, enable access by choosing Phatha ukufinyelela kwemodeli, selecting the models, and choosing Cela ukufinyelela imodeli. The models are enabled for use immediately.
Use AWS CloudFormation to create the solution stack
You can use AWS CloudFormation to create the solution stack. If you have created the solution for Part 1 in the same AWS account, be sure to delete that before creating this stack.
Isifunda se-AWS | isixhumanisi |
---|---|
us-east-1 |
|
us-west-2 |
Ngemuva kokuthi isitaki senziwe ngempumelelo, zulazulela kuthebhu ethi Okukhiphayo kwesitaki kukhonsoli ye-AWS CloudFormation futhi uqaphele amanani we MultimodalCollectionEndpoint
futhi OpenSearchPipelineEndpoint
. You use these in the subsequent steps.
Isifanekiso se-CloudFormation sidala izinsiza ezilandelayo:
- Izindima ze-IAM - Okulandelayo Ubunikazi be-AWS Nokuphathwa Kokufinyelela (IAM) roles are created. Update these roles to apply least-privilege permissions, as discussed in Izindlela ezihamba phambili zokuphepha.
SMExecutionRole
nge Isevisi ye-Amazon Simple Storage (Amazon S3), SageMaker, OpenSearch Service, and Amazon Bedrock full access.OSPipelineExecutionRole
with access to the S3 bucket and OSI actions.
- SageMaker notebook – All code for this post is run using this notebook.
- Iqoqo le-OpenSearch Serverless - Lesi yisizindalwazi se-vector sokugcina nokukhipha okushumekiwe.
- Ipayipi le-OSI - Leli ipayipi lokungenisa idatha ku-OpenSearch Serverless.
- S3 ibhakede - Yonke idatha yalokhu okuthunyelwe igcinwe kuleli bhakede.
The CloudFormation template sets up the pipeline configuration required to configure the OSI pipeline with HTTP as source and the OpenSearch Serverless index as sink. The SageMaker notebook 2_data_ingestion.ipynb
displays how to ingest data into the pipeline using the Izicelo HTTP library.
Isifanekiso se-CloudFormation siyadala Inethiwekhi, ukubethela futhi ukufinyelela kwedatha policies required for your OpenSearch Serverless collection. Update these policies to apply least-privilege permissions.
The CloudFormation template name and OpenSearch Service index name are referenced in the SageMaker notebook 3_rag_inference.ipynb
. If you change the default names, make sure you update them in the notebook.
Hlola ikhambi
After you have created the CloudFormation stack, you can test the solution. Complete the following steps:
- Ku-console ye-SageMaker, khetha notebooks kufasitela lokuhambisa.
- Khetha
MultimodalNotebookInstance
bese ukhetha Open JupyterLab. - In Isiphequluli Sefayela, traverse to the notebooks folder to see notebooks and supporting files.
The notebooks are numbered in the sequence in which they run. Instructions and comments in each notebook describe the actions performed by that notebook. We run these notebooks one by one.
- Khetha
1_data_prep.ipynb
ukuyivula ku-JupyterLab. - Use Qalisa imenyu, khetha Qalisa Wonke Amaseli ukusebenzisa ikhodi kule notebook.
This notebook will download a publicly available indawo yama-slide, convert each slide into the JPG file format, and upload these to the S3 bucket.
- Khetha
2_data_ingestion.ipynb
ukuyivula ku-JupyterLab. - Use Qalisa imenyu, khetha Qalisa Wonke Amaseli ukusebenzisa ikhodi kule notebook.
In this notebook, you create an index in the OpenSearch Serverless collection. This index stores the embeddings data for the slide deck. See the following code:
You use the Claude 3 Sonnet and Amazon Titan Text Embeddings models to convert the JPG images created in the previous notebook into vector embeddings. These embeddings and additional metadata (such as the S3 path and description of the image file) are stored in the index along with the embeddings. The following code snippet shows how Claude 3 Sonnet generates image descriptions:
The image descriptions are passed to the Amazon Titan Text Embeddings model to generate vector embeddings. These embeddings and additional metadata (such as the S3 path and description of the image file) are stored in the index along with the embeddings. The following code snippet shows the call to the Amazon Titan Text Embeddings model:
The data is ingested into the OpenSearch Serverless index by making an API call to the OSI pipeline. The following code snippet shows the call made using the Requests HTTP library:
- Khetha
3_rag_inference.ipynb
ukuyivula ku-JupyterLab. - Use Qalisa imenyu, khetha Qalisa Wonke Amaseli ukusebenzisa ikhodi kule notebook.
This notebook implements the RAG solution: you convert the user question into embeddings, find a similar image description from the vector database, and provide the retrieved description to Claude 3 Sonnet to generate an answer to the user question. You use the following prompt template:
Amazwibela wekhodi alandelayo ahlinzeka ngokugeleza komsebenzi we-RAG:
Imiphumela
The following table contains some user questions and responses generated by our implementation. The Umbuzo ikholomu ithwebula umbuzo womsebenzisi, kanye ne- Impendulo column is the textual response generated by Claude 3 Sonnet. The isithombe column shows the k-NN slide match returned by the OpenSearch Serverless vector search.
Imiphumela ye-RAG ye-Multimodal
Query your index
You can use OpenSearch Dashboards to interact with the OpenSearch API to run quick tests on your index and ingested data.
Hlanza
To avoid incurring future charges, delete the resources. You can do this by deleting the stack using the AWS CloudFormation console.
Isiphetho
Enterprises generate new content all the time, and slide decks are a common way to share and disseminate information internally within the organization and externally with customers or at conferences. Over time, rich information can remain buried and hidden in non-text modalities like graphs and tables in these slide decks.
You can use this solution and the power of multimodal FMs such as the Amazon Titan Text Embeddings and Claude 3 Sonnet to discover new information or uncover new perspectives on content in slide decks. You can try different Claude models available on Amazon Bedrock by updating the CLAUDE_MODEL_ID
ku globals.py
Ifayela.
This is Part 2 of a three-part series. We used the Amazon Titan Multimodal Embeddings and the LLaVA model in Part 1. In Part 3, we will compare the approaches from Part 1 and Part 2.
Portions of this code are released under the Apache 2.0 License.
Mayelana nababhali
Amit Arora iyi-AI kanye ne-ML Specialist Architect e-Amazon Web Services, esiza amakhasimende ebhizinisi ukuthi asebenzise izinsiza zokufunda zomshini ezisekelwe emafini ukuze akhulise ngokushesha amasu awo. Uphinde abe ngumfundisi osizayo ohlelweni lwe-MS data science and analytics eGeorgetown University eWashington DC.
UManju Prasad is a Senior Solutions Architect at Amazon Web Services. She focuses on providing technical guidance in a variety of technical domains, including AI/ML. Prior to joining AWS, she designed and built solutions for companies in the financial services sector and also for a startup. She is passionate about sharing knowledge and fostering interest in emerging talent.
Archana Inapudi is a Senior Solutions Architect at AWS, supporting a strategic customer. She has over a decade of cross-industry expertise leading strategic technical initiatives. Archana is an aspiring member of the AI/ML technical field community at AWS. Prior to joining AWS, Archana led a migration from traditional siloed data sources to Hadoop at a healthcare company. She is passionate about using technology to accelerate growth, provide value to customers, and achieve business outcomes.
U-Antara Raisa is an AI and ML Solutions Architect at Amazon Web Services, supporting strategic customers based out of Dallas, Texas. She also has previous experience working with large enterprise partners at AWS, where she worked as a Partner Success Solutions Architect for digital-centered customers.
- I-SEO Powered Content & PR Distribution. Khuliswa Namuhla.
- I-PlatoData.Network Vertical Generative Ai. Zinike Amandla. Finyelela Lapha.
- I-PlatoAiStream. I-Web3 Intelligence. Ulwazi Lukhulisiwe. Finyelela Lapha.
- I-PlatoESG. Ikhabhoni, I-CleanTech, Amandla, Environment, Ilanga, Ukuphathwa Kwemfucuza. Finyelela Lapha.
- I-PlatoHealth. I-Biotech kanye ne-Clinical Trials Intelligence. Finyelela Lapha.
- Source: https://aws.amazon.com/blogs/machine-learning/talk-to-your-slide-deck-using-multimodal-foundation-models-hosted-on-amazon-bedrock-and-amazon-sagemaker-part-2/