Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update you_rm to return an iterable of predictions, in line with othe… #1

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dsp/primitives/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from collections.abc import Iterable

import numpy as np

import dsp


Expand All @@ -7,6 +10,10 @@ def retrieve(query: str, k: int, **kwargs) -> list[str]:
if not dsp.settings.rm:
raise AssertionError("No RM is loaded.")
passages = dsp.settings.rm(query, k=k, **kwargs)
if not isinstance(passages, Iterable):
# it's not an iterable yet; make it one.
# TODO: we should unify the type signatures of dspy.Retriever
passages = [passages]
passages = [psg.long_text for psg in passages]

if dsp.settings.reranker:
Expand Down
3 changes: 2 additions & 1 deletion dspy/retrieve/you_rm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dspy
import os
import requests
from dsp.utils import dotdict

from typing import Union, List, Optional

Expand Down Expand Up @@ -43,4 +44,4 @@ def forward(self, query_or_queries: Union[str, List[str]], k: Optional[int] = No
for hit in results["hits"][:k]:
for snippet in hit["snippets"]:
docs.append(snippet)
return dspy.Prediction(passages=docs)
return [dotdict({"long_text": document}) for document in docs]