mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-15 22:19:28 +00:00
feat: add evaluation service module for RAG and Agent (#2070)
This commit is contained in:
@@ -287,7 +287,7 @@ class AnswerEvaluatorOperator(JoinOperator[List[EvaluationResult]]):
|
||||
contexts=contexts,
|
||||
passing=result.passing,
|
||||
raw_dataset=raw_dataset,
|
||||
metric_name=metric.name,
|
||||
metric_name=metric.name(),
|
||||
feedback=result.feedback,
|
||||
)
|
||||
)
|
||||
|
@@ -184,6 +184,7 @@ class IndexStoreBase(ABC):
|
||||
max_threads,
|
||||
)
|
||||
|
||||
@abstractmethod
|
||||
def similar_search(
|
||||
self, text: str, topk: int, filters: Optional[MetadataFilters] = None
|
||||
) -> List[Chunk]:
|
||||
@@ -196,16 +197,26 @@ class IndexStoreBase(ABC):
|
||||
Return:
|
||||
List[Chunk]: The similar documents.
|
||||
"""
|
||||
return self.similar_search_with_scores(text, topk, 0.0, filters)
|
||||
|
||||
async def asimilar_search(
|
||||
self,
|
||||
query: str,
|
||||
topk: int,
|
||||
filters: Optional[MetadataFilters] = None,
|
||||
) -> List[Chunk]:
|
||||
"""Async similar_search in vector database."""
|
||||
return await blocking_func_to_async_no_executor(
|
||||
self.similar_search, query, topk, filters
|
||||
)
|
||||
|
||||
async def asimilar_search_with_scores(
|
||||
self,
|
||||
doc: str,
|
||||
query: str,
|
||||
topk: int,
|
||||
score_threshold: float,
|
||||
filters: Optional[MetadataFilters] = None,
|
||||
) -> List[Chunk]:
|
||||
"""Aynsc similar_search_with_score in vector database."""
|
||||
"""Async similar_search_with_score in vector database."""
|
||||
return await blocking_func_to_async_no_executor(
|
||||
self.similar_search_with_scores, doc, topk, score_threshold, filters
|
||||
self.similar_search_with_scores, query, topk, score_threshold, filters
|
||||
)
|
||||
|
@@ -54,7 +54,7 @@ class RetrieverEvaluatorOperator(JoinOperator[List[EvaluationResult]]):
|
||||
contexts=contexts,
|
||||
passing=result.passing,
|
||||
raw_dataset=raw_dataset,
|
||||
metric_name=metric.name,
|
||||
metric_name=metric.name(),
|
||||
)
|
||||
)
|
||||
return results
|
||||
|
@@ -10,7 +10,6 @@ from dbgpt.rag.retriever.rerank import DefaultRanker, Ranker
|
||||
from dbgpt.rag.retriever.rewrite import QueryRewrite
|
||||
from dbgpt.storage.vector_store.filters import MetadataFilters
|
||||
from dbgpt.util.chat_util import run_async_tasks
|
||||
from dbgpt.util.executor_utils import blocking_func_to_async_no_executor
|
||||
from dbgpt.util.tracer import root_tracer
|
||||
|
||||
|
||||
@@ -241,9 +240,7 @@ class EmbeddingRetriever(BaseRetriever):
|
||||
"query": query,
|
||||
},
|
||||
):
|
||||
return await blocking_func_to_async_no_executor(
|
||||
self._index_store.similar_search, query, self._top_k, filters
|
||||
)
|
||||
return await self._index_store.asimilar_search(query, self._top_k, filters)
|
||||
|
||||
async def _run_async_tasks(self, tasks) -> List[Chunk]:
|
||||
"""Run async tasks."""
|
||||
|
Reference in New Issue
Block a user