dataset_example.py

Overview

dataset_example.py is a simple example script demonstrating CRUD (Create, Read, Update, Delete) operations on a dataset using the RAGFlow SDK. It showcases how to instantiate the RAGFlow client, create a dataset, update its properties, list or print the dataset details, and finally delete the dataset. This example is intended to illustrate the basic usage pattern of the RAGFlow SDK’s dataset management capabilities.


Detailed Explanation

Imports and Constants


Main Flow

The script is wrapped in a try-except block to handle exceptions gracefully.

1. Creating a RAGFlow instance

ragflow_instance = RAGFlow(api_key=API_KEY, base_url=HOST_ADDRESS)

2. Creating a Dataset

dataset_instance = ragflow_instance.create_dataset(name="dataset_instance")

3. Updating the Dataset

updated_message = {"name": "updated_dataset"}
updated_dataset = dataset_instance.update(updated_message)

4. Reading (Printing) Dataset Information

print(dataset_instance)
print(updated_dataset)

5. Deleting the Dataset

to_be_deleted_datasets = [dataset_instance.id]
ragflow_instance.delete_datasets(ids=to_be_deleted_datasets)

6. Exit Handling


Important Implementation Details


Interaction with Other Parts of the System


Usage Example

Run the script directly after setting proper HOST_ADDRESS and API_KEY values:

python dataset_example.py

Expected output (simplified):

<Dataset object at 0x... with name 'dataset_instance'>
<Dataset object at 0x... with name 'updated_dataset'>
test done

If any error occurs (e.g., network or authentication failure), the error message will be printed and the script will exit with code -1.


Mermaid Class Diagram

The following diagram represents the structure and main interactions in this file. The primary classes involved are RAGFlow and the dataset object returned by create_dataset().

classDiagram
    class RAGFlow {
        +__init__(api_key: str, base_url: str)
        +create_dataset(name: str) Dataset
        +delete_datasets(ids: list)
    }

    class Dataset {
        +id: str
        +name: str
        +update(update_fields: dict) Dataset
        +__str__()
    }

    RAGFlow --o Dataset : creates
    Dataset --> Dataset : update()

Summary

The dataset_example.py file is a straightforward demonstration of how to perform CRUD operations on datasets using the RAGFlow SDK. It is ideal for developers who want to understand the basic API usage patterns for managing datasets in the InfiniFlow ecosystem. The clean, stepwise operations with exception handling make it a good starting point for integration or testing purposes.