Implementation:Infiniflow Ragflow GenerateButtonHook
| Knowledge Sources | |
|---|---|
| Domains | Frontend, Knowledge_Base |
| Last Updated | 2026-02-12 06:00 GMT |
Overview
Polling hooks with task lifecycle management for Knowledge Graph and Raptor generation operations.
Description
This module exports three hooks. useTraceGenerate polls two endpoints (traceGraphRag and traceRaptor) at 5-second intervals when tasks are running (progress between 0 and 1), using React Query's refetchInterval. It auto-starts/stops polling based on progress values via useEffect. useUnBindTask provides a mutation to cancel pipeline tasks via deletePipelineTask. useDatasetGenerate orchestrates generation by calling kbService.runGraphRag or kbService.runRaptor based on GenerateType, invalidating related queries on success, and providing pauseGenerate which chains cancelDataflow and handleUnbindTask together.
Usage
Consumed by the generate button component on the dataset page to start, monitor, and cancel Knowledge Graph and Raptor generation tasks.
Code Reference
Source Location
- Repository: Infiniflow_Ragflow
- File: web/src/pages/dataset/dataset/generate-button/hook.ts
- Lines: 1-179
Signature
export const useTraceGenerate = ({ open }: { open: boolean }) => {
graphRunData, graphRunloading, raptorRunData, raptorRunloading,
};
export const useUnBindTask = () => { handleUnbindTask };
export const useDatasetGenerate = () => {
runGenerate, pauseGenerate, data, loading,
};
Import
import { useTraceGenerate, useDatasetGenerate } from './hook';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| open | boolean | Yes (useTraceGenerate) | Whether the generate panel is open (enables polling) |
| type | GenerateType | Yes (useDatasetGenerate) | KnowledgeGraph or Raptor |
Outputs
| Name | Type | Description |
|---|---|---|
| graphRunData | ITraceInfo | Current graph generation task status |
| raptorRunData | ITraceInfo | Current raptor generation task status |
| runGenerate | function | Start a generation task |
| pauseGenerate | function | Cancel a running generation task |
Usage Examples
const { runGenerate, pauseGenerate } = useDatasetGenerate();
const { graphRunData, raptorRunData } = useTraceGenerate({ open: panelOpen });
// Start generation
await runGenerate({ type: GenerateType.KnowledgeGraph });