MlflowException: Unsupported Databricks profile key prefix: ''. Key prefixes cannot be empty.

AnnamalaiVR
New Contributor

I am trying to fetch data from mlflow model registry in Databricks and to use it in my local notebook. But I don't find any resource in internet to do so. I want to configure my mlflow in such a way i can fetch model registry values from databricks workspace. Also, I am sharing the code for more clarification.

In the below code. I'm getting the error in client.search_model_versions() line.

databricks_host = "*********************"
databricks_token = "**********"
databricks_org_id = "******"

# Set the Databricks tracking URI
tracking_uri = f"databricks://{databricks_host}?org_id={databricks_org_id}"

nw_dict = dict()
for mv in client.search_model_versions("name='sk-learn-logistic-reg-model'"):
    dic = dict(mv)    
    run_data_dict = client.get_run(dic['run_id']).data.to_dictionary()
    print(run_data_dict['metrics']['accuracy score'])
    nw_dict[dic['run_id']] = run_data_dict['metrics']['accuracy score']

Kumaran
Databricks Employee
Databricks Employee

Hi @AnnamalaiVR,

Thank you for posting the question in Databricks Community.

In your Python code, import the MLflow library and create a client object to access your Model Registry.

 

%python
import mlflow

# Set the Databricks tracking URI
databricks_host = "*********************"
databricks_token = "**********"
databricks_org_id = "******"
tracking_uri = f"databricks://{databricks_host}?org_id={databricks_org_id}"
mlflow.set_tracking_uri(tracking_uri)

# Configure the MLflow client
client = mlflow.tracking.MlflowClient()
 
Now you can query the Model Registry using the client object. Here's an example to fetch the registered model versions for a given model name:
%python
model_name = "my_model"
model_versions = client.search_model_versions(f"name='{model_name}'")

for model_version in model_versions:
# Fetch the run ID and metrics for the model version
run_id = model_version.run_id
metrics = client.get_run(run_id).data.metrics

# Add the metrics to a dictionary
accuracy_score = metrics["accuracy score"]
nw_dict[run_id] = accuracy_score
 
Make sure to replace the model_name variable with the name of your registered model.