Retrieval Module¶
erniebot_agent.retrieval
¶
BaizhongSearch
¶
A class for interacting with the Baizhong Search API.
Attributes:
| Name | Type | Description |
|---|---|---|
base_url |
str
|
The base URL for the AIStudio service. |
access_token |
str
|
The access token for authentication. |
knowledge_base_id |
int
|
The ID of the knowledge base being used (if applicable). |
Source code in erniebot-agent/src/erniebot_agent/retrieval/baizhong_search.py
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
__init__(access_token, knowledge_base_name=None, knowledge_base_id=None)
¶
Initialize a BaizhongSearch object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token |
str
|
The access token for authentication. |
required |
knowledge_base_name |
Optional[str]
|
The name of the knowledge base to use (optional). |
None
|
knowledge_base_id |
Optional[int]
|
The ID of an existing knowledge base to use (optional). |
None
|
Raises:
| Type | Description |
|---|---|
BaizhongError
|
If neither knowledge_base_name nor knowledge_base_id is provided. |
Source code in erniebot-agent/src/erniebot_agent/retrieval/baizhong_search.py
create_knowledge_base(knowledge_base_name)
¶
Create a JSON payload with the provided knowledge base name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
knowledge_base_name |
str
|
The knowledge base name. |
required |
Returns:
| Type | Description |
|---|---|
|
Dict[str, Any]: A dictionary containing knowledge base results. |
Raises:
| Type | Description |
|---|---|
BaizhongError
|
If the API request fails, this exception is raised with details about the error. |
Source code in erniebot-agent/src/erniebot_agent/retrieval/baizhong_search.py
search(query, top_k=10, filters=None)
¶
Perform a search using the Baizhong common search API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query |
str
|
The search query. |
required |
top_k |
int
|
The number of top results to retrieve (default is 10). |
10
|
filters |
Optional[Dict[str, Any]]
|
Additional filters to apply to the search query |
None
|
Returns:
| Type | Description |
|---|---|
|
List[Dict[str, Any]]: A list of dictionaries containing search results. |
Raises:
| Type | Description |
|---|---|
BaizhongError
|
If the API request fails, this exception is raised with details about the error. |