summaryrefslogtreecommitdiff
path: root/rag/retriever/rerank/abstract.py
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2024-04-24 09:09:24 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2024-04-24 09:09:24 +0200
commit9e0cbcb4e7f1f3f95f304046d3190c6ebc4d3901 (patch)
tree5d890ce2705b79f23d63988c140d08edadaf35c5 /rag/retriever/rerank/abstract.py
parent2e85325639ce3827cc2eb32f9750dfa873e3a480 (diff)
Reformat and fix typo
Diffstat (limited to 'rag/retriever/rerank/abstract.py')
-rw-r--r--rag/retriever/rerank/abstract.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/rag/retriever/rerank/abstract.py b/rag/retriever/rerank/abstract.py
new file mode 100644
index 0000000..b96b70a
--- /dev/null
+++ b/rag/retriever/rerank/abstract.py
@@ -0,0 +1,17 @@
+from abc import abstractmethod
+
+from rag.generator.prompt import Prompt
+
+
+class AbstractReranker(type):
+ _instances = {}
+
+ def __call__(cls, *args, **kwargs):
+ if cls not in cls._instances:
+ instance = super().__call__(*args, **kwargs)
+ cls._instances[cls] = instance
+ return cls._instances[cls]
+
+ @abstractmethod
+ def rank(self, prompt: Prompt) -> Prompt:
+ return prompt