common.py


Overview

The common.py file serves as a utility module within the InfiniFlow project, primarily facilitating batch operations related to dataset, document, chunk, chat assistant, and session management through the ragflow_sdk API. It provides high-level helper functions that enable streamlined creation and bulk handling of core entities—such as datasets, documents, chunks, chats, and sessions—thus simplifying common workflows for testing, data ingestion, or initialization tasks.

This module abstracts repetitive operations by wrapping lower-level SDK calls into convenient batch functions, promoting code reuse and improving maintainability of scripts or services that interact with the InfiniFlow knowledge graph and conversational AI components.


Detailed Documentation of Functions

1. batch_create_datasets

def batch_create_datasets(client: RAGFlow, num: int) -> list[DataSet]:
client = RAGFlow(...)
datasets = batch_create_datasets(client, 5)
for ds in datasets:
    print(ds.name)

2. bulk_upload_documents

def bulk_upload_documents(dataset: DataSet, num: int, tmp_path: Path) -> list[Document]:
from pathlib import Path

tmp_dir = Path("/tmp")
uploaded_docs = bulk_upload_documents(dataset, 3, tmp_dir)
for doc in uploaded_docs:
    print(doc.display_name)

3. batch_add_chunks

def batch_add_chunks(document: Document, num: int) -> list[Chunk]:
chunks = batch_add_chunks(document, 10)
for chunk in chunks:
    print(chunk.content)

4. batch_create_chat_assistants

def batch_create_chat_assistants(client: RAGFlow, num: int) -> list[Chat]:
chat_assistants = batch_create_chat_assistants(client, 4)
for chat in chat_assistants:
    print(chat.name)

5. batch_add_sessions_with_chat_assistant

def batch_add_sessions_with_chat_assistant(chat_assistant: Chat, num) -> list[Session]:
sessions = batch_add_sessions_with_chat_assistant(chat_assistant, 5)
for session in sessions:
    print(session.name)

Important Implementation Details and Algorithms


Interactions with Other System Components


Visual Diagram: Function Flowchart

flowchart TD
    A[RAGFlow Client] -->|batch_create_datasets| B[DataSet List]
    B -->|bulk_upload_documents| C[Document List]
    C -->|batch_add_chunks| D[Chunk List]
    A -->|batch_create_chat_assistants| E[Chat List]
    E -->|batch_add_sessions_with_chat_assistant| F[Session List]
    subgraph File Utilities
        G[create_txt_file]
    end
    G -->|creates text files| H[Temporary Files]
    H -->|read as blobs| C

Explanation:


Summary

The common.py file provides essential batch utility functions for managing datasets, documents, chunks, chats, and sessions within the InfiniFlow ecosystem via the ragflow_sdk. It simplifies bulk operations through straightforward APIs and temporary file handling, supporting efficient data onboarding and testing workflows. This module plays a key role in accelerating development and deployment processes by abstracting common repetitive tasks into reusable functions.