What is RAG?
Retrieval-Augmented Generation, or RAG for short, is an approach that combines information retrieval with the text generation capabilities of large language models. Google Cloud describes RAG as a structure that brings together information access tools, such as search systems and databases, with generative language models.
In the flow AWS describes, the user query first goes to an information retrieval component. This component fetches information related to the query. Then both the query and the retrieved information are passed to the language model. While building its answer, the model uses the retrieved information along with what it learned during training.
According to AWS, RAG extends the scope of a language model to an organization's internal knowledge or content from a specific domain without retraining the model. Google Cloud likewise notes that this approach can be added to language model applications and agents that need to access private or domain-specific data.
How is content prepared for search?
In the flow AWS describes, information outside the model's original training data can come from APIs, databases, or content repositories. This information can take the form of files, database records, or long-form text. To make it searchable, the content is processed and converted into numerical representations.
Splitting a large text into smaller sections is one of the preparation steps Microsoft Learn describes. This process is called chunking. Chunking breaks long content into pieces that can be matched individually. This way, a search can find the sections relevant to the question instead of the whole text.
Microsoft Learn explains that the vectorization step performed while building an index produces the embeddings used in vector queries. In the method AWS describes, embedding models convert content into numerical representations. These representations are stored in a vector database and later matched against the user query.
Content does not have to consist of plain text alone. According to Google Cloud, multimodal embeddings can also be used for images, audio, and video. These representations can be retrieved together with text embeddings or embeddings in different languages. Microsoft Learn also lists OCR, image analysis, and describing an image in text among the content preparation capabilities in Foundry IQ.
How is information found when a question arrives?
In the vector search flow AWS describes, the user query is converted into a vector representation. This representation is matched against the information in the vector database. The relationship is determined by mathematical calculations on the vector representations. The relevant content chunks are then used in answer generation.
AWS gives the example of a chatbot that answers staff questions. When an employee asks about their annual leave entitlement, the system can retrieve the annual leave policy together with the employee's past leave record. In the example, this content is selected because it relates to the employee's query. The language model receives the information along with the question.
Google Cloud explains that vector databases store content as embeddings and that retrieval can be performed based on semantic similarity. The vector similarity search Microsoft Learn describes can likewise find matches between concepts rather than searching for the same words.
Different search types can be used in the same flow. According to Microsoft Learn, hybrid search combines keyword search and vector search. In a hybrid query, the text and its vector counterpart produce parallel queries for keyword and similarity searches. The relevant matches from both search types are merged into a single result set.
Google Cloud notes that in some search engines, results are scored by a re-ranker. According to Microsoft Learn, semantic ranking also rescores results based on their meaning rather than only on keywords. Google Cloud further explains that some search engines transform the query and correct spelling errors before searching.
How does retrieved information enter the answer?
According to AWS, after retrieval, the relevant information found is added as context to the user's input. This augmented input, that is, the prompt, is sent to the language model. The model generates its answer using both the user's question and the retrieved content.
Google Cloud describes this stage as grounded generation: the retrieved and preprocessed information is added to the context the model uses. The preprocessing steps Google Cloud lists include tokenization, stemming, and stop word removal. These steps may occur in the flow before the retrieved information is passed to the model.