Did you test an AI assistant with a question about your company and securely answered something false? It is not a defect of that product. A language model knows what he saw in training: he never read your contracts, your manuals, your list.
The RAG solves this problem. In this guide we see what it is, how it works and why to build it on AWS with Amazon Bedrock is convenient to many companies, but not to all.
What is RAG, in simple words
RAG stands for Retrieval-Augmented Generation: relevant information is retrieved before the model generates an answer.
Think of an open book exam. The student should not remember everything by heart: when the question comes, he opens the book to the right page and answers with the front page.
- Search: When a question comes, the system finds in your documents the most relevant steps.
- Add to Wishlist: Enter those steps in the request sent to the model.
- Generation: the model writes the answer based on those passages and indicates where it took them from.
The model remains the same. Changes what you have under your eyes while responding.
What problem does it solve for a company
A model used alone has three limits that in the company weigh:
- He doesn't know your data. Internal procedures, product cards, ticket history: for him do not exist.
- It's still on a date. What changed after training doesn't know.
- Don't mention the sources. A right answer and an invention have the same tone.
With the RAG update a document and the answer changes immediately, without retraining anything, and each response brings with it the source, so who the law can verify it.
The most common uses:
- customer support that answers from the manuals and the real sales conditions;
- internal research on procedures, regulations and technical documentation;
- support to the commercial network on past lists, cards and offers;
- onboarding of new assumptions on the knowledge that today lies in the head of a few.
RAG, fine-tuning or longer prompt?
It's the three roads to give a pattern of information you don't have.
- Paste documents in the prompt It works with few pages. With hundreds of files it becomes slow and expensive, because you pay every time all the text you send, and the pattern struggles to find the passage that counts.
- The end-tuning It is useful to teach him a tone, format or repetitive task. It is not suitable for changing content: every update requires a new training, and the model continues not to tell you where an answer comes from.
- The RAG leaves the model as it is and passes it, to every question, only the steps that are needed. The contents are updated by changing the documents and each answer has a source.
For most of the projects starting from a document base, RAG is the first sensible step.The three roads are not excluded: a mature system can combine them.
How does RAG system work
A RAG system has two distinct moments.
The preparation of documents. The files are read, divided into text blocks and transformed into*embedding*: sequences of numbers that represent the meaning of each block. Embeddings end up in a vector database, which allows you to search for meaning and not just for an exact word.
The answer to the question. Even the question becomes an embedding. The system recovers the nearest blocks by meaning, passes them to the model along with the question and the model writes the answer.
It seems linear. In practice every step is a piece of software to build and maintain: connectors to sources, division into blocks, vector database, synchronization when a file changes, permissions, monitoring.
Why do it on AWS with Amazon Bedrock
Amazon Bedrock is the AWS service that gives access to different suppliers models through a single API. In its interior, Bedrock Knowledge Bases manages the entire RAG flow: from document acquisition to recovery, to response with sources.
Less infrastructure to build
Indicate where the documents are and Bedrock reads them, divides them into blocks, calculates embeddings and saves them in the vector database.
| Activities | RAG built from zero | With Bedrock Knowledge Bases |
|---|---|---|
| Reading and dividing documents | Your code | Managed, with configurable strategies |
| Calculation of embedding | Pipeline your own | Managed |
| Vector database | To install and maintain | Managed or your choice |
| Content update | Job your own | Synchronization of sources |
| Sources in the answer | To implement | Including |
The time you don't spend on the infrastructure spends it where it counts: the quality of documents and answers.
Your data remains yours
The AWS documentation on data protection declares that Bedrock does not use prompts and answers to train models, does not distribute them to third parties and that model providers do not have access to customer data.
To this you add the AWS tools that your company may already use: data encryption, IAM permissions to decide who can question what, private connections not to pass traffic from the internet.
A point to be checked during the project: with the inference between regions the requests can be processed in a region other than that of origin, within the chosen geographical area. If you have constraints on the residence of the data, the region and the inference profile must be decided before, not after.
Choose the model, and you can change it
The models improve every few months. With Bedrock the model is a configuration parameter: you can use an economical one for simple questions and one more capable for complex ones, and replace them when a better one comes out, without rewriting the application.
Connect to what you already have
Knowledge Bases read from Amazon S3 and from tools such as Confluence, SharePoint and Salesforce, as well as from websites. For table data they can directly question Amazon Redshift, translating the question into a query.
The vector database is also a choice and not a constraint: Amazon OpenSearch, Aurora PostgreSQL, Amazon S3 Vectors, or external solutions such as Pinecone and MongoDB Atlas. If you already use PostgreSQL on AWS, you do not have to adopt a new product.
Tools to improve and control responses
A RAG that works in demo and disappoints in production is the most common case. Bedrock offers levers to avoid it: filters on metadata to search only in the right documents, models of*reranking* that reorder the results by relevance, hybrid research that combines meaning and keywords.
With Bedrock Guardrails you can also block unwanted arguments, mask personal data and verify that the answer is based on the recovered documents.
Costs related to use
The models pay for consumption, according to the processed text. They do not need GPUs or servers that are always on. However, beware of the vector database: some options have a fixed cost even at zero traffic. For a small project, the choice of storage affects the expense more than the model.
When Bedrock is not the right choice
A managed platform is not always the answer. It is advisable to evaluate alternatives if:
- your data may not come out of your office, by contract or by law;
- your company works entirely on another cloud and does not want to add a second;
- you need fine control over every step of the search, as well as what the managed service allows.
And in any case it is worth a rule that no platform changes: a RAG is as good as the documents it reads.
From where to
Three steps, before writing a line of code:
- Choose a case of use only, with a benefit you can measure, for example: repetitive questions that come to assistance.
- Collect fifty real questions with the correct answer. They will be your meter: without, you will never know if the system improves or worsens.
- Identify sources which contain those answers and check in which state they are.
With these three elements a prototype on Bedrock tells you soon if the project holds, before investing in production.
Do you want to know if the RAG does it for you?
In shardana.ai, from Cabras (Oristano), we design and manufacture RAG systems on AWS for companies that want to put their internal knowledge to work.
In a first consultation we look at your case of use together, the documents you have and the data constraints. You get out with a clear answer: if the RAG is the right tool, what architecture makes sense and what commitment it requires.
Frequently asked questions
- Does the RAG eliminate the hallucinations of the model?
- No, it reduces them. The model responds by starting from your documents and cites the sources, so errors become verifiable. If the right document is missing or wrong, the answer remains wrong: that is why you need cured data and tests on real questions.
- With Amazon Bedrock my data is used to train models?
- No. According to AWS documentation, Bedrock does not use prompts and answers to train models and does not share them with model providers.
- Do you already need an AWS infrastructure to RAG with Bedrock?
- No, just an AWS account. If your documents and systems are already on AWS, however, the advantage is greater: same permissions, same network, same invoice.
- Better the RAG or the end-tuning?
- To respond to a model on company content, RAG almost always: update documents without retraining anything and each response has a source.
- How long does it take for a first prototype?
- It depends on the quality of documents more than technology. With a service managed as Bedrock Knowledge Bases the technical part of a prototype is short; the real job is to choose sources, clean them and measure the answers.