Skip to content

Commit

Permalink
updated vector search response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
arnavsinghvi11 committed Feb 23, 2024
1 parent df8372a commit 171567d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions dspy/retrieve/databricks_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import requests
from typing import Union, List, Optional
from collections import defaultdict
from dspy.primitives.prediction import Prediction

class DatabricksRM(dspy.Retrieve):
"""
Expand Down Expand Up @@ -113,7 +115,16 @@ def forward(self, query: Union[str, List[float]], query_type: str = 'vector') ->
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)
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])

0 comments on commit 171567d

Please sign in to comment.