From 06f45511912d58f3fe997a0b65e878d2c8629400 Mon Sep 17 00:00:00 2001 From: Chen Qian Date: Fri, 27 Dec 2024 13:20:51 -0800 Subject: [PATCH] Allow returning empty results when nothing is retrieved from DatabricksRM (#1995) * raise error when databricks index is not ready * don't fail on non-existing data_array --- dspy/retrieve/databricks_rm.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dspy/retrieve/databricks_rm.py b/dspy/retrieve/databricks_rm.py index 249b3856d..0334154dd 100644 --- a/dspy/retrieve/databricks_rm.py +++ b/dspy/retrieve/databricks_rm.py @@ -273,11 +273,12 @@ def forward( # Extracting the results items = [] - for _, data_row in enumerate(results["result"]["data_array"]): - item = {} - for col_name, val in zip(col_names, data_row): - item[col_name] = val - items += [item] + if "data_array" in results["result"]: + for _, data_row in enumerate(results["result"]["data_array"]): + item = {} + for col_name, val in zip(col_names, data_row): + item[col_name] = val + items += [item] # Sorting results by score in descending order sorted_docs = sorted(items, key=lambda x: x["score"], reverse=True)[: self.k]