|
1 | 1 | # Copyright (c) Alibaba, Inc. and its affiliates. |
2 | | -from abc import abstractmethod |
| 2 | +from abc import ABC, abstractmethod |
3 | 3 | from typing import Any, List |
4 | 4 |
|
5 | | -from ms_agent.llm import Message |
6 | 5 |
|
7 | | - |
8 | | -class Rag: |
| 6 | +class RAG(ABC): |
9 | 7 | """The base class for rags""" |
10 | 8 |
|
11 | 9 | def __init__(self, config): |
12 | 10 | self.config = config |
13 | 11 |
|
14 | 12 | @abstractmethod |
15 | | - async def add_document(self, url: str, content: str, **metadata) -> bool: |
| 13 | + async def add_documents(self, documents: List[str]) -> bool: |
16 | 14 | """Add document to Rag |
17 | 15 |
|
18 | 16 | Args: |
19 | | - url(`str`): The url of the document |
20 | | - content(`str`): The content of the document |
21 | | - **metadata: Metadata information |
| 17 | + documents(`List[str]`): The content of the document |
22 | 18 |
|
23 | 19 | Returns: |
24 | 20 | success or not |
25 | 21 | """ |
26 | 22 | pass |
27 | 23 |
|
28 | 24 | @abstractmethod |
29 | | - async def search_documents(self, |
30 | | - query: str, |
31 | | - limit: int = 5, |
32 | | - score_threshold: float = 0.7, |
33 | | - **filters) -> List[Any]: |
34 | | - """Search documents in Rag |
| 25 | + async def query(self, query: str) -> str: |
| 26 | + """Search documents |
35 | 27 |
|
36 | 28 | Args: |
37 | 29 | query(`str`): The query to search for |
38 | | - limit(`int`): The number of documents to return |
39 | | - score_threshold(`float`): The score threshold |
40 | | - **filters: Any extra filters |
41 | | -
|
42 | 30 | Returns: |
43 | | - List of documents |
| 31 | + The query result |
44 | 32 | """ |
45 | 33 | pass |
46 | 34 |
|
47 | 35 | @abstractmethod |
48 | | - async def delete_document(self, url: str) -> bool: |
49 | | - """Delete document from Rag |
| 36 | + async def retrieve(self, |
| 37 | + query: str, |
| 38 | + limit: int = 5, |
| 39 | + score_threshold: float = 0.7, |
| 40 | + **filters) -> List[Any]: |
| 41 | + """Retrieve documents |
50 | 42 |
|
51 | 43 | Args: |
52 | | - url(`str`): The url of the document |
| 44 | + query(`str`): The query to search for |
| 45 | + limit(`int`): The number of documents to return |
| 46 | + score_threshold(`float`): The score threshold |
| 47 | + **filters: Any extra filters |
53 | 48 |
|
54 | 49 | Returns: |
55 | | - bool: True if the document was successfully deleted |
| 50 | + List of documents |
56 | 51 | """ |
57 | 52 | pass |
58 | | - |
59 | | - @abstractmethod |
60 | | - async def run(self, inputs: List[Message]) -> List[Message]: |
61 | | - pass |
0 commit comments