-
Notifications
You must be signed in to change notification settings - Fork 533
/
Copy pathsimilarity_evaluation.py
41 lines (32 loc) · 1.23 KB
/
similarity_evaluation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from abc import ABCMeta, abstractmethod
from typing import Tuple, Dict, Any
class SimilarityEvaluation(metaclass=ABCMeta):
"""Similarity Evaluation interface,
determine the similarity between the input request and the requests from the Vector Store.
Based on this similarity, it determines whether a request matches the cache.
Example:
.. code-block:: python
from gptcache import cache
from gptcache.similarity_evaluation import SearchDistanceEvaluation
cache.init(
similarity_evaluation=SearchDistanceEvaluation()
)
"""
@abstractmethod
def evaluation(
self, src_dict: Dict[str, Any], cache_dict: Dict[str, Any], **kwargs
) -> float:
"""Evaluate the similarity score of the user and cache requests pair.
:param src_dict: the user request params.
:type src_dict: Dict
:param cache_dict: the cache request params.
:type cache_dict: Dict
"""
pass
@abstractmethod
def range(self) -> Tuple[float, float]:
"""Range of similarity score.
:return: the range of similarity score, which is the min and max values
:rtype: Tuple[float, float]
"""
pass