iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📖

re:Invent 2025: Building Generative AI Apps with Amazon DocumentDB – Practical RAG and Vector Search

に公開
2025/12/10

Introduction

By transcribing various overseas lectures into Japanese articles, we aim to make hidden, high-quality information more accessible. In this project, we are tackling the following presentation!

For transcription articles of re:Invent 2025, please check the information compiled in this Spreadsheet. Please take a look.

📖re:Invent 2025: AWS re:Invent 2025 - Supercharge app intelligence using gen AI with Amazon DocumentDB (DAT313)

In this session, Principal Solutions Architect Cody Allen and Senior Solutions Architect Doug Bonser explain building generative AI applications utilizing Amazon DocumentDB. They introduce the importance of vector embeddings in RAG architectures, the characteristics and selection criteria for two types of vector indexes—IVFFlat and HNSW—and three practical access patterns. Specifically, they demonstrate the DocumentDB TSQL plugin powered by Amazon Bedrock for converting SQL statements to MQL, building a multilingual chatbot, and data exploration and code generation using the Model Context Protocol (MCP) server. They emphasize that customer data is the true differentiator, and building gen AI applications on existing data foundations can reduce architectural complexity.

https://www.youtube.com/watch?v=YL1eKFuwFqw
Please note that this is an automatically generated article that maintains the content of the original lecture as much as possible. Please be aware that there may be typos or incorrect information.

Main Content

Thumbnail 0

Generative AI and DocumentDB: An Era Where Data is the Differentiator

First, let me confirm that you are in the right session. This is DAT 313. I will talk about how to supercharge your app intelligence with DocumentDB. Are you ready? It is a brand new concept you have never heard of before. It is generative AI. This is something new, right? Rest assured, I will explain it step-by-step. Raise your hand if you haven't attended 17 sessions on Gen AI today since lunch. No, I'm just kidding.

Thumbnail 30

Now, I am going to talk about several different topics. I will explain Gen AI. I will introduce myself shortly, so please wait. I will talk about Gen AI, but from a database perspective. I want to look at Gen AI from the perspective of DocumentDB, which is your data store. I will talk about these foundations, which are vector embeddings on a database. I will explain this important part. The foundation for everything I am going to show you is the access patterns. I will explain these as well.

I am Cody Allen. I am a Principal Solutions Architect for DocumentDB. With me is Doug Bonser, a Senior Solutions Architect for DocumentDB. What Doug and I do every day is talk to you. We talk to customers every day. Actually, talking about DocumentDB is our favorite thing to do. In these conversations, we discuss Gen AI, what customers are doing with Gen AI, the proof of concepts they are implementing, and the enterprise applications they are deploying. And we want to share that with you. We want to tell you what we are seeing. We will show you some tools, give you a demo of what our customers are doing and what we are doing with Gen AI, explain access patterns, and finish with best practices.

To say the least, building a new generative AI application is overwhelming. Many variables and many different factors are involved. So, we will provide you with best practices. We will talk about things you can take home and start building these applications. Let's start with the background of what Gen AI is. Just kidding. You already know what Gen AI is, right?

Thumbnail 110

What is interesting is that according to McKinsey, Gen AI is expected to add between $2.6 trillion and $4.4 trillion to the global economy annually. That's an amazing number. I can't even imagine a number of that scale. But really, what this means is that Gen AI apps have become an enterprise initiative. Everyone is talking about it. Is there anyone here who works at a company that isn't talking about Gen AI? Exactly, there isn't, right? Everyone is focused on this and trying to find out what they can do. Because this is disruptive.

Thumbnail 160

There is a massive number of models available on the cloud and models that can be run locally. I will show you some of them. However, the lifeblood of all these Gen AI applications is data. Secure data, enriched data, and your data. Everything starts there, and that is the most important thing. Doug and I talked here last year about generative AI in Amazon DocumentDB. We dove pretty deep into vector indexes and how to use them. And what we told you then was that your data is the differentiator. And guess what? Nothing has changed. Your data is still the differentiator. That is what creates Gen AI applications unique to your business.

Thumbnail 180

Benefits of Building Generative AI Applications Leveraging Existing Data Foundations

Now, generative AI applications are seen as a new type of application built on top of existing data foundations. This means you want to connect to existing data sources. You want to build these applications by connecting to data lakes, data warehouses, external or hybrid data stores, document data stores, etc. Customers are telling us that they basically do not want to create a new data architecture for a new set of applications. They want to utilize systems they already have, systems they are already using in production. They want to utilize existing architecture to create these new Gen AI workflows, and they want these new Gen AI workflows and applications to follow already established enterprise rules.

Thumbnail 230

Now, keeping vectors as close as possible to the underlying data store makes this architecture really simple. The movement of data and the ETL processes that need to be executed are minimized. Performance is also improved. There are fewer points that can fail. Furthermore, there is the advantage of reducing licensing costs by introducing new applications. And speaking of that, when you start adding these new types of application layers, what happens? You have to learn new APIs. You have to learn new SDKs. The overhead of new programming languages to implement these occurs.

For example, if you place a vector store on top of an existing database, you can utilize the knowledge you already have. So, for example, if your organization is familiar with Redis and is storing data in Redis, then the vector capability of MemoryDB would be suitable. This also applies to Aurora. It applies to RDS, OpenSearch, and Neptune Analytics. And guess what? It also applies to Amazon DocumentDB, which is why you are here. Generally, this allows you to avoid introducing new database components just to build AI applications. And you get the confidence that your existing data structures are already proven in production. They already meet security requirements. They already meet availability, storage, and compute requirements. By building on top of that.

Thumbnail 290

Thumbnail 300

Foundations of Vector Embeddings and the Reality of Generative AI in Enterprises

That said, let's move on to that foundational part we were talking about earlier: vector embeddings. This is an important component of vectors in databases. What is a vector embedding?

Thumbnail 330

Well, it's simply a numerical representation of text, or even videos and photos, but regarding DocumentDB, we are focusing on text. We can all see and understand what is displayed on the left. We can read the words and understand the context, but computers cannot. Therefore, we need to convert it into numbers. Since machines understand numbers, we have to convert that text into numbers. This allows the machine to understand context the same way we do. Words have different meanings when they are near other words. When you ask a question with a specific rhythm or pattern, the meaning changes, and as a result, the results you get can also change. This is not a binary search just looking for names, addresses, or email addresses. What we are looking for is context, that is, a natural query language.

Thumbnail 350

Now, as I mentioned earlier, Doug and I are constantly talking to customers, and what they are doing is building and deploying these generative AI proofs of concept into production. However, the real purpose of doing this is to improve customer experience. They want to improve employee productivity. We see this often inside AWS as well. They want to create completely new content or improve business operations. This is common to every company we talk to, including finance, engineering, customer support, sales, and marketing. Customers are running these pilot programs to try them out and see what is possible. They are experimenting with generative AI.

Very strategic customers are building chatbots. They are doing virtual assistants. They are doing conversational search, natural query language, and code generation. You know, I was a terrible programmer before generative AI came along. Now I am a terrible programmer who uses generative AI, and generative AI fixes it for me. It's fantastic. I believe it's fantastic. I don't think you do, though.

Thumbnail 410

Thumbnail 420

Amazon Bedrock-Powered DocumentDB TSQL Plugin: A Tool for the Relational Mind

Let's talk about these access patterns. What can you do with them? The first thing we are going to look at is building a tool that uses some generative AI tools to assist with DocumentDB. We built this Amazon Bedrock-powered DocumentDB TSQL plugin for mongosh. Phew, that's easy to say. It's about 72 characters long. Clearly, I am not from the marketing department.

Is there anyone here who is a relational database person? A DBA or someone who specializes in that? Me too. SQL Server, Oracle, MySQL, Postgres—that's my expertise. Aside from the blinking cursor, this looks like home to me. It's like a warm cup of coffee you drink in a cozy corner on a cold day. I can understand this. Oh my god, I can't understand this anymore. Oh, I can understand it again. SELECT star FROM table, join this other table, WHERE field equals field. So, imagine when I started my MongoDB journey, my DocumentDB journey—I had to learn MongoDB Query Language, MQL, and that warm cup of coffee that was my area of expertise became this. Yes, exactly. Everything got distorted. I can't understand it anymore. I have to do a lookup. What is a dollar lookup? I have to do this dollar project. I am not a project manager. Why do I have to care about project?

Thumbnail 490

Thumbnail 500

Writing the UPDATE statement didn't get any easier either. Again, this is home. I can understand this. It feels good. Even at this distance, it feels good. And now I had to do something like this in MQL. I have to do that dollar lookup again for every item. I have to write a function to update this. My simple lizard brain, my relational brain, couldn't understand this.

Thumbnail 510

So, we built this tool. It translates these TSQL commands into DocumentDB commands within the mongosh environment and is configured to automatically handle all APIs, operators, and data types supported by DocumentDB. And guess what? We actually built two versions. One connects to Bedrock, and the other uses Ollama, allowing you to customize the prompt and LLM. In other words, if you don't want to connect to Bedrock, you can actually use this on your local machine. Dramatic pause.

Thumbnail 540

Thumbnail 560

Thumbnail 570

Thumbnail 580

TSQL Plugin Demo: Query Translation with Ollama and Bedrock

Let's move on to the demo. So, this is published in our GitHub repository. There are two different packages here, and we will look at the Ollama plugin first. We enter that directory and run the shell script to set it up. What this does is install all dependencies and download the Ollama LLM. We can confirm that immediately. It uses a compatibility tool to handle compatibility and references the operators that should be used in these mongosh commands for DocumentDB. Once that is done, you can see that the CodeLlama 7B library has been installed. Now, this is a very large library—it's 3.8 GB. It takes time. In a real environment, it's not as fast as the demo, but this allows you to perform all calls locally. You don't need to be connected to Bedrock or the Internet at all.

You can see it's installed. We have a plugin using Ollama, and we execute queries within mongosh using this TSQL wrapper. Let's start mongosh. We call the JS file that instructs it to use it, and you can see it has been loaded.

Thumbnail 610

Thumbnail 630

Thumbnail 640

Thumbnail 650

There are several namespaces for this demo: customers, orders, and products. Customers and orders each have about 100 documents. There is a products table that combines customers and orders. That's the troublesome dollar lookup we were looking at earlier. So, we run this TSQL wrapper. We execute select star from table where field equals value. Simple, it makes sense, right? auto execute false at the end means don't actually execute it, just translate it. You can see we are in review mode. The command is not executed, and there is the MQL. You copy that, paste it, and guess what—no missing quotes, no missing braces, it just works. If I did this, it would have taken me three tries. It's like plugging in a USB port; I always succeed on the third try.

Thumbnail 660

Thumbnail 670

Thumbnail 680

Let's make it a bit more complex. Instead of select star, let's select multiple fields. Then we'll add a where clause and ask it to translate this. We'll do it all within the MongoDB Shell environment. Again, using Ollama locally, there are lots of those extra braces and quotes here. We copy this. Let's hope the syntax is correct. And look at that, this is a recorded demo, so it works. And we got the values.

Let's go a little further. We did select star, we did field selection, next let's try select count from this table. With the same criteria, the same filter conditions, we won't execute it, we just want it translated.

Thumbnail 700

Thumbnail 710

When we execute this, the find operator doesn't return. An aggregation is returned instead. Ah, it would have taken me about 30 minutes to do this while making typos every time. But now, all I have to do is copy and paste this, and I get the result: 75. It's using dollar match and dollar count. As I said before, you can customize the LLM with this tool. So, instead of using that CodeLlama 7B LLM, let's try the 13B. It's about twice the size, 7.4GB versus 3.8GB. Again, the trade-off here is that you use a lot more space locally, but you are running it locally. Since this is a demo, it's pre-loaded, but it might take about a minute to download on your machine.

Thumbnail 740

Thumbnail 760

Thumbnail 770

You need to update the JavaScript file that the MongoDB Shell is calling. Instead of using that CodeLlama 7B library, you instruct it to switch to CodeLlama 13B. Once you change this, the great thing is, you don't need to recompile anything. It's just a flat file in JavaScript, and when you start the MongoDB Shell, it will reference this new library. So, let's start the MongoDB Shell. We enter that demo namespace again, same place as before. You can see nothing has changed. We're still using Ollama. And we run exactly the same query as we ran before: select count IDs from the table with two where clauses. We had dollar match and dollar count before, it's a little bit different. It's dollar match, dollar add fields, dollar match, dollar count. But when we run this, we get the same result; we still get 75 results back. This is how you can customize the LLM.

Thumbnail 800

Thumbnail 810

Now, let's switch. That was the local version. Let's switch to the Bedrock version. Just like before, we run the shell script to install the dependencies. This time, we are not installing a local LLM, so it moves much faster. It goes to connect to Bedrock. When you run the same process as before, it asks where the compatibility tool file is, so it can provide recommendations based on the supported APIs. Once you input that, everything else installs very quickly. The next step is a bit different. The first thing you have to do is run AWS configure, because we are making calls to Bedrock, and we need credentials for that. The second item, ensuring you have access, is no longer needed. We changed that 2 or 3 weeks ago, so you have access to all models by default; it's outdated information. It needs to be updated. But you can see here that I'm using Claude 3.

Thumbnail 840

Thumbnail 850

Thumbnail 870

The operation is exactly the same. Since we have the TSQL wrapper, we go back to the MongoDB Shell, and when we connect, we can see that we are using the plugin with Bedrock this time. We enter the same namespace. We run the same query: count ID from the table with two where clauses. This time, it's not aggregate, it's countDocuments. It's a little different, right? You can see we are getting slightly different results from each, but the query count is the same. The great thing about this is—ah, I forgot this. With this, we got the result. I had removed auto execute false. When you remove that, it doesn't just provide the translation, it also provides the result.

Thumbnail 890

Thumbnail 900

This is quite a powerful feature for someone like me who can't write MQL statements correctly in the first 12 tries. It can save a lot of time, but this can also get quite complicated. I can put a fairly large TSQL statement in here, and it will translate it for me. For example, this select star with multiple where and AND statements, and order by—look, this is converted into find. It provides regex searches, it has dollar in lists, and it has sort conditions. It handles all of that for me. So instead of Cody crying, getting frustrated, and yelling at his dogs or kids because he doesn't know what he's doing, he gets results very quickly.

Thumbnail 920

This is truly an example of how you can use these Gen AI tools with DocumentDB to improve the developer experience. In other words, it means making things easier and more productive for internal teams.

Thumbnail 940

RAG Architecture: Fine-tuning foundation models with organizational data

Next, I'll talk about RAG architecture. I'll take a pause here as I'm starting to lose my voice. Now, as I mentioned earlier, there are important factors that will be the differentiator for these new Gen AI apps. That important differentiator is your data. Your data is what makes Gen AI applications specific to your business. Everyone here has access to the exact same foundation models, as we saw earlier. You can get Llama models, you can get Bedrock models, right? However, only those here who are building AI apps using their own data will be the ones creating real value. You'll be building something constructible that improves customer and employee experience.

Your data is the differentiator between generic apps like ChatGPT and something that truly understands your business and your customers. But the good news is that you don't have to build your own model. We have customers who have 30 to 40 years of documents. There are billions of documents you can refer to, and you could hire data scientists to create an LLM. But you don't have to. Through a process called Retrieval Augmented Generation, or RAG, you can fine-tune these foundation models using your organizational data. And to get very technical, what this means is taking relevant information, adding it to the context, and generating a response. This is level 400 content. I'll try not to make it any harder than this, everyone. Sorry about that.

Thumbnail 1020

Let me give you an example. Suppose you have an online shoe store and want to support customers with an interactive agent. For example, if a customer says, "Can I return these shoes? I want a refund." This is where the operational data store comes in. The agent performs a factual lookup against the database holding inventory or order information to retrieve relevant details. Then, it performs a vector similarity search against a collection holding policy documents—things like, if you ordered more than 30 days ago, there's a fee, or if it's within 7 days, you get a free upgrade. It is performing a similarity search against the data store as a knowledge repository to make a decision about exchanging the shoes.

Thumbnail 1090

Thumbnail 1100

Thumbnail 1110

Thumbnail 1120

That is a high-level overview. Now let's look at the backend. Let's look at the architecture and go through it step by step. First, the user asks a question there. There is a prompt to process it, and this is where the interaction begins. Next, there is a repository to hold the conversation history. In many cases, that conversation was part of an ongoing one. You have to take your kid to lacrosse practice, you have to go cook dinner, etc. You get distracted, come back, and want to keep that. Next, the application needs to query your contextual data, which is retrieved from the data store. That's what I was talking about earlier—things like inventory or order status. The application uses an LLM to tokenize that original question and generate an embedding of the question. It uses that to perform a similarity search in the vector data store. This uses some algorithm, an approximate nearest neighbor search. We'll look at that later. Then, it integrates all of that into an engineered prompt and sends it back to the LLM to get a response. You need to update that conversation again. And guess what? Finally, you return the response and finish. This is like the data flow we go through.

Thumbnail 1130

Now, this is where DocumentDB comes in. By supporting vector search through vector indexes, both vector search and data source search are executed against the same repository. This is because DocumentDB is an operational data store. Furthermore, conversation history exists there on its own, but you can also place that in DocumentDB. With vector index support in Amazon DocumentDB, you can significantly reduce the complexity of that architecture.

Thumbnail 1170

Thumbnail 1180

Thumbnail 1190

DocumentDB Chatbot Demo: Q&A System leveraging Developer Guides and Blogs

Now, let's move on to the demo. Let's take a look. Here we have a black screen. Very nice. Go ahead. What we're doing here is creating a DocumentDB chatbot. Hopefully, it works. The first thing we need to do is install a few libraries. The two main libraries we use are Gradio—this is just for interaction and demo purposes—and LangChain. LangChain is used to create vectors that we put into Amazon DocumentDB. Once those are established, we need to set some variables for the vectors themselves. We need to specify the number of embeddings needed. We need to set some parameters for the index we are about to create. I'll touch on those values a little later. We won't go too deep into them at this stage. Next, we need to establish the index we're creating in Amazon DocumentDB.

Thumbnail 1210

Thumbnail 1220

We create an HNSW index in Amazon DocumentDB using cosine similarity and pass in some of the values we established earlier. Once that's established, we can create a Mongo client connection to the Amazon DocumentDB database. This uses PyMongo, the MongoDB API. We are just setting the pool size and timeout.

Thumbnail 1240

Thumbnail 1250

Next, we need to chunk the data. We need to put the data along with the vectors into DocumentDB. What we do is split the data into 1000-character chunks with a 200-character overlap. Because we want to retain the meaning. We don't want to lose the meaning. What data are we processing? It's the entire 1500-page Developer Guide for DocumentDB. There's a PDF data modeling guide, which is why we're using LangChain. We split them into 1000-character chunks with a 200-character overlap and create embeddings from them.

Thumbnail 1260

Thumbnail 1270

On top of that, we'll parse through all existing DocumentDB blogs. And we take all that information, split it into 1000-character chunks. Once all of that is ready, we'll feed it into the model. Oh, right, we also take the pricing page, the FAQ page, and the features page, right? Think of this as operational data. Now, these are all public information, but for the purpose of this demo, imagine this is internal information.

Thumbnail 1290

Thumbnail 1300

Thumbnail 1310

We pass this through the Titan Embedding Text V2 model to create embeddings. We keep the original text document, which is the 1000 characters. We keep the vector content, which are all the numbers for those characters, and we also have metadata. This is: Where did it come from? Which page is it from? We'll see that in a moment. Once all of that is ready, we feed it into the model. The model splits it into chunks, processes the PDF, processes the blogs, saves all of that within DocumentDB, and creates an index so that we can start searching.

Thumbnail 1320

Thumbnail 1330

Thumbnail 1340

Now, here is our prompt. Here we are telling the chat agent what to do. Hey, you are a Q&A assistant specializing in DocumentDB. Here are the rules, okay? You need to identify technical details. You need to ensure the response is accurate. You need to be clear and concise. I'll stop here for a second, but this is funny to me. Be friendly and helpful. Someone, please use this, set it to be unfriendly and unhelpful, and send me the results. I want to get your contact info and change that, and send me the results. Because I want to try this myself. What happens if I instruct it that way? Will it actually return wrong answers? That would be amazing.

Thumbnail 1360

Thumbnail 1380

Anyway, that's part of the prompt. We also provide examples. For example, we provide a template for how it should react to the person it's talking to, like: "You can respond like this." Once all of this is ready, we set some thresholds for the accuracy of the response. A score threshold of 0.8 means we want at least 80% accuracy in the returned response. We set the history. We have conversation history, right? I want it to remember the last six things we talked about. And here, this is just Gradio. This is the interface we'll see in a moment.

Thumbnail 1390

Thumbnail 1400

However, before we get into Gradio, let's look at the documents in DocumentDB. We go into the collection where we're saving all of this and look at some projections. There are about 5400 documents from all those PDFs and all the blogs. They were parsed into 5400 different documents. Those documents look like this: There's text content. There's metadata showing where it came from. For example, this came from the Developer Guide PDF. Let's skip a few and look at another one. This is about vector embeddings, and interestingly, it came from a blog about vector embeddings. How timely. Again, this is a pre-recorded demo. This is all set up. It's not a coincidence.

Thumbnail 1430

Thumbnail 1440

Then, let's look at the full document. What I'm showing now are just a few fields, but if you look at the whole thing, you can see what these documents look like when stored in DocumentDB. There's text content. There are these numbers. These mean nothing to us. This is what the computer is using for the vector index. There is also metadata: title, where it came from, page, link, etc.

Thumbnail 1450

Thumbnail 1460

Thumbnail 1470

Now, let's ask a very simple question here. Does DocumentDB offer serverless instances? This is simple, right? You can tell by reading the developer guide, but we have a chatbot. It's fun, exciting, and should be helpful, right? Remember, I want to see what happens when it's not helpful. We can make it a little more complex. For example, we can ask how to audit logins in a cluster. We need to know who connected. We need to know the date and time they connected. Again, this vector search comes back and gives us the correct answer. It says: "Enable it like this." And by the way, once you enable it, these logs are sent to CloudWatch. And these are the fields available in CloudWatch. And by the way, here is a query you can run in CloudWatch. If there's something I'm worse at than MQL, it's CloudWatch filtering. And lo and behold, the CloudWatch filter is right there.

Increasing the complexity, I'll ask about indexes. I need a partial index for the customer collection. I'll filter by address in Texas. Is there anyone here from Texas? Yeehaw, glad to hear that.

Thumbnail 1510

The system parses the query, searches again while augmenting the LLM with our data, and provides the information. It tells me how to achieve the task and instructs me to use a specific partial filter expression. It's particularly helpful that it explains exactly what it's doing, highlights key points, and provides additional information. This response can be customized via the prompt.

Thumbnail 1540

Thumbnail 1550

Next, I'll ask it to join the orders and customer collections to get the top three customers. This is the query we saw earlier. We saw that we could do something similar with the TSQL tool, but here I'm getting this answer in natural language. What I like about this example is that it walks me through each stage of the aggregation, so even my old relational brain can understand what it's doing. It starts with a $lookup, then a $unwind, and then performs a $group operation. Using all of the knowledge base we fed in, it provides this answer specifically for DocumentDB.

Thumbnail 1560

Thumbnail 1570

We can make the questions much more complex. The next question I'm going to ask... the person running this demo is the worst, come on, hurry up. This is interesting. We have an e-commerce platform that currently uses Postgres, with separate tables for products, inventory, orders, shipping, and customer reviews, with multiple variants and categories. There are 100,000 SKUs. If you watch this later on YouTube and want to read it all, please pause the video. I'm not going to explain the whole thing, but there's a very complex question I'm about to ask.

Thumbnail 1590

Thumbnail 1600

I input it, let's see what it tells us. Go ahead. Remember, one of the documents we fed in was the schema design document for DocumentDB. And using that, it tells us that the products collection should look like this. The products review collection should look like this, inventory documents and order collections should look like this. If you hand this to a developer, it streamlines the interaction with DocumentDB or document databases.

Thumbnail 1610

Thumbnail 1620

Let's ask another question about a more complex situation. We have a game platform that tracks player progress and achievements, with 15 normalized tables and 1 million player sessions a day. We're feeding in information about the rate of operations and taking this into account. We need these things: real-time player leaderboards, cross-game achievement tracking, and in-game purchase history. We're giving it all these requirements and asking it to solve them for us. This is why I'm a great programmer; because I have tools like this.

Thumbnail 1640

Thumbnail 1650

It does exactly that. It provides a schema, tells you how to interact with it, where to store the data, the schema to store the data, and how that data interacts with each other. Using all the information we fed in, it provides an answer customized for DocumentDB.

Thumbnail 1660

Thumbnail 1690

One last thing I want to show you, which I think is often overlooked, but is really powerful. We work with many very large enterprises operating worldwide. There are companies based in Nebraska with developers in Spain and London. Some customers have headquarters in Chile with developers in Argentina or Brazil. It's multi-language, and that's the great thing about this. For example, I'm asking what language this is; can anyone tell me, can anyone speak this language? It's Portuguese. It's asking if DocumentDB is supported in the São Paulo region. What this does is translate it, query the operational data source, and answer: "Yes, DocumentDB is supported in the São Paulo region."

Now, if you have developers using multiple languages all over the world, they can interact with tools like this in their native language, and the tool will accommodate them. It will answer someone in Nebraska, someone in Spain, someone in the UK, someone in Chile or Argentina, all the same. They get the same answer. I'll hand over the next access pattern to Doug. So everyone, can you still hear me? Yes, thank you Cody.

Model Context Protocol (MCP): Seamless Integration of Existing Systems and AI Agents

I want to talk about the third access pattern. I'll take a breath again, as my voice is starting to give out. Now, Cody talked about the TSQL plugin for the Mongo Shell and the RAG architecture. Now I want to talk about the Model Context Protocol, or MCP servers. How many of you have never heard of MCP? There are a few of you. Most of you know it, and some of you are less familiar with it. I'll introduce MCP a bit and talk about how it relates to DocumentDB. To provide context, like with RAG or the TSQL plugin, you might know how to access data and be accustomed to querying data via the Mongo API, but suppose there is data you really need to dive deep into. Where do you start? You can start writing a lot of queries, but that takes time. Let's look at an MCP server. I'll go over how this helps.

Thumbnail 1780

I'll talk a little bit about MCP. It's the Model Context Protocol server. For those who don't know, a good way to think about MCP is that it's a way to seamlessly integrate agentic AI components and applications with existing tools and systems. Put more simply, it's a standardized way to access the functionality you already have. It's a client-server architecture, and as you see on the screen, there are a few components.

There are four main elements to keep in mind. First, there's the host. The host is the application that orchestrates and manages multiple MCP clients. The host might be the agentic AI application you've developed. The host might be Visual Studio Code where the client is running. You'll see this in the demo. In short, there are various hosts, and they host MCP clients.

What an MCP client does is maintain a one-to-one relationship with an MCP server—a one-to-one connection. The host understands that it needs to connect to this server to perform some action. Then a client is created, the connection is established, and the host keeps track of all the different clients and which servers they are connected to. The server is a lightweight program that exposes some functionality through a standard interface, a JSON-RPC interface. Usually, it's not much, but it exposes some functionality. On the far right, there's the existing data source. It could be a database or a local data or file source, like a local file. It could be a remote data source like a web service or another API, but the point is that an MCP server can access all kinds of sources, whether local or remote.

Thumbnail 1900

Here, I'd like to look at MCP servers in a little more detail. MCP servers have three different types of capabilities: resources, prompts, and tools. Resources are read-only, persistent data that the server can expose to the client. Think of it as, for example, files you have, static files you want to expose through an MCP server. You can do that. If you define a resource on an MCP server, a client running on a host can ask questions like, "Who is the engineering lead for the mobile app team?" through perhaps a natural language interface. If all your HR information is in a static file that you've exposed as a resource through the MCP server, you'll be able to interact with that static resource. Resources do not perform any kind of action. They don't take action against other resources or external systems. They are simply read-only.

The second capability of an MCP server is prompts. As shown here, these are pre-defined instructions. They are templates that the server provides to the client to help understand what tools are provided, what functionality is offered, what the interface is like, what information you need to pass to execute this action, and what information it will return. And tools—these are what actually do the work. In other words, they perform some action. They can read or write, but this is also defined by a schema, so what this tool does and the interface to the tool is clearly defined. A very important point at the bottom is that, by default, execution requires explicit user approval. Because you probably don't want your agentic AI tools running around freely, doing everything, making changes, deleting tables, or modifying data. Now, as I'll show in the demo, you can set it to auto-approve, but by default, you need to provide explicit approval on the MCP server.

Thumbnail 2040

So, let's focus on a specific MCP server. This is what you'll actually see in the demo. This might be a simplified view of the Amazon DocumentDB MCP server. I'll show you the QR code and link at the end. But as you see here, there's a client running on the host. That client connects to the MCP server—the Amazon DocumentDB MCP server. This server has all the different tools it exposes and the logic required to implement those tools. For example, there's a tool that can connect to an Amazon DocumentDB cluster. There's a tool that can list all databases in the cluster, and a tool that can list all collections in the database. There's also a tool that can query data in the database. Again, the idea is to make it easy to start exploring, perhaps, new datasets or databases—things about which you might not know much about what's inside or how to use it.

Thumbnail 2100

Amazon DocumentDB MCP Server Demo: Data Analysis and Code Generation with Natural Language

So, let's take a look at this demo. In this demo, I'm using Cline in Visual Studio Code. This is my host, and it's connected to the AWS DocumentDB MCP server.

If you look at the bottom, you can see what is configured. I am using the Anthropic Claude 3.7 Sonnet model. Oh, I forgot to hit the play button. So, let's take a look at the MCP server itself.

Thumbnail 2130

Thumbnail 2140

We have the Amazon DocumentDB MCP server. In this case, 16 different tools are exposed. I don't intend to explain all of them, but for example, you can see one here: a connect tool for connecting to an Amazon DocumentDB cluster. This is already set to auto-approve, as I've been using this and connecting to the cluster is fine; it's not a destructive operation. However, again, by default, these will be unchecked. And you can see the description of what that tool does.

Thumbnail 2160

Thumbnail 2170

This is another tool, the disconnect tool. This disconnects from the database. Then there is the find tool. I have not auto-approved this one. Perhaps you might be nervous about letting it execute a query without checking it yourself first. In other words, the point is that you have the option to approve through the host, auto-approve, or not approve at all.

Thumbnail 2180

Thumbnail 2190

Thumbnail 2210

Now, let's assume your role is a developer at an e-commerce company, and you are tasked with analyzing sales trends from the past holiday season. The first step is, well, what's inside this database, right? So, through Cline, you can ask what collections are in this database. You can see it going out and checking through the MCP server. Okay, addresses, customers, orders, products, and reviews. It looks like this contains the information I need to find what I'm looking for.

Thumbnail 2230

Thumbnail 2240

Thumbnail 2250

So, let's just ask. Okay, what are the most popular items during the holiday season over the past few years? Now, it starts processing and begins the work. Since it's running a new tool it hasn't used before, the server exposes the analyze schema tool to check the documents and their contents. I'll auto-approve it. It's fine to have it run this every time. As you can see, the process is moving forward. It's checking the orders, products, and customers collections to see what's inside. As the process moves along, we get some information.

Thumbnail 2270

Thumbnail 2280

Thumbnail 2290

Now, another new tool has appeared here. The aggregate tool. The MCP server is smart enough to understand that to find the top products, it needs to perform an aggregation this time. So, I give it approval and let it run. And you can see what it's thinking here. Group orders by state, calculate total revenue per state. Sort them, and then get the top products again, and get the details for those products. Approve, and let it continue processing. You can see it's moving along quite fast. You can see some of the aggregations and the information being returned.

Thumbnail 2300

Thumbnail 2310

Thumbnail 2320

Now, we've got some of the top products. It's trying to run find to get information about these products, but again, approval is required because by default it won't execute without approval. So, I'll set it to auto-approve, and it will continue on its own next time. So, I'll let this find execute. Now, a lot of processing is happening. And here is the report.

Thumbnail 2340

Basically, it took all the information retrieved from DocumentDB, ran it through the LLM, and created this report. You can see the top 5 states by revenue, and the most popular products by quantity in each of these states. Immediate tub is popular in Mississippi, and puny sandpaper is popular in Maine, for instance. All the information you need is right here.

Thumbnail 2350

Thumbnail 2360

Thumbnail 2370

Thumbnail 2390

Now, while doing this, I realized that we need to do this every year. Someone like me might forget how I did it. So, I can ask Cline to give me the Python code to do this. You can see it creating the Python code needed to generate this report. It's generating a fair amount of code, but if you look, it has all the code to handle the different steps. Code to find the top states by revenue, and code to find the popular products in each state, right? You can see the aggregations and the queries for the products.

Thumbnail 2400

It's like, give me the product details. In other words, I can see all the queries and aggregations created to produce this report. They are now available within this code. Of course, I'll review the code before running it, but I've got a really good, solid starting point.

Thumbnail 2410

Thumbnail 2420

Thumbnail 2430

Thumbnail 2440

Thumbnail 2450

Thumbnail 2460

Now, while doing this, my boss came by and said, "I know you're working on this, but can you tell me what's going to be popular this holiday season?" So, again, through natural language, I can ask based on past products, past performance, and past sales what's expected to be popular this holiday season. As you can see, it's trying various things. Sometimes you might see things that don't work out. If an error occurs, try something else. But the point is, I've reached the point of performing the analysis, and now it's creating a report on what's expected to be popular this holiday season based on the sales of the past few years. As you can see, through the MCP server and agentic AI solutions, it's relatively easy to explore data, generate code, and get a good starting point for your application.

Thumbnail 2470

Thumbnail 2480

Thumbnail 2500

Best Practices for Vector Indexes: Selection Criteria for IVFFlat and HNSW

So, let's talk about best practices for the remaining time. This is probably the first time, well, the first time you've seen this in these presentations. If you are familiar with vector embeddings in Amazon DocumentDB, you may already know that we support two different types of vector indexes: IVFFlat and HNSW. You have two to choose from, but which one should you choose? Each has trade-offs, but broadly speaking, IVFFlat indexes are small and require less memory. However, you must populate the data beforehand. In other words, you have to load the dataset before creating the index. And for workloads where that information is updated or more information is added, you need to rebuild those indexes.

Thumbnail 2550

On the other hand, HNSW has slower index build times and uses more memory, but it is more accurate, has lower latency, and you don't need to rebuild the index even if the data changes. So, which one should you choose? It depends on your requirements, but usually, starting with HNSW is a good idea. To summarize, if you need the fastest index creation, IVFFlat is a good option. If you need something that is easy to manage, performs well, and has high recall, go with HNSW.

Thumbnail 2560

Let me provide some information about index construction time, i.e., index creation time. There's a quite significant difference. So, if you are building or creating indexes frequently, this might be a factor to consider. This specific test was run on an 8XL instance. What is shown here is the number of embeddings. Remember when Cody showed the human-readable text, and then the arrays and numbers, i.e., the embeddings? There are 6 embeddings here. The green bars are IVFFlat. The other bars are HNSW. As you can see, as I said in the previous slide, IVFFlat is significantly faster in terms of build time compared to HNSW in seconds. Since this scale is in seconds, it visually represents the difference in build time between the two index types well.

Thumbnail 2620

Now, regarding HNSW, since IVFFlat can only build indexes on existing data, that is the only choice, but its index build time is quite fast. HNSW gives you options. You can create an index first, and it will be built as you load the data. Or you can create it later. As you can see here, the low purple line is if you create the index first. These indexes are built much faster because they update the index as data is added. If you build the index later, it takes time. Honestly, this is the same recommendation as any other index you create in DocumentDB. If you can create an index before loading the data, it's much faster to update than trying to build it later.

Thumbnail 2670

Some decision points for IVFFlat vs. HNSW. If you need an exact nearest neighbor search, i.e., 100% recall, meaning you need to find an exact match, do not use a vector index. Use a standard index. Because, basically, you are just performing a point lookup and an exact match. If you need the fastest index creation, it's IVFFlat. If you need the easiest management and frequent updates, it's HNSW. If you need higher performance and recall, it's HNSW.

Thumbnail 2720

Yes, this is a slide you want to take a photo of. Or as Cody said, pause the video once it's published on YouTube. Vector embeddings consume space in the document, right? That is to say, this is great. You can add these vector embeddings, but space is limited. There is a limit to the DocumentDB document size. It is 16 megabytes. If you have a large number of embeddings and a large amount of metadata, hopefully, you haven't reached 16 megabytes, but the point is that there is a limit. Therefore, you need to keep in mind the impact these vector embeddings have on the document size.

It's a very simple formula. What you see in the top right is key length plus 1 plus dimension count times 13. In other words, the key length, in this case, embedding. Key length plus 1 plus dimension count times 13. The breakdown of this 13 is 4 bytes for an int32 value, 8 bytes for element length—meaning each item in the array is stored as 8 bytes—and a 1-byte terminator. There are 14 bytes for the initial value, then 8 bytes per element, and a 1-byte terminator. Combining all of these gives you the size. Or, if you look at the chart, you can see that 100 dimensions is about 1.3 kilobytes, and 1000 dimensions is, as you might imagine, about 10 times that. Again, this is something to remember. Having more embeddings in your vector is great for getting better matches, but it consumes more space.

Thumbnail 2820

There's a lot to think about, isn't there? Which vector index type to use, those various settings, the number of embeddings, the number of connections, etc. But a better way to think about this is to take a step back and think. What are your requirements? How many queries per second do you need to support? What's the query latency? Does this need to execute in a second, less than a second, or 30 seconds? What about recall? Does it always have to be an exact match? In that case, a vector index is probably not the appropriate method. Do you need 90% recall, or is 50% sufficient? Again, depending on these answers, which vector index to use, IVFFlat or HNSW, will affect ingestion time. In the case of IVFFlat, index construction on existing data is very fast. So, if low ingestion time is a priority, you might want to select IVFFlat. And the same goes for index build time. These are the points to consider. It's better to reverse the thinking, consider what your requirements are, and decide the index type and settings from there.

Thumbnail 2900

So, a few more slides. Some tests regarding query performance. These are about different index types. This is an IVFFlat index. What is shown here, the numbers 20, 40, 80, 400, 600 at the bottom, are the number of probes, i.e., the number of lists to search. A good analogy for IVFFlat is that there are people living in apartments, and the number of apartment buildings is finite. Let's say, for example, there are 20 apartment buildings. As the number of people increases, more people will live in each apartment building. Those apartment buildings are the lists. In other words, 20 groups of embeddings, 40 groups of embeddings, 80, etc. That is what's shown at the bottom.

Thumbnail 2960

Looking at queries per second, certainly, the fewer the groups, the fewer the probes, the faster the queries because there is less to search, but the recall is lower. It's about 85%. Increasing the number of probes or groups decreases queries per second, but recall increases. However, as you can see, in this case, once you reach about 400, it becomes a point of diminishing returns. Yes, you can get slightly better recall by increasing to 600, but the number of queries per second decreases. So, remember that you don't always need to go to the maximum value. And it depends on your dataset and your embeddings. But understand that there's a point where you probably don't need to go any further. The same can be said for HNSW.

Thumbnail 3010

Different terms are used for HNSW. They call this EF search. This is the list size when running a query, how many items you are looking at. Information about the index is shown at the top, but it's a similar idea. I won't go into details too much, but again, the smaller the list being considered, the higher the queries per second. You can see that queries per second are much higher with HNSW. Now with HNSW, it's thousands of queries per second. It's higher performance.

Thumbnail 3070

However, regarding recall, it might be sufficient for your use case, or it might not be. Try increasing the EF search. But again, you reach a point close to 1. No matter how much you increase the EF search, it doesn't improve much, but queries per second will drop. In summary, test and find an appropriate value close enough to what you need, and go with that. Don't always go to the maximum value because you don't need to.

So, the best way to summarize all of this. We've seen a lot of information, watched 3 demos, and talked about various index types and all these things. The best way to summarize it, as in the first point, is to commit to experimentation early. If you haven't used it yet, start using these things. If you haven't started using it yet, start using it, see what you can do, and get used to it. I didn't know anything about MCP servers, but when I started using them, I thought, wow, this is amazing. I love it. So please try it. The more you use it, the more ways you'll find to solve your use cases or problems. So try it and start using it.

Second point: you might find new ways of working, new methods of development, or new ways to solve problems with these technologies. But at the end of the day, one of the main points here is why vector support in DocumentDB is so important. As Cody said, your data is your differentiator. We are now enabling you to store these vector embeddings alongside your DocumentDB data. Everything you need to do all the things we showed you here today is right there.

Thumbnail 3160

Thumbnail 3180

If you'd like, take a picture immediately. There are QR codes that can take you to the Amazon DocumentDB MCP server and the Mongo Shell TSQL plugin. And I realized my mistake here. I forgot to emphasize something very important early on. What I should have emphasized early on is that for HNSW indexes, you should always create the index before inserting data into a new namespace. Very important. I don't know if you've been to sessions like this, but if you go to a booth and tell someone to always create the index before inserting data into a namespace, you might get a hoodie.

So, everyone, thank you very much for your time and attention. Please send us your feedback. We would appreciate your honest opinions. We want honest feedback. We want to make these even better. We believe we are telling you what you want to hear, but perhaps that's not the case. Perhaps we talked about content that wasn't very useful. Please let us know. If you do, we can adjust and continue to make these better. We always read feedback and take it seriously, so please, please help us out. Again, thank you very much. On behalf of Cody, enjoy the rest of your stay at re:Invent. Have a great night.

Discussion