Contact Us 1-800-596-4880

Lab 2: Retrieval Augmented Generation

Overview

In this lab we will go through creating a more complex scenario that allows us to ask AI questions about a document we have given it access to - this is done via Retrieval Augmented Generation (RAG). There are three steps to this:

Step 1: Create a knowledge store using Embedding

  1. Add a document to the store

  2. Create a query to ask the LLM model questions (Perform RAG)

    Create a knowledge store using Embeddings

  3. In your current project add a new flow. Type ‘flow’ in the search box of the Mule Palette and drag the ‘ Flow ’ component to the canvas.

    img 0

  4. Rename this flow to ‘ 1-EmbedNewStore’

    img 1

  5. Add an HTTP Listener to the flow (just like for the previous flow). Reuse the same connection Config (HTTP_Listener_config), and set path to /store

    img 2

  6. Add the MuleSoft AI Chain’s “Embedding new store” operation to the flow.

    • Store name: mule.home ++ "/apps/" ++ app.name ++ "/knowledge-centre.store" (Remember to check the ‘fx’ button.)

      img 3

Step 2: Create additional flows

In this scenario we are using a hard-coded store name.

  1. Repeat step 1 to create 2 additional flows:

    Flow number 2:

    • Name: 2-GetInfoFromStore.

    • MAC Connector’s Component to be used: Embedding get info from store.

    • Connection config: HTTP_Listener_config.

    • Path: /query

      Listener and MAC Connector / Component properties:

    • Module configuration: MuleSoft_AI_Chain_Config (Reuse the same config created earlier)

    • Data: payload.data ++ "Don’t make assumptions"

    • Store Name: mule.home ++ "/apps/" ++ app.name ++ "/knowledge-centre.store"

      img 5

      Flow number 3:

    • Name: 3-AddDocsToStore

    • MAC Connector’s Component to be used: Embedding add document to store

    • Connection config: HTTP_Listener_config

    • Path: /addDocs

      Listener and MAC Connector / Component properties:

    • Store name: mule.home ++ "/apps/" ++ app.name ++ "/knowledge-centre.store"

    • Context path: payload.contextFile

    • Max segment size in chars: 100000

    • Max overlap size in chars: 10000

    • File type: any

      img 7

  2. Save all the changes (Select File - Save Al l)

  3. Run the project and check that it is deployed without any errors:

    img 8

Step 3: Populate Vector DB

We are now ready to populate our Vector DB store but first download a fictitious product information document for a product called Mulesoft TXY, as this is the document we will use to test RAG

  1. Download MulesoftTXY.pdf from here

    • Have a quick look at this document and see what details it contains

  2. First, run the following to create the embedding store (No message Body is required for this).

    you can use curl or Postman
    curl --location "http://localhost:8081/store" --data ''
  3. Let’s do a query and see what it knows.

    curl --location --request GET "http://localhost:8081/query" --header "Content-Type: application/json" --data "{\"data\":\"What is the mulesoft TXY?\"}"

    The response should looks like this:

    {"sources":[],"response":"Mulesoft TXY is a proprietary technology or product developed by Mulesoft, a software company specializing in integration and API management. Without further context, it is not possible to provide a specific answer about what Mulesoft TXY specifically refers to." }
    Notice that it does not respond with any relevant info.
  4. Now we’ll populate our embedding store with the PDF file we downloaded earlier. Note - Update the location of the MulesoftTXY.pdf accordingly

    curl --location --request GET "http://localhost:8081/addDocs" --header "Content-Type: application/json" --data "{\"contextFile\":\"C:\\Users\\workshop\\Downloads\\MulesoftTXY.pdf\"}"

    Response should look like this: {"status":"updated"}

  5. Now that the embedding store is populated, we can ask our LLM some more intelligent questions.

    curl --location --request GET "http://localhost:8081/query" --header "Content-Type: application/json" --data "{\"data\":\"What are the key features of mulesoft TXY headphones?\"}"

    The response should be like this:

    {"sources":[],"response":"1. High-quality sound: Mulesoft TXY headphones are designed to deliver clear, crisp sound with deep bass and balanced highs.\n\n2. Comfortable fit: These headphones are ergonomically designed to provide a comfortable and secure fit for extended listening sessions.\n\n3. Bluetooth connectivity: The Mulesoft TXY headphones feature Bluetooth connectivity, allowing you to easily pair them with your device and enjoy wireless music playback.\n\n4. Built-in microphone: These headphones come with a built-in microphone, making it easy to take calls hands-free while on the go.\n\n5. Long battery life: The Mulesoft TXY headphones have a long battery life, allowing you to enjoy hours of music playback on a single charge.\n\n6. Lightweight and portable: These headphones are lightweight and foldable, making them easy to carry with you wherever you go.\n\n7. Noise-cancelling technology: The Mulesoft TXY headphones feature noise-cancelling technology to block out external sounds and provide an immersive listening experience."}

Notice that the response contains relevant info retrieved from the PDF file we uploaded to the store.

Congratulations, you have finished Lab 2!!

The next (optional) lab will show you how to use One Flow RAG.

Please proceed to Lab 3.

If not…​

Congratulations! You have completed this Module .

Please proceed to next Module