Tutorials & How-To

Building a RAG Q&A System with Dataworkz: A Step-by-Step Guide

A step-by-step build of a RAG question-answering system, from data prep to optimization.

Key takeaways

  • The guide walks through building a RAG application for PubMed data using Dataworkz, powered by MongoDB Atlas, starting with uploading files to a GCS bucket and configuring the MongoDB and GCS connectors in Dataworkz.
  • Step 1 is pre-processing: create a pre-processing job and configure sources such as PDF files and website URLs (with sub-crawling and JavaScript options), then submit to a target location and verify the saved dataset.
  • Step 2 builds the Q&A system: configure the source from pre-processed datasets, choose an embedding model (privately hosted, HuggingFace-hosted, or bring-your-own), configure MongoDB vector storage with cosine similarity plus threshold/delimiter/chunk size/overlap settings, and select language models to test (e.g., Llama 2, ChatGPT, Mistral) with a custom prompt.
  • On submit, the Dataworkz RAG builder creates the index and chunks in MongoDB, and the cloud infrastructure for embeddings and chunks scales on-demand.
  • Steps 3 and 4 cover using and optimizing the system: answers return with the source data location, and users can refine results by changing prompts, formatting metadata (e.g., versioning MongoDB documents), and adding data from other sources like Google Sheets and Docs.
On this pagesections

    This document will guide you through the process of building a RAG application for PubMed data using Dataworkz and powered by MongoDB Atlas.   

    Uploading Files to GCS for Building a RAG Q&A System:

    • Connect to your GCS console:
      • Choose the bucket you want to upload the object to. Create a new folder to store the files, click upload files, and in the selection box, add the files you would like to upload.
      • Choose open and the files will be added to the folder

    Configuring the MongoDB Connector for RAG Data Processing:

    To connect to your MongoDB database using Dataworkz:

    • Go to the Dataworkz dashboard and click on “Configuration” in the top-right corner.
    • Click on “Databases” and then click on “MongoDB.”
    • Click the “+” icon to add a new configuration.
    • Enter a name for the storage configuration and the MongoDB hostname or IP address.
    • Enter the MongoDB username and password.
    • Click “Test Connection” to test the connection.
    • If successful, click “Save” to save the configuration.

     

    Setting Up GCS Connection for RAG Q&A System in Dataworkz:

    Now, you need to configure the GCS connector to connect to your instance. Here’s how:

    • Go to the Dataworkz dashboard and click on “Configuration” in the top-right corner.
    • Click on “Cloud data platforms” and select GCS
    • Hit the “+” icon to open the configuration window shown below
    • Enter the storage name, Project ID, Client ID, Client Email, and Account Private Key ID, Account Private Key
    • Test the connection to make sure the configuration is successful, then save

    Step 1: Pre-processing Data

    • Access Pre-processing Settings in Dataworkz:
      • Click on the gear icon in the top right, navigate to the AI Applications section, and select Pre-processing.
    • Create a Pre-processing Job:

    Press the ‘+’ button and name your pre-processing job.

    Configuring Sources

    • PDF Files:
      • For PDFS, select the file type – PDF.
      • Choose the storage you have uploaded files to
      • Find the pdf file that you have uploaded to your cloud storage, make sure to select all files.
    • Website URL(HTML):
      • For URL links, select the file type – html.
      • Add URLs of interest, check the sub-crawling and javascript enabled boxes.

    Submit Pre-processing:

    • Next, choose the pre-processing target location and hit submit to perform pre-processing. 
    • Verify the saved data in the dataset tab.

    Step 2: Building the Q&A System

    • Access the Dataworkz RAG builder:
      • Click on the gear icon, navigate to AI Applications, and select Q&A.

    • Create a Q&A System:
      • Click on the ‘+’ button and give the Q&A system a name.

    • Configure Source:
      • First, configure the source using the datasets created during pre-processing.
      • Add question(text) and external link(PDF or URL) columns based on the source files.
    • Choose Embedding Model:
      • Select the embedding model for your Q&A system. You can choose from one of the following options: 
        • Choose a model that is hosted privately – this includes all the popular ones from the MTEB leaderboard.
        • Choose a model hosted in HuggingFace
        • Bring your own
    • Configure Vector Storage (Using MongoDB):
      • Name your vector storage and choose cosine similarity metric.
      • Set the threshold, delimiter, chunk size, and overlap.

      • Save the configuration.
    • Choose Language Models:
      • Select language models you want to test (e.g., Llama 2, ChatGPT, Mistral, etc…).
      • Provide a custom prompt for the system.

    • Save and Submit:
      • Save and submit to create the Q&A system. The Dataworkz RAG builder will create the relevant index and chunks in MongoDB. The cloud infrastructure to create embeddings and chunks is scaled on-demand.  

    Step 3: Using the Q&A System

    • Testing the System:
      • Ask a question in the chat box, and the system will return an answer along with the location of the data.
    • Reviewing Results:
      • The user can check the source links to see where the information generated has originated from.

    Step 4: Testing and Optimization

    • Test Results:
      • Test the system by changing prompts and formatting metadata.
    • Formatting Metadata:
      • Experiment with different ways to make RAG sources more relevant, like versioning for the mongodb documents.
    • Adding Data from Other Sources:
      • Enhance the system by adding data from Google Sheets, Docs, or other internal sources.

    By following these steps, you can create a powerful RAG Q&A system that not only answers queries effectively but also ensures accuracy and relevance across various data sources. Dataworkz empowers you to provide a top-notch self-service experience for any user.

    If this is something you would like to see live and demoed on your data, you can send an email to info@dataworkz.io or contact us on dataworkz.com/v1m/contact-us/

    For future blogs, keep an eye out for our next blog on Advance RAG topics, RAG monitoring, and AI guardrails.  

    Frequently asked questions

    What data and technologies does this guide use to build the RAG Q&A system?

    It builds a RAG application for PubMed data using Dataworkz, powered by MongoDB Atlas, with files stored in a Google Cloud Storage (GCS) bucket and connected through Dataworkz's MongoDB and GCS connectors.

    What are the main steps to build the Q&A system?

    The guide follows four steps: pre-processing the data, building the Q&A system (configuring source, embedding model, vector storage, and language models), using the system to ask questions, and testing and optimizing it.

    What embedding model options are available?

    You can choose a privately hosted model (including popular ones from the MTEB leaderboard), a model hosted in HuggingFace, or bring your own.

    How does the system show where an answer came from?

    When you ask a question, the system returns an answer along with the location of the source data, and users can check the source links to see where the generated information originated.

    How can the Q&A system be optimized or extended?

    You can test different prompts and metadata formatting (such as versioning MongoDB documents to make sources more relevant) and enhance it by adding data from other sources like Google Sheets or Docs.

    See what your engineers can ship in production

    Dataworkz is the agentic AI platform enterprises trust to put AI agents into production. Teams build production-ready agents in days, every decision stays traceable, and every agent has ROI attached.

    Explore the platform