Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

updated vector search response handling

Arnav Singhvi171567d818f5
diff --git a/dspy/retrieve/databricks_rm.py b/dspy/retrieve/databricks_rm.py
index 530fcf02d..2431585e8 100644
--- a/dspy/retrieve/databricks_rm.py
+++ b/dspy/retrieve/databricks_rm.py
@@ -2,6 +2,8 @@ import dspy
import os
import requests
from typing import Union, List, Optional
+from collections import defaultdict
+from dspy.primitives.prediction import Prediction
class DatabricksRM(dspy.Retrieve):
"""
@@ -113,7 +115,16 @@ class DatabricksRM(dspy.Retrieve):
headers=headers
)
results = response.json()
- docs = []
+
+ docs = defaultdict(float)
+ text, score = None, None
for data_row in results["result"]["data_array"]:
- docs.append({col: val for col, val in zip(results["manifest"]["columns"], data_row)})
- return dspy.Prediction(embeddings=docs)
\ No newline at end of file
+ for col, val in zip(results["manifest"]["columns"], data_row):
+ if col["name"] == 'text':
+ text = val
+ if col["name"] == 'score':
+ score = val
+ docs[text] += score
+
+ sorted_docs = sorted(docs.items(), key=lambda x: x[1], reverse=True)[:self.k]
+ return Prediction(docs=[doc for doc, _ in sorted_docs])