RAG 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.
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 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 use a Conda environment
FOR /F "tokens=*" %T IN ('gcloud auth print-access-token') DO pip install --extra-index-url "https://oauth2accesstoken:%T@glsdk.gdplabs.id/gen-ai-internal/simple/" gllm-rag gllm-core gllm-generation gllm-inference gllm-pipeline gllm-retrieval gllm-misc gllm-datastoreYou can either:
You can refer to the guide whenever you need explanation or want to clarify how each part works.
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
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 Make sure you already set up the API keys for the models that you'd like to try. Refer to Supported Models for the supported models.
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.
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.
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
Congratulations! You have created an RAG pipeline with dynamic models!
Last updated