Fix init to accept kwargs

This commit is contained in:
Connor Shorten
2025-11-27 11:36:01 -05:00
parent b0578059e5
commit 313ab4c8c6

View File

@@ -48,23 +48,24 @@ class CERankerAgent(PrecompiledAgent):
result = await self.reranker.acall(query=query, document=document) result = await self.reranker.acall(query=query, document=document)
return (document, result.relevance_score) return (document, result.relevance_score)
async def __acall__(self, query: str, k: int | None = None) -> str: async def __acall__(self, query: str, k: int | None = None) -> list[str]:
if k is None: if k is None:
k = self.k k = self.k
response = self.collection.query.hybrid(query=query, limit=self.k) response = self.collection.query.hybrid(query=query, limit=k)
documents = [o.properties["content"] for o in response.objects] documents = [o.properties["content"] for o in response.objects]
scored_results = await asyncio.gather( scored_results = await asyncio.gather(
*[self._score_document(query, doc) for doc in documents] *[self._score_document(query, doc) for doc in documents]
) )
scored_results.sort(key=lambda x: x[1], reverse=True)
return "\n".join([doc for doc, score in scored_results[:self.k]])
def __call__(self, query: str, k: int | None = None) -> str: # Sort by the score (descending). If score is True, it comes first.
scored_results.sort(key=lambda x: x[1], reverse=True)
# Return a list of documents (not joined as a string), up to k results
return [doc for doc, score in scored_results[:k]]
def __call__(self, query: str, k: int | None = None) -> list[str]:
return asyncio.run(self.__acall__(query, k)) return asyncio.run(self.__acall__(query, k))