DSPy: The framework for programming—not prompting—language models
Python
update
demontegoc2a7c13124e9
diff --git a/dspy/retrieve/marqo_rm.py b/dspy/retrieve/marqo_rm.pyindex 7af3791c1..d85aa3c87 100644--- a/dspy/retrieve/marqo_rm.py+++ b/dspy/retrieve/marqo_rm.py@@ -1,6 +1,7 @@from collections import defaultdictfrom typing import List, Unionimport dspy+from dspy import dotdicttry:import marqo@@ -20,6 +21,9 @@ class MarqoRM(dspy.Retrieve):marqo_index_name (str): The name of the marqo index.marqo_client (marqo.client.Client): A marqo client instance.k (int, optional): The number of top passages to retrieve. Defaults to 3.+ page_content (str, optional): The name of the field in the marqo index that contains the text of the passage. Defaults to 'document'.+ filter_string (str, optional): A filter string to use when searching. Defaults to None.+ **kwargs: Additional keyword arguments to pass to the marqo search function.Examples:Below is a code snippet that shows how to use Marqo as the default retriver:@@ -43,13 +47,17 @@ class MarqoRM(dspy.Retrieve):marqo_index_name: str,marqo_client: marqo.client.Client,k: int = 3,+ page_content: str = 'document',+ filter_string: str = None):self._marqo_index_name = marqo_index_nameself._marqo_client = marqo_client+ self.page_content = page_content+ self.filter_string = filter_stringsuper().__init__(k=k)- def forward(self, query_or_queries: Union[str, List[str]]) -> dspy.Prediction:+ def forward(self, query_or_queries: Union[str, List[str]], k=None, **kwargs) -> dspy.Prediction:"""Search with Marqo for self.k top passages for queryArgs:@@ -63,13 +71,16 @@ class MarqoRM(dspy.Retrieve):if isinstance(query_or_queries, str)else query_or_queries)- queries = [q for q in queries if q]+ queries = [q for q in queries if q]+ limit = k if k else self.kall_query_results = []for query in queries:_result = self._marqo_client.index(self._marqo_index_name).search(q=query,- limit=self.k+ limit=limit,+ filter_string=self.filter_string,+ **kwargs)all_query_results.append(_result)@@ -77,8 +88,8 @@ class MarqoRM(dspy.Retrieve):for result_dict in all_query_results:for result in result_dict['hits']:- passages[result['document']] += result['_score']+ passages[result[self.page_content]] += result['_score']sorted_passages = sorted(- passages.items(), key=lambda x: x[1], reverse=True)[:self.k]- return dspy.Prediction(passages=[passage for passage, _ in sorted_passages])+ passages.items(), key=lambda x: x[1], reverse=True)[:limit]+ return [dotdict({"long_text": passage}) for passage, _ in sorted_passages]diff --git a/poetry.lock b/poetry.lockindex 1c1cec136..3b77ccac1 100644--- a/poetry.lock+++ b/poetry.lock@@ -2131,13 +2131,13 @@ files = [[[package]]name = "marqo"-version = "0.11.0"+version = "3.1.0"description = "Tensor search for humans"optional = truepython-versions = ">=3"files = [- {file = "marqo-0.11.0-py3-none-any.whl", hash = "sha256:e1a5409beeb02dcec725566cfbc5fd88a84ce65ca7bce08a1120f8082badeab4"},- {file = "marqo-0.11.0.tar.gz", hash = "sha256:808e691cf06f5f7d67d422dc7f5f6fcc53b9acc6a4bc000abbcae8a817fd765d"},+ {file = "marqo-3.1.0-py3-none-any.whl", hash = "sha256:e777949b1ff4d6229c8d92e7f3e0c34ed229755b7795ef3af7c2430bc6c32531"},+ {file = "marqo-3.1.0.tar.gz", hash = "sha256:4a9160f4a194cb1d594dfcc7b3310bcabc640c06fd0343251e169391735fdbcd"},][package.dependencies]diff --git a/setup.py b/setup.pyindex 7d0918ebc..64f8f07f4 100644--- a/setup.py+++ b/setup.py@@ -24,7 +24,7 @@ setup(extras_require={"chromadb": ["chromadb~=0.4.14"],"qdrant": ["qdrant-client", "fastembed"],- "marqo": ["marqo"],+ "marqo": ["marqo~=3.1.0"],"mongodb": ["pymongo~=3.12.0"],"pinecone": ["pinecone-client~=2.2.4"],"weaviate": ["weaviate-client~=3.26.1"],