Optimizing Parameters
Optimize your parameters of your LLM System for your evaluation metrics
Below, we demonstrate how to set up a Python notebook to optimize a basic Retrieval-Augmented Generation (RAG) pipeline using the Nomadic SDK. We provide the basic steps to set up a simple RAG optimization experiment with the Nomadic SDK to identify the best-performing hyperparameter configurations for your pipeline.
This example uses the Llama 2 academic paper as a document source, performs a question-answering task, and optimizes hyperparameters for chunk size and top-k using a semantic similarity evaluation metric.
For other templates, see the Cookbooks repository.
1. Install Nomadic
To run these locally, you’ll need to install the Nomadic SDK, as below:
To sync results with the Nomadic Workspace, you’ll need a Nomadic account and an associated API key.
2. Import Necessary Libraries & Configure OpenAI API Key
Import the required classes for Experiment setup, document processing, and evaluation.
3. Prepare Data Ingestion Pipeline
Download and process the necessary documents and evaluation dataset.
4. Define the Objective Function
This function evaluates the model’s performance given specific hyperparameters.
Here, we take in both our tunable and fixed hyperparameter values. We then utilize LlamaIndex’s semantic similary evaluator to compare the RAG system’s produced answers to the given ground truths. Our reported evaluation metric that is representative of the selected hyperparameters’ performance is the average of the evaluator’s produced score, which we return.
5. Set Up and Run the Experiment
Define and run the Nomadic experiment with the specified hyperparameters. We’ve chosen to explore the chunk_size
values of 256, 512, 1024
, and top_k
values of 1, 2, 5
.
6. Interpret & Visualize Results
After running the experiment, we view the best hyperparameters’ produced results, in terms of their overall semantic similarity score, and the model’s actual produced answers.