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-datastoreHow to Use this Guide
You can either:
Download or copy the complete guide file(s) to get everything ready instantly by heading to 📂 Complete Guide Files section in the end of this page. 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.
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