Path: blob/master/cloud/notebooks/python_sdk/experiments/autoai_rag/Use AutoAI RAG and Chroma to create a pattern about IBM.ipynb
6405 views
Use AutoAI RAG and Chroma to create a pattern and get information from ibm-watsonx-ai
SDK documentation
Disclaimers
Use only Projects and Spaces that are available in watsonx context.
Notebook content
This notebook contains the steps and code to demonstrate the usage of IBM AutoAI RAG. The AutoAI RAG experiment conducted in this notebook uses data scraped from the ibm-watsonx-ai
SDK documentation.
Some familiarity with Python is helpful. This notebook uses Python 3.11.
Learning goal
The learning goals of this notebook are:
Create an AutoAI RAG job that will find the best RAG pattern based on provided data
Contents
This notebook contains the following parts:
Set up the environment
Before you use the sample code in this notebook, you must perform the following setup tasks:
Create a watsonx.ai Runtime Service instance (a free plan is offered and information about how to create the instance can be found here).
Install and import the required modules and dependencies
Defining the watsonx.ai credentials
This cell defines the credentials required to work with the watsonx.ai Runtime service.
Action: Provide the IBM Cloud user API key. For details, see documentation.
Defining the project id
The foundation model requires a project id that provides the context for the call. We will try to obtain the id directly from the project in which this notebook runs. If this fails, you'll have to provide the project id.
Create an instance of APIClient with authentication details.
RAG Optimizer definition
Defining a connection to training data
Upload training data to a COS bucket and then define a connection to this file. This example uses the Base
description from the ibm_watsonx_ai
documentation.
The code in the next cell uploads training data to the bucket.
Define a connection to training data.
Defining a connection to test data
Upload a json
file that will be used for benchmarking to COS and then define a connection to this file. This example uses content from the ibm_watsonx_ai
SDK documentation.
The code in the next cell uploads testing data to the bucket as a json
file.
Define connection information to testing data.
RAG Optimizer configuration
Provide the input information for AutoAI RAG optimizer:
name
- experiment namedescription
- experiment descriptionmax_number_of_rag_patterns
- maximum number of RAG patterns to createoptimization_metrics
- target optimization metrics
Configuration parameters can be retrieved via get_params()
.
You can use the get_run_status()
method to monitor AutoAI RAG jobs in background mode.
Additionally, you can pass the scoring
parameter to the summary method, to filter RAG patterns starting with the best.
Get selected pattern
Get the RAGPattern object from the RAG Optimizer experiment. By default, the RAGPattern of the best pattern is returned.
The pattern details can be retrieved by calling the get_pattern_details
method:
Create the index/collection
Build solution on the best pattern, with additional document indexing.
You can check which index_name
you are working on:
Query the RAGPattern locally, to test it.
Get executed optimizer's configuration parameters
Get historical rag_optimizer instance and training details
List trained patterns for selected optimizer
If you want to clean up all created assets:
experiments
trainings
pipelines
model definitions
models
functions
deployments
please follow up this sample notebook.
Summary and next steps
You successfully completed this notebook!
You learned how to use ibm-watsonx-ai
to run AutoAI RAG experiments.
Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Authors
Michał Steczko, Software Engineer watsonx.ai
Copyright © 2024-2025 IBM. This notebook and its source code are released under the terms of the MIT License.