gearsRAG with Dynamic Models

This guide will walk you through the process of creating a Pipeline where the model is not fixed. This is useful for RAG applications where users can freely select their models.

circle-info

This tutorial extends the Your First RAG Pipeline tutorial. Ensure you have followed the instructions to set up your repository.

chevron-rightPrerequisiteshashtag

This example specifically requires:

  1. Completion of all setup steps listed on the Prerequisites page.

  2. An Elastic Search vector data store that is already set up and available for use. Refer to Supported Vector Data Store and Index Your Data with Vector Data Store.

You must have already completed the following tutorial:

Installation

# you can use a Conda environment
pip install --extra-index-url "https://oauth2accesstoken:$(gcloud auth print-access-token)@glsdk.gdplabs.id/gen-ai-internal/simple/" gllm-rag gllm-core gllm-generation gllm-inference gllm-pipeline gllm-retrieval gllm-misc gllm-datastore

You can either:

  1. You can refer to the guide whenever you need explanation or want to clarify how each part works.

  2. Follow along with each step to recreate the files yourself while learning about the components and how to integrate them.

Both options will workβ€”choose based on whether you prefer speed or learning by doing!

Project Setup

1

Extend Your RAG Pipeline Project

Start with your completed RAG pipeline project from the previous tutorial. Add the query transformer component to your existing structure:

You'll extend your existing structure with this new file:

<project-name>/
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ <index>/...                    
β”‚   β”œβ”€β”€ chroma.sqlite3                 
β”‚   β”œβ”€β”€ imaginary_animals.csv         
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ retriever.py                
β”‚   └── response_synthesizer.py     # πŸ‘ˆ Updated with dynamic model option
β”œβ”€β”€ pipeline.py                     # πŸ‘ˆ Updated with dynamic model pipeline
β”œβ”€β”€ indexer.py                      
└── .env                            
circle-exclamation

1) Make the response synthesizer dynamic

For the user to be able to utilize different models, we will make the response synthesizer dynamic. To do this, we will wrap the response synthesizer inside a builder function, like so.

2) Make the pipeline dynamic

Next, we will make the pipeline itself dynamic.

1

Import the response synthesizer builder

Since it is the response synthesizer that will handle the calls to the different LMs, we change our import from using the prebuilt component to using the build_response_synthesizer function that we created in the previous step.

2

Wrap the pipeline inside a builder function

Similarly, we need to make it so that the Pipeline is dynamic by wrapping it inside a builder function, which builds a new pipeline with the selected model.

3) Run the pipeline

To run the pipeline, we modify the main block as follows:

You should get a response similar to this:

πŸ“‚ Complete Guide Files

file-archive
4MB

Congratulations! You have created an RAG pipeline with dynamic models!

Last updated