DSPy: The framework for programming—not prompting—language models
Python
Added k to arguments in qdrant forward function
tleersc124314c2a58
diff --git a/dspy/retrieve/qdrant_rm.py b/dspy/retrieve/qdrant_rm.pyindex 4a6660a26..a54f0feb4 100644--- a/dspy/retrieve/qdrant_rm.py+++ b/dspy/retrieve/qdrant_rm.py@@ -1,6 +1,7 @@from collections import defaultdictfrom typing import List, Unionimport dspy+from typing import Optionaltry:from qdrant_client import QdrantClient@@ -51,7 +52,7 @@ class QdrantRM(dspy.Retrieve):super().__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: Optional[int]) -> dspy.Prediction:"""Search with Qdrant for self.k top passages for queryArgs:@@ -66,9 +67,10 @@ class QdrantRM(dspy.Retrieve):else query_or_queries)queries = [q for q in queries if q] # Filter empty queries-++ k = k if k is not None else self.kbatch_results = self._qdrant_client.query_batch(- self._qdrant_collection_name, query_texts=queries, limit=self.k)+ self._qdrant_collection_name, query_texts=queries, limit=k)passages = defaultdict(float)for batch in batch_results:@@ -77,5 +79,5 @@ class QdrantRM(dspy.Retrieve):passages[result.document] += result.scoresorted_passages = sorted(- passages.items(), key=lambda x: x[1], reverse=True)[:self.k]+ passages.items(), key=lambda x: x[1], reverse=True)[:k]return dspy.Prediction(passages=[passage for passage, _ in sorted_passages])