Example of Retrieval Augmented Generation (RAG)

Let us now see an example displaying the process of RAG. This is an example flow displaying what happens when you ask a query or type a prompt.

Here is the flow:

  1. Input Query: Let’s say our prompt is “Tell me about the history of the Taj Mahal.”
  2. Document Retrieval:
    Initial Search: The system searches through a large dataset (like a collection of articles) to find relevant
    documents about the Taj Mahal.
    Chunking: These documents are divided into smaller chunks, each containing a few paragraphs or sentences.
  3. Vector Embeddings:
    Encoding: The query “Tell me about the history of the Taj Mahal” is encoded into a vector. Each chunk of the retrieved documents is also encoded into vector embeddings.
  4. Similarity Calculation:
    Similarity: The system calculates the cosine similarity between the query vector and each chunk’s vector.
    Selection: The top-k most relevant chunks are selected based on their similarity scores.
  5. Relevance Ranking:
    The retrieved and encoded document chunks are ranked according to their relevance to the query using
    ranking algorithms.
  6. Context Encoding: Encode the query and selected documents together.
  7. Attention Mechanism: Focus on the most relevant parts of the context.
  8. Response Generation: Using an LLM like GPT, generate a detailed response
  9. Output: “The Taj Mahal is a breathtaking white-marble mausoleum located in Agra, India, along the
    southern bank of the Yamuna River”

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

Process of Retrieval Augmented Generation (RAG)
Vector embeddings in RAG and its process
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading