Updated dataset APIs (#2820)

### What problem does this PR solve?


### Type of change


- [x] Documentation Update
This commit is contained in:
writinwaters 2024-10-12 20:07:21 +08:00 committed by GitHub
parent 6eed115723
commit 8e5efcc47f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 175 additions and 157 deletions

View File

@ -5,7 +5,7 @@
**POST** `/api/v1/dataset` **POST** `/api/v1/dataset`
Creates a dataset. Creates a knowledge base (dataset).
### Request ### Request
@ -31,11 +31,11 @@ Creates a dataset.
#### Request example #### Request example
```bash ```bash
# "id": id must not be provided. # "id": "id" must not be provided.
# "name": name is required and can't be duplicated. # "name": name is required and cannot be duplicated.
# "tenant_id": tenant_id must not be provided. # "tenant_id": tenant_id must not be provided.
# "embedding_model": embedding_model must not be provided. # "embedding_model": REQUIRED.
# "navie" means general. # "naive": general.
curl --request POST \ curl --request POST \
--url http://{address}/api/v1/dataset \ --url http://{address}/api/v1/dataset \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
@ -51,21 +51,21 @@ curl --request POST \
#### Request parameters #### Request parameters
- `"id"`: (*Body parameter*) - `"id"`: (*Body parameter*)
The ID of the created dataset used to uniquely identify different datasets. The unique identifier of each created dataset.
- If creating a dataset, `id` must not be provided. - When creating a dataset, `id` must not be provided.
- `"name"`: (*Body parameter*) - `"name"`: (*Body parameter*)
The name of the dataset, which must adhere to the following requirements: The name of the dataset, which must adhere to the following requirements:
- Required when creating a dataset and must be unique. - Required when creating a dataset and must be unique.
- If updating a dataset, `name` must still be unique. - When updating a dataset, `name` must still be unique.
- `"avatar"`: (*Body parameter*) - `"avatar"`: (*Body parameter*)
Base64 encoding of the avatar. Base64 encoding of the avatar.
- `"tenant_id"`: (*Body parameter*) - `"tenant_id"`: (*Body parameter*)
The ID of the tenant associated with the dataset, used to link it with specific users. The ID of the tenant associated with the dataset, used to link it with specific users.
- If creating a dataset, `tenant_id` must not be provided. - When creating a dataset, `tenant_id` must not be provided.
- If updating a dataset, `tenant_id` cannot be changed. - When updating a dataset, `tenant_id` cannot be changed.
- `"description"`: (*Body parameter*) - `"description"`: (*Body parameter*)
The description of the dataset. The description of the dataset.
@ -74,31 +74,31 @@ curl --request POST \
The language setting for the dataset. The language setting for the dataset.
- `"embedding_model"`: (*Body parameter*) - `"embedding_model"`: (*Body parameter*)
Embedding model used in the dataset to generate vector embeddings. Embedding model used in the dataset for generating vector embeddings.
- If creating a dataset, `embedding_model` must not be provided. - When creating a dataset, `embedding_model` must not be provided.
- If updating a dataset, `embedding_model` cannot be changed. - When updating a dataset, `embedding_model` cannot be changed.
- `"permission"`: (*Body parameter*) - `"permission"`: (*Body parameter*)
Specifies who can manipulate the dataset. Specifies who can manipulate the dataset.
- `"document_count"`: (*Body parameter*) - `"document_count"`: (*Body parameter*)
Document count of the dataset. Document count of the dataset.
- If updating a dataset, `document_count` cannot be changed. - When updating a dataset, `document_count` cannot be changed.
- `"chunk_count"`: (*Body parameter*) - `"chunk_count"`: (*Body parameter*)
Chunk count of the dataset. Chunk count of the dataset.
- If updating a dataset, `chunk_count` cannot be changed. - When updating a dataset, `chunk_count` cannot be changed.
- `"parse_method"`: (*Body parameter*) - `"parse_method"`: (*Body parameter*)
Parsing method of the dataset. Parsing method of the dataset.
- If updating `parse_method`, `chunk_count` must be greater than 0. - When updating `parse_method`, `chunk_count` must be greater than 0.
- `"parser_config"`: (*Body parameter*) - `"parser_config"`: (*Body parameter*)
The configuration settings for the dataset parser. The configuration settings for the dataset parser.
### Response ### Response
The successful response includes a JSON object like the following: A successful response includes a JSON object like the following:
```json ```json
{ {
@ -139,8 +139,7 @@ The successful response includes a JSON object like the following:
- `"error_code"`: `integer` - `"error_code"`: `integer`
`0`: The operation succeeds. `0`: The operation succeeds.
An error response includes a JSON object like the following:
The error response includes a JSON object like the following:
```json ```json
{ {
@ -153,7 +152,7 @@ The error response includes a JSON object like the following:
**DELETE** `/api/v1/dataset` **DELETE** `/api/v1/dataset`
Deletes datasets by ids. Deletes datasets by their IDs.
### Request ### Request
@ -169,7 +168,7 @@ Deletes datasets by ids.
#### Request example #### Request example
```bash ```bash
# Either id or name must be provided, but not both. # Specify either "ids" or "names", NOT both.
curl --request DELETE \ curl --request DELETE \
--url http://{address}/api/v1/dataset \ --url http://{address}/api/v1/dataset \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
@ -181,13 +180,13 @@ curl --request DELETE \
#### Request parameters #### Request parameters
- `"ids"`: (*Body parameter*) - `"ids"`: (*Body parameter*)
Dataset IDs to delete. IDs of the datasets to delete.
### Response ### Response
The successful response includes a JSON object like the following: A successful response includes a JSON object like the following:
```json ```json
{ {
@ -199,7 +198,7 @@ The successful response includes a JSON object like the following:
`0`: The operation succeeds. `0`: The operation succeeds.
The error response includes a JSON object like the following: An error response includes a JSON object like the following:
```json ```json
{ {
@ -212,7 +211,7 @@ The error response includes a JSON object like the following:
**PUT** `/api/v1/dataset/{dataset_id}` **PUT** `/api/v1/dataset/{dataset_id}`
Updates a dataset by its id. Updates a dataset by its ID.
### Request ### Request
@ -227,14 +226,14 @@ Updates a dataset by its id.
#### Request example #### Request example
```bash ```bash
# "id": id is required. # "id": REQUIRED
# "name": If you update name, it can't be duplicated. # "name": If you update "name", it cannot be duplicated.
# "tenant_id": If you update tenant_id, it can't be changed # "tenant_id": If you update "tenant_id", it cannot be changed
# "embedding_model": If you update embedding_model, it can't be changed. # "embedding_model": If you update "embedding_model", it cannot be changed.
# "chunk_count": If you update chunk_count, it can't be changed. # "chunk_count": If you update "chunk_count", it cannot be changed.
# "document_count": If you update document_count, it can't be changed. # "document_count": If you update "document_count", it cannot be changed.
# "parse_method": If you update parse_method, chunk_count must be 0. # "parse_method": If you update "parse_method", "chunk_count" must be 0.
# "navie" means general. # "naive": General.
curl --request PUT \ curl --request PUT \
--url http://{address}/api/v1/dataset/{dataset_id} \ --url http://{address}/api/v1/dataset/{dataset_id} \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
@ -245,17 +244,18 @@ curl --request PUT \
"embedding_model": "BAAI/bge-zh-v1.5", "embedding_model": "BAAI/bge-zh-v1.5",
"chunk_count": 0, "chunk_count": 0,
"document_count": 0, "document_count": 0,
"parse_method": "navie" "parse_method": "naive"
}' }'
``` ```
#### Request parameters #### Request parameters
(Refer to the "Create Dataset" for the complete structure of the request parameters.)
See the "Create Dataset" for the complete structure of the request parameters.
### Response ### Response
The successful response includes a JSON object like the following: A successful response includes a JSON object like the following:
```json ```json
{ {
@ -267,7 +267,7 @@ The successful response includes a JSON object like the following:
`0`: The operation succeeds. `0`: The operation succeeds.
The error response includes a JSON object like the following: An error response includes a JSON object like the following:
```json ```json
{ {
@ -321,7 +321,7 @@ curl --request GET \
### Response ### Response
The successful response includes a JSON object like the following: A successful response includes a JSON object like the following:
```json ```json
{ {
@ -365,7 +365,7 @@ The successful response includes a JSON object like the following:
``` ```
The error response includes a JSON object like the following: An error response includes a JSON object like the following:
```json ```json
{ {
@ -409,7 +409,7 @@ curl --request POST \
### Response ### Response
The successful response includes a JSON object like the following: A successful response includes a JSON object like the following:
```shell ```shell
{ {
@ -421,7 +421,7 @@ The successful response includes a JSON object like the following:
`0`: The operation succeeds. `0`: The operation succeeds.
The error response includes a JSON object like the following: An error response includes a JSON object like the following:
```shell ```shell
{ {
@ -464,7 +464,7 @@ curl --request GET \
### Response ### Response
The successful response includes a JSON object like the following: A successful response includes a JSON object like the following:
```shell ```shell
{ {
@ -476,7 +476,7 @@ The successful response includes a JSON object like the following:
`0`: The operation succeeds. `0`: The operation succeeds.
The error response includes a JSON object like the following: An error response includes a JSON object like the following:
```shell ```shell
{ {
@ -528,7 +528,7 @@ curl --request GET \
### Response ### Response
The successful response includes a JSON object like the following: A successful response includes a JSON object like the following:
```shell ```shell
{ {
@ -605,7 +605,7 @@ The successful response includes a JSON object like the following:
`0`: The operation succeeds. `0`: The operation succeeds.
The error response includes a JSON object like the following: An error response includes a JSON object like the following:
```shell ```shell
{ {
@ -659,7 +659,7 @@ curl --request PUT \
### Response ### Response
The successful response includes a JSON object like the following: A successful response includes a JSON object like the following:
```shell ```shell
{ {
@ -667,7 +667,7 @@ The successful response includes a JSON object like the following:
} }
``` ```
The error response includes a JSON object like the following: An error response includes a JSON object like the following:
```shell ```shell
{ {
@ -710,7 +710,7 @@ curl --request POST \
### Response ### Response
The successful response includes a JSON object like the following: A successful response includes a JSON object like the following:
```shell ```shell
{ {
@ -718,7 +718,7 @@ The successful response includes a JSON object like the following:
} }
``` ```
The error response includes a JSON object like the following: An error response includes a JSON object like the following:
```shell ```shell
{ {
@ -761,7 +761,7 @@ curl --request DELETE \
### Response ### Response
The successful response includes a JSON object like the following: A successful response includes a JSON object like the following:
```shell ```shell
{ {
@ -769,7 +769,7 @@ The successful response includes a JSON object like the following:
} }
``` ```
The error response includes a JSON object like the following: An error response includes a JSON object like the following:
```shell ```shell
{ {
@ -808,7 +808,7 @@ curl --request GET \
### Response ### Response
The successful response includes a JSON object like the following: A successful response includes a JSON object like the following:
```shell ```shell
{ {
@ -863,7 +863,7 @@ The successful response includes a JSON object like the following:
} }
``` ```
The error response includes a JSON object like the following: An error response includes a JSON object like the following:
```shell ```shell
{ {

View File

@ -24,7 +24,7 @@ Creates a knowledge base (dataset).
### Parameters ### Parameters
#### name: `str`, *Required* #### name: *Required*
The unique name of the dataset to create. It must adhere to the following requirements: The unique name of the dataset to create. It must adhere to the following requirements:
@ -36,70 +36,81 @@ The unique name of the dataset to create. It must adhere to the following requir
- Maximum 65,535 characters. - Maximum 65,535 characters.
- Case-insensitive. - Case-insensitive.
#### avatar: `str` #### avatar
Base64 encoding of the avatar. Defaults to `""` Base64 encoding of the avatar. Defaults to `""`
#### tenant_id: `str` #### tenant_id
The id of the tenant associated with the created dataset is used to identify different users. Defaults to `None`. The id of the tenant associated with the created dataset is used to identify different users. Defaults to `None`.
- If creating a dataset, tenant_id must not be provided. - When creating a dataset, `tenant_id` must not be provided.
- If updating a dataset, tenant_id can't be changed. - When updating a dataset, `tenant_id` cannot be changed.
#### description: `str` #### description
The description of the created dataset. Defaults to `""`. The description of the created dataset. Defaults to `""`.
#### language: `str` #### language
The language setting of the created dataset. Defaults to `"English"`. ???????????? The language setting of the created dataset. Defaults to `"English"`.
#### embedding_model: `str` #### embedding_model
The specific model used by the dataset to generate vector embeddings. Defaults to `""`. The specific model used by the dataset to generate vector embeddings. Defaults to `""`.
- If creating a dataset, embedding_model must not be provided. - When creating a dataset, `embedding_model` must not be provided.
- If updating a dataset, embedding_model can't be changed. - When updating a dataset, `embedding_model` cannot be changed.
#### permission: `str` #### permission
Specify who can operate on the dataset. Defaults to `"me"`. The person who can operate on the dataset. Defaults to `"me"`.
#### document_count: `int` #### document_count
The number of documents associated with the dataset. Defaults to `0`. The number of documents associated with the dataset. Defaults to `0`.
- If updating a dataset, `document_count` can't be changed. :::tip NOTE
When updating a dataset, `document_count` cannot be changed.
:::
#### chunk_count: `int` #### chunk_count
The number of data chunks generated or processed by the created dataset. Defaults to `0`. The number of data chunks generated or processed by the created dataset. Defaults to `0`.
- If updating a dataset, chunk_count can't be changed. :::tip NOTE
When updating a dataset, `chunk_count` cannot be changed.
:::
#### parse_method, `str` #### parse_method
The method used by the dataset to parse and process data. The method used by the dataset to parse and process data. Defaults to `"naive"`.
- If updating parse_method in a dataset, chunk_count must be greater than 0. Defaults to `"naive"`. :::tip NOTE
When updating `parse_method` in a dataset, `chunk_count` must be greater than 0.
:::
#### parser_config, `Dataset.ParserConfig` #### parser_config
The configuration settings for the parser used by the dataset. The parser configuration of the dataset. A `ParserConfig` object contains the following attributes:
- `chunk_token_count`: Defaults to `128`.
- `layout_recognize`: Defaults to `True`.
- `delimiter`: Defaults to `'\n!?。;!?'`.
- `task_page_size`: Defaults to `12`.
### Returns ### Returns
```python
DataSet - Success: A `dataset` object.
description: dataset object - Failure: `Exception`
```
### Examples ### Examples
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
ds = rag.create_dataset(name="kb_1") ds = rag_object.create_dataset(name="kb_1")
``` ```
--- ---
@ -107,28 +118,27 @@ ds = rag.create_dataset(name="kb_1")
## Delete knowledge bases ## Delete knowledge bases
```python ```python
RAGFlow.delete_datasets(ids: List[str] = None) RAGFlow.delete_datasets(ids: list[str] = None)
``` ```
Deletes knowledge bases.
Deletes knowledge bases by name or ID.
### Parameters ### Parameters
#### ids: `List[str]` #### ids
The ids of the datasets to be deleted.
The IDs of the knowledge bases to delete.
### Returns ### Returns
```python - Success: No value is returned.
no return - Failure: `Exception`
```
### Examples ### Examples
```python #### Delete knowledge bases by name
from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") ```python
rag.delete_datasets(ids=["id_1","id_2"]) rag.delete_datasets(ids=["id_1","id_2"])
``` ```
@ -144,76 +154,84 @@ RAGFlow.list_datasets(
desc: bool = True, desc: bool = True,
id: str = None, id: str = None,
name: str = None name: str = None
) -> List[DataSet] ) -> list[DataSet]
``` ```
Lists all knowledge bases in the RAGFlow system. Lists all knowledge bases.
### Parameters ### Parameters
#### page: `int` #### page
The current page number to retrieve from the paginated data. This parameter determines which set of records will be fetched. Defaults to `1`. The current page number to retrieve from the paginated data. This parameter determines which set of records will be fetched. Defaults to `1`.
#### page_size: `int` #### page_size
The number of records to retrieve per page. This controls how many records will be included in each page. Defaults to `1024`. The number of records to retrieve per page. This controls how many records will be included in each page. Defaults to `1024`.
#### order_by: `str` #### order_by
The field by which the records should be sorted. This specifies the attribute or column used to order the results. Defaults to `"create_time"`. The attribute by which the results are sorted. Defaults to `"create_time"`.
#### desc: `bool` #### desc
Whether the sorting should be in descending order. Defaults to `True`. Indicates whether to sort the results in descending order. Defaults to `True`.
#### id: `str` #### id
The id of the dataset to be got. Defaults to `None`. The ID of the dataset to retrieve. Defaults to `None`.
#### name: `str` #### name
The name of the dataset to be got. Defaults to `None`. The name of the dataset to retrieve. Defaults to `None`.
### Returns ### Returns
```python - Success: A list of `DataSet` objects representing the retrieved knowledge bases.
List[DataSet] - Failure: `Exception`.
description:the list of datasets.
```
### Examples ### Examples
```python #### Retrieve a list of knowledge bases associated with the current user
from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") ```python
for ds in rag.list_datasets(): for ds in rag_object.list_datasets():
print(ds) print(ds.name)
```
#### Retrieve a knowledge base by ID
```python
ds = rag_object.list_datasets(id = "id_1")
print(ds.name)
``` ```
--- ---
## Update knowledge base
## Update knowledge base
```python ```python
DataSet.update(update_message: dict) DataSet.update(update_message: dict)
``` ```
Updates the current knowledge base.
### Parameters
#### update_message
### Returns ### Returns
```python - Success: No value is returned.
no return - Failure: `Exception`
```
### Examples ### Examples
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
ds = rag.get_dataset(name="kb_1") ds = rag.list_datasets(name="kb_1")
ds.update({"parse_method":"manual", ...}} ds.update({"parse_method":"manual", ...}}
``` ```
@ -336,7 +354,7 @@ Duration of the processing in seconds or minutes. Defaults to `0.0`.
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
doc = rag.get_document(id="wdfxb5t547d",name='testdocument.txt') doc = rag.get_document(id="wdfxb5t547d",name='testdocument.txt')
print(doc) print(doc)
``` ```
@ -358,7 +376,7 @@ bool
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
doc = rag.get_document(id="wdfxb5t547d") doc = rag.get_document(id="wdfxb5t547d")
doc.parser_method= "manual" doc.parser_method= "manual"
doc.save() doc.save()
@ -381,7 +399,7 @@ bytes of the document.
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
doc = rag.get_document(id="wdfxb5t547d") doc = rag.get_document(id="wdfxb5t547d")
open("~/ragflow.txt", "w+").write(doc.download()) open("~/ragflow.txt", "w+").write(doc.download())
print(doc) print(doc)
@ -392,7 +410,7 @@ print(doc)
## List documents ## List documents
```python ```python
Dataset.list_docs(keywords: str=None, offset: int=0, limit:int = -1) -> List[Document] Dataset.list_docs(keywords: str=None, offset: int=0, limit:int = -1) -> list[Document]
``` ```
### Parameters ### Parameters
@ -407,18 +425,18 @@ The beginning number of records for paging. Defaults to `0`.
#### limit: `int` #### limit: `int`
Records number to return, -1 means all of them. Records number to return, -1 means all of them. Records number to return, -1 means all of them.
### Returns ### Returns
List[Document] list[Document]
### Examples ### Examples
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
ds = rag.create_dataset(name="kb_1") ds = rag.create_dataset(name="kb_1")
filename1 = "~/ragflow.txt" filename1 = "~/ragflow.txt"
@ -448,7 +466,7 @@ description: delete success or not
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
ds = rag.create_dataset(name="kb_1") ds = rag.create_dataset(name="kb_1")
filename1 = "~/ragflow.txt" filename1 = "~/ragflow.txt"
@ -581,7 +599,7 @@ chunk
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
doc = rag.get_document(id="wdfxb5t547d") doc = rag.get_document(id="wdfxb5t547d")
chunk = doc.add_chunk(content="xxxxxxx") chunk = doc.add_chunk(content="xxxxxxx")
``` ```
@ -603,7 +621,7 @@ bool
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
doc = rag.get_document(id="wdfxb5t547d") doc = rag.get_document(id="wdfxb5t547d")
chunk = doc.add_chunk(content="xxxxxxx") chunk = doc.add_chunk(content="xxxxxxx")
chunk.delete() chunk.delete()
@ -626,7 +644,7 @@ bool
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
doc = rag.get_document(id="wdfxb5t547d") doc = rag.get_document(id="wdfxb5t547d")
chunk = doc.add_chunk(content="xxxxxxx") chunk = doc.add_chunk(content="xxxxxxx")
chunk.content = "sdfx" chunk.content = "sdfx"
@ -638,7 +656,7 @@ chunk.save()
## Retrieval ## Retrieval
```python ```python
RAGFlow.retrieval(question:str, datasets:List[Dataset], document=List[Document]=None, offset:int=0, limit:int=6, similarity_threshold:float=0.1, vector_similarity_weight:float=0.3, top_k:int=1024) -> List[Chunk] RAGFlow.retrieval(question:str, datasets:list[Dataset], document=list[Document]=None, offset:int=0, limit:int=6, similarity_threshold:float=0.1, vector_similarity_weight:float=0.3, top_k:int=1024) -> list[Chunk]
``` ```
### Parameters ### Parameters
@ -647,11 +665,11 @@ RAGFlow.retrieval(question:str, datasets:List[Dataset], document=List[Document]=
The user query or query keywords. Defaults to `""`. The user query or query keywords. Defaults to `""`.
#### datasets: `List[Dataset]`, *Required* #### datasets: `list[Dataset]`, *Required*
The scope of datasets. The scope of datasets.
#### document: `List[Document]` #### document: `list[Document]`
The scope of document. `None` means no limitation. Defaults to `None`. The scope of document. `None` means no limitation. Defaults to `None`.
@ -677,14 +695,14 @@ Number of records engaged in vector cosine computaton. Defaults to `1024`.
### Returns ### Returns
List[Chunk] list[Chunk]
### Examples ### Examples
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
ds = rag.get_dataset(name="ragflow") ds = rag.get_dataset(name="ragflow")
name = 'ragflow_test.txt' name = 'ragflow_test.txt'
path = 'test_data/ragflow_test.txt' path = 'test_data/ragflow_test.txt'
@ -715,7 +733,7 @@ Chat APIs
RAGFlow.create_chat( RAGFlow.create_chat(
name: str = "assistant", name: str = "assistant",
avatar: str = "path", avatar: str = "path",
knowledgebases: List[DataSet] = ["kb1"], knowledgebases: list[DataSet] = ["kb1"],
llm: Chat.LLM = None, llm: Chat.LLM = None,
prompt: Chat.Prompt = None prompt: Chat.Prompt = None
) -> Chat ) -> Chat
@ -736,7 +754,7 @@ The name of the created chat. Defaults to `"assistant"`.
The icon of the created chat. Defaults to `"path"`. The icon of the created chat. Defaults to `"path"`.
#### knowledgebases: `List[DataSet]` #### knowledgebases: `list[DataSet]`
Select knowledgebases associated. Defaults to `["kb1"]`. Select knowledgebases associated. Defaults to `["kb1"]`.
@ -778,7 +796,7 @@ You are an intelligent assistant. Please summarize the content of the knowledge
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
kb = rag.get_dataset(name="kb_1") kb = rag.get_dataset(name="kb_1")
assi = rag.create_chat("Miss R", knowledgebases=[kb]) assi = rag.create_chat("Miss R", knowledgebases=[kb])
``` ```
@ -802,7 +820,7 @@ no return
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
kb = rag.get_knowledgebase(name="kb_1") kb = rag.get_knowledgebase(name="kb_1")
assi = rag.create_chat("Miss R" knowledgebases=[kb]) assi = rag.create_chat("Miss R" knowledgebases=[kb])
assi.update({"temperature":0.8}) assi.update({"temperature":0.8})
@ -813,7 +831,7 @@ assi.update({"temperature":0.8})
## Delete chats ## Delete chats
```python ```python
RAGFlow.delete_chats(ids: List[str] = None) RAGFlow.delete_chats(ids: list[str] = None)
``` ```
### Parameters ### Parameters
@ -833,7 +851,7 @@ no return
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
rag.delete_chats(ids=["id_1","id_2"]) rag.delete_chats(ids=["id_1","id_2"])
``` ```
@ -849,7 +867,7 @@ RAGFlow.list_chats(
desc: bool = True, desc: bool = True,
id: str = None, id: str = None,
name: str = None name: str = None
) -> List[Chat] ) -> list[Chat]
``` ```
### Parameters ### Parameters
@ -892,7 +910,7 @@ A list of chat objects.
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
for assi in rag.list_chats(): for assi in rag.list_chats():
print(assi) print(assi)
``` ```
@ -922,7 +940,7 @@ The id of the created session is used to identify different sessions.
The name of the created session. Defaults to `"New session"`. The name of the created session. Defaults to `"New session"`.
#### messages: `List[Message]` #### messages: `list[Message]`
The messages of the created session. The messages of the created session.
- messages cannot be provided. - messages cannot be provided.
@ -945,7 +963,7 @@ The id of associated chat
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
assi = rag.list_chats(name="Miss R") assi = rag.list_chats(name="Miss R")
assi = assi[0] assi = assi[0]
sess = assi.create_session() sess = assi.create_session()
@ -967,7 +985,7 @@ no return
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
assi = rag.list_chats(name="Miss R") assi = rag.list_chats(name="Miss R")
assi = assi[0] assi = assi[0]
sess = assi.create_session("new_session") sess = assi.create_session("new_session")
@ -1005,7 +1023,7 @@ The id of the message. `id` is automatically generated. Defaults to `None`. ????
The content of the message. Defaults to `"Hi! I am your assistant, can I help you?"`. The content of the message. Defaults to `"Hi! I am your assistant, can I help you?"`.
#### reference: `List[Chunk]` #### reference: `list[Chunk]`
The auto-generated reference of the message. Each `chunk` object includes the following attributes: The auto-generated reference of the message. Each `chunk` object includes the following attributes:
@ -1027,7 +1045,7 @@ The auto-generated reference of the message. Each `chunk` object includes the fo
A similarity score based on vector representations. This score is obtained by converting texts, words, or objects into vectors and then calculating the cosine similarity or other distance measures between these vectors to determine the similarity in vector space. A higher value indicates greater similarity in the vector space. Defaults to `None`. ????????????????????????????????? A similarity score based on vector representations. This score is obtained by converting texts, words, or objects into vectors and then calculating the cosine similarity or other distance measures between these vectors to determine the similarity in vector space. A higher value indicates greater similarity in the vector space. Defaults to `None`. ?????????????????????????????????
- **term_similarity**: `float` - **term_similarity**: `float`
The similarity score based on terms or keywords. This score is calculated by comparing the similarity of key terms between texts or datasets, typically measuring how similar two words or phrases are in meaning or context. A higher value indicates a stronger similarity between terms. Defaults to `None`. ??????????????????? The similarity score based on terms or keywords. This score is calculated by comparing the similarity of key terms between texts or datasets, typically measuring how similar two words or phrases are in meaning or context. A higher value indicates a stronger similarity between terms. Defaults to `None`. ???????????????????
- **position**: `List[string]` - **position**: `list[string]`
Indicates the position or index of keywords or specific terms within the text. An array is typically used to mark the location of keywords or specific elements, facilitating precise operations or analysis of the text. Defaults to `None`. ?????????????? Indicates the position or index of keywords or specific terms within the text. An array is typically used to mark the location of keywords or specific elements, facilitating precise operations or analysis of the text. Defaults to `None`. ??????????????
### Examples ### Examples
@ -1035,7 +1053,7 @@ The auto-generated reference of the message. Each `chunk` object includes the fo
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
assi = rag.list_chats(name="Miss R") assi = rag.list_chats(name="Miss R")
assi = assi[0] assi = assi[0]
sess = assi.create_session() sess = assi.create_session()
@ -1066,12 +1084,12 @@ Chat.list_sessions(
desc: bool = True, desc: bool = True,
id: str = None, id: str = None,
name: str = None name: str = None
) -> List[Session] ) -> list[Session]
``` ```
### Returns ### Returns
List[Session] list[Session]
description: the List contains information about multiple assistant object, with each dictionary containing information about one assistant. description: the List contains information about multiple assistant object, with each dictionary containing information about one assistant.
### Examples ### Examples
@ -1079,7 +1097,7 @@ description: the List contains information about multiple assistant object, with
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
assi = rag.list_chats(name="Miss R") assi = rag.list_chats(name="Miss R")
assi = assi[0] assi = assi[0]
for sess in assi.list_sessions(): for sess in assi.list_sessions():
@ -1122,7 +1140,7 @@ The name of the chat to be retrieved.
## Delete session ## Delete session
```python ```python
Chat.delete_sessions(ids:List[str] = None) Chat.delete_sessions(ids:list[str] = None)
``` ```
### Returns ### Returns
@ -1134,13 +1152,13 @@ no return
```python ```python
from ragflow import RAGFlow from ragflow import RAGFlow
rag = RAGFlow(api_key="xxxxxx", base_url="http://xxx.xx.xx.xxx:9380") rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
assi = rag.list_chats(name="Miss R") assi = rag.list_chats(name="Miss R")
assi = assi[0] assi = assi[0]
assi.delete_sessions(ids=["id_1","id_2"]) assi.delete_sessions(ids=["id_1","id_2"])
``` ```
### Parameters ### Parameters
#### ids: `List[string]` #### ids: `list[string]`
IDs of the sessions to be deleted. IDs of the sessions to be deleted.
- `None` - `None`