Replies: 1 comment 1 reply
|
The proposed Service API endpoints for creating and updating documents (by text or file, with streaming support) in Pipeline Knowledge Bases are not yet implemented in the Dify codebase—they remain in the planning stage and are tracked in issue #31524. Currently, the available pipeline-related endpoints are Authentication for these endpoints typically requires a user-scoped API token with appropriate permissions; using a dataset token will result in errors source. The technical rationale for the proposed endpoints is sound: separating pipeline document APIs from vendor KB APIs, using RESTful conventions (POST for create, PATCH for update), and ensuring all document operations run through the pipeline workflow ( For now, keep an eye on issue #31524 for updates, and use the existing endpoints with the above limitations in mind. If you need guaranteed pipeline execution (especially with custom extractors), use the Web UI until these new endpoints are available. To reply, just mention @dosu. Docs are dead. Just use Dosu. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Self Checks
Pipeline Knowledge Base Service API Implementation Documentation
1. Background and Requirements
1.1 Requirements
Add the following Service API endpoint support for Pipeline Knowledge Bases:
Data Preparation Endpoints (do NOT execute workflow):
PipelineGenerateService.generate()Unified Endpoints (instead of separate text/file endpoints):
POST /v1/datasets/<dataset_id>/pipeline/documents- Prepare data for document creationPATCH /v1/datasets/<dataset_id>/pipeline/documents/<document_id>- Prepare data for document updateUsers execute workflow separately:
POST /v1/datasets/<dataset_id>/pipeline/runendpoint with prepared dataPipelineGenerateService.generate()directly2. Technical Analysis
Correct Approach:
PipelineGenerateService.generate()or/pipeline/runendpoint separately2.3 Pipeline Workflow Document Processing Flow
2.4 How Pipeline Handles
online_documentDatasource TypeWhen pipeline runs with
online_documentdatasource type, the processing flow is:Key Points:
credential_idto authenticate with the online document service3. Implementation Plan
3.1 Design Decision
Create new endpoints instead of modifying existing ones
Reasons:
/datasets/<id>/pipeline/...path3.2 API Endpoint Design
Unified Data Preparation Endpoints (do NOT execute workflow):
Create Endpoint:
Update Endpoint:
Key Design Points:
PipelineGenerateService.generate()start_node_idis optional)online_documentvslocal_file, etc.) is obtained fromnode_data.provider_typenode_data.provider_nameandnode_data.plugin_idstart_node_idparameterlocal_fileandwebsite_crawl: Returnsdatasource_info_listonline_documentandonline_drive: Returns document list (datasource_info_list), users need to select before execution3.3 File Organization
4. Implementation Details
4.1 Core Implementation Logic
4.1.1 Data Preparation Flow (No Execution)
4.2 Key Function Implementations
4.2.1 Pipeline Knowledge Base Validation
4.2.2 Get First Datasource Node ID
4.2.3 Get Datasource Type from Node
4.2.4 Get Default Credential ID
4.2.5 Get Online Document List
4.2.6 Build Datasource Info List
5. Complete API Usage Examples
5.1 Create Document with Local File Upload
Step 1: Prepare Data (does NOT execute workflow)
Request:
Note:
start_node_idis optional. If not provided, the system will automatically select the first datasource node in the workflow.Response:
{ "start_node_id": "node_123", "datasource_type": "local_file", "datasource_info_list": [ { "related_id": "file_550e8400-e29b-41d4-a716-446655440001", "name": "document.pdf", "type": "document", "size": 102400, "extension": "pdf", "mime_type": "application/pdf", "url": "", "transfer_method": "local_file" } ] }Step 2: Execute Workflow (user calls separately)
5.2 Create Document with Text Content
Step 1: Prepare Data
Request:
Note:
start_node_idis optional. If not provided, the system will automatically select the first datasource node in the workflow.Response:
{ "start_node_id": "node_123", "datasource_type": "local_file", "datasource_info_list": [ { "related_id": "file_550e8400-e29b-41d4-a716-446655440002", "name": "text_document.txt", "type": "text", "size": 512, "extension": "txt", "mime_type": "text/plain", "url": "", "transfer_method": "local_file" } ] }Step 2: Execute Workflow (same as Step 2 in 5.1)
5.3 Create Document with Online Document (Notion)
Step 1: Get Document List
Request:
Or specify a specific datasource node (if pipeline has multiple datasource nodes):
Response:
{ "start_node_id": "node_456", "datasource_type": "online_document", "datasource_info_list": [ { "workspace_id": "workspace_123", "workspace_name": "My Notion Workspace", "workspace_icon": "https://...", "pages": [ { "page_id": "page_456", "page_name": "My Notion Page 1", "type": "page", "parent_id": "parent_789", "page_icon": null, "is_bound": false }, { "page_id": "page_789", "page_name": "My Notion Page 2", "type": "page", "parent_id": "parent_789", "page_icon": null, "is_bound": false } ], "credential_id": "cred_default_123" } ] }Note:
credential_idis automatically injected by the systemdatasource_info_list(document list), does NOT containpipeline_run_argsStep 2: User Selects Documents and Executes Workflow
User selects documents from the document list returned in Step 1, then calls
/pipeline/run:5.4 Create Document with Website Crawl
Step 1: Prepare Data
Request:
Response:
{ "start_node_id": "node_789", "datasource_type": "website_crawl", "datasource_info_list": [ { "source_url": "https://example.com/page", "credential_id": "cred_default_456" } ] }Step 2: Execute Workflow (using returned data)
5.5 Update Document
Step 1: Prepare Data
Request:
Note:
start_node_idis optional. If not provided, the system will automatically select the first datasource node in the workflow.Response:
{ "start_node_id": "node_123", "datasource_type": "local_file", "datasource_info_list": [ { "related_id": "file_550e8400-e29b-41d4-a716-446655440003", "name": "updated_document.pdf", "type": "document", "size": 204800, "extension": "pdf", "mime_type": "application/pdf", "url": "", "transfer_method": "local_file" } ] }Step 2: Execute Workflow (using returned data with
original_document_id)6. Important Considerations
6.1 Key Design Principles
PipelineGenerateService.generate()local_fileandwebsite_crawl: Returnsdatasource_info_listready for executiononline_documentandonline_drive: Returns document list (datasource_info_list), users need to select documents before executioncredential_idfrom datasource node default credentialdatasource_info_list, file upload, or text input/pipeline/runorPipelineGenerateService.generate()with prepared data6.2 Critical Limitations
start_node_idprovided, otherwise uses first)/pipeline/runendpoint orPipelineGenerateService.generate()to execute workflow6.3 Error Handling
start_node_idis not a datasource node, return errordatasource_info_listfor non-local_file types6.4 Performance Considerations
6.5 Compatibility
/pipeline/run,/pipeline/datasource/nodes/...)/pipeline/runendpoint for workflow execution7. Implementation Steps
7.1 Create New File
Create
api/controllers/service_api/dataset/rag_pipeline/rag_pipeline_document.py7.2 Implement Endpoints
PipelineDocumentCreateApi.post()- Prepare data for document creation (POST, supports JSON and multipart/form-data)PipelineDocumentUpdateApi.patch()- Prepare data for document update (PATCH, supports JSON and multipart/form-data)_get_first_datasource_node_id()- Automatically get first datasource node ID_get_datasource_type_from_node()- Get datasource type from start_node_id_get_default_credential_id()- Get default credential from datasource node_get_online_document_list()- Get document list for online documents (Notion, Google Drive)_build_datasource_info_list()- Build datasource_info_list with automatic credential injection7.3 Register Endpoints
Import new module in
api/controllers/service_api/dataset/rag_pipeline/__init__.py7.4 Testing
online_documentandonline_drivedocument list retrieval functionality/pipeline/run)All reactions