feat(knowledge): add reranking functionality for simple_assistant_agent and summary_assis_agent

- Implement reranking of retrieved chunks when needed
- Improve relevance of search results by ranking chunks based on query
This commit is contained in:
tam
2025-04-21 09:58:01 +08:00
parent b0ef14c111
commit 32b1fd4c1e

View File

@@ -111,6 +111,9 @@ class RetrieverResource(Resource[ResourceParameters]):
if not question:
raise ValueError("Question is required for knowledge resource.")
chunks = await self.retrieve(question)
if self.need_rerank and len(chunks) > 1:
chunks = self.reranker.rank(candidates_with_scores=chunks, query=question)
prompt_template = """Resources-{name}:\n {content}"""
prompt_template_zh = """资源-{name}:\n {content}"""
if lang == "en":