diff --git a/lightrag_webui/src/api/lightrag.ts b/lightrag_webui/src/api/lightrag.ts index 3dbf52e9..5a68851c 100644 --- a/lightrag_webui/src/api/lightrag.ts +++ b/lightrag_webui/src/api/lightrag.ts @@ -221,9 +221,9 @@ axiosInstance.interceptors.response.use( export const queryGraphs = async ( label: string, maxDepth: number, - minDegree: number + maxNodes: number ): Promise => { - const response = await axiosInstance.get(`/graphs?label=${encodeURIComponent(label)}&max_depth=${maxDepth}&min_degree=${minDegree}`) + const response = await axiosInstance.get(`/graphs?label=${encodeURIComponent(label)}&max_depth=${maxDepth}&max_nodes=${maxNodes}`) return response.data } diff --git a/lightrag_webui/src/components/graph/Settings.tsx b/lightrag_webui/src/components/graph/Settings.tsx index 1989a01e..f8b0e6cd 100644 --- a/lightrag_webui/src/components/graph/Settings.tsx +++ b/lightrag_webui/src/components/graph/Settings.tsx @@ -121,7 +121,7 @@ export default function Settings() { const enableHideUnselectedEdges = useSettingsStore.use.enableHideUnselectedEdges() const showEdgeLabel = useSettingsStore.use.showEdgeLabel() const graphQueryMaxDepth = useSettingsStore.use.graphQueryMaxDepth() - const graphMinDegree = useSettingsStore.use.graphMinDegree() + const graphMaxNodes = useSettingsStore.use.graphMaxNodes() const graphLayoutMaxIterations = useSettingsStore.use.graphLayoutMaxIterations() const enableHealthCheck = useSettingsStore.use.enableHealthCheck() @@ -180,15 +180,14 @@ export default function Settings() { }, 300) }, []) - const setGraphMinDegree = useCallback((degree: number) => { - if (degree < 0) return - useSettingsStore.setState({ graphMinDegree: degree }) + const setGraphMaxNodes = useCallback((nodes: number) => { + if (nodes < 1 || nodes > 1000) return + useSettingsStore.setState({ graphMaxNodes: nodes }) const currentLabel = useSettingsStore.getState().queryLabel useSettingsStore.getState().setQueryLabel('') setTimeout(() => { useSettingsStore.getState().setQueryLabel(currentLabel) }, 300) - }, []) const setGraphLayoutMaxIterations = useCallback((iterations: number) => { @@ -277,10 +276,11 @@ export default function Settings() { onEditFinished={setGraphQueryMaxDepth} /> { const { t } = useTranslation() const graphQueryMaxDepth = useSettingsStore.use.graphQueryMaxDepth() - const graphMinDegree = useSettingsStore.use.graphMinDegree() + const graphMaxNodes = useSettingsStore.use.graphMaxNodes() return (
{t('graphPanel.sideBar.settings.depth')}: {graphQueryMaxDepth}
-
{t('graphPanel.sideBar.settings.degree')}: {graphMinDegree}
+
{t('graphPanel.sideBar.settings.maxNodes')}: {graphMaxNodes}
) } diff --git a/lightrag_webui/src/hooks/useLightragGraph.tsx b/lightrag_webui/src/hooks/useLightragGraph.tsx index 2ee28749..fde463b7 100644 --- a/lightrag_webui/src/hooks/useLightragGraph.tsx +++ b/lightrag_webui/src/hooks/useLightragGraph.tsx @@ -70,7 +70,7 @@ export type NodeType = { } export type EdgeType = { label: string } -const fetchGraph = async (label: string, maxDepth: number, minDegree: number) => { +const fetchGraph = async (label: string, maxDepth: number, maxNodes: number) => { let rawData: any = null; // Check if we need to fetch all database labels first @@ -89,8 +89,8 @@ const fetchGraph = async (label: string, maxDepth: number, minDegree: number) => const queryLabel = label || '*'; try { - console.log(`Fetching graph label: ${queryLabel}, depth: ${maxDepth}, deg: ${minDegree}`); - rawData = await queryGraphs(queryLabel, maxDepth, minDegree); + console.log(`Fetching graph label: ${queryLabel}, depth: ${maxDepth}, nodes: ${maxNodes}`); + rawData = await queryGraphs(queryLabel, maxDepth, maxNodes); } catch (e) { useBackendState.getState().setErrorMessage(errorMessage(e), 'Query Graphs Error!'); return null; @@ -218,7 +218,7 @@ const useLightrangeGraph = () => { const rawGraph = useGraphStore.use.rawGraph() const sigmaGraph = useGraphStore.use.sigmaGraph() const maxQueryDepth = useSettingsStore.use.graphQueryMaxDepth() - const minDegree = useSettingsStore.use.graphMinDegree() + const maxNodes = useSettingsStore.use.graphMaxNodes() const isFetching = useGraphStore.use.isFetching() const nodeToExpand = useGraphStore.use.nodeToExpand() const nodeToPrune = useGraphStore.use.nodeToPrune() @@ -292,14 +292,14 @@ const useLightrangeGraph = () => { // Use a local copy of the parameters const currentQueryLabel = queryLabel const currentMaxQueryDepth = maxQueryDepth - const currentMinDegree = minDegree + const currentMaxNodes = maxNodes // Declare a variable to store data promise let dataPromise; // 1. If query label is not empty, use fetchGraph if (currentQueryLabel) { - dataPromise = fetchGraph(currentQueryLabel, currentMaxQueryDepth, currentMinDegree); + dataPromise = fetchGraph(currentQueryLabel, currentMaxQueryDepth, currentMaxNodes); } else { // 2. If query label is empty, set data to null console.log('Query label is empty, show empty graph') @@ -384,7 +384,7 @@ const useLightrangeGraph = () => { state.setLastSuccessfulQueryLabel('') // Clear last successful query label on error }) } - }, [queryLabel, maxQueryDepth, minDegree, isFetching, t]) + }, [queryLabel, maxQueryDepth, maxNodes, isFetching, t]) // Handle node expansion useEffect(() => { @@ -407,7 +407,7 @@ const useLightrangeGraph = () => { } // Fetch the extended subgraph with depth 2 - const extendedGraph = await queryGraphs(label, 2, 0); + const extendedGraph = await queryGraphs(label, 2, 1000); if (!extendedGraph || !extendedGraph.nodes || !extendedGraph.edges) { console.error('Failed to fetch extended graph'); diff --git a/lightrag_webui/src/locales/ar.json b/lightrag_webui/src/locales/ar.json index c67fbbb3..d3affb90 100644 --- a/lightrag_webui/src/locales/ar.json +++ b/lightrag_webui/src/locales/ar.json @@ -148,7 +148,7 @@ "hideUnselectedEdges": "إخفاء الحواف غير المحددة", "edgeEvents": "أحداث الحافة", "maxQueryDepth": "أقصى عمق للاستعلام", - "minDegree": "الدرجة الدنيا", + "maxNodes": "الحد الأقصى للعقد", "maxLayoutIterations": "أقصى تكرارات التخطيط", "depth": "العمق", "degree": "الدرجة", diff --git a/lightrag_webui/src/locales/en.json b/lightrag_webui/src/locales/en.json index 6fcb3558..a00cfc75 100644 --- a/lightrag_webui/src/locales/en.json +++ b/lightrag_webui/src/locales/en.json @@ -148,7 +148,7 @@ "hideUnselectedEdges": "Hide Unselected Edges", "edgeEvents": "Edge Events", "maxQueryDepth": "Max Query Depth", - "minDegree": "Minimum Degree", + "maxNodes": "Max Nodes", "maxLayoutIterations": "Max Layout Iterations", "depth": "Depth", "degree": "Degree", diff --git a/lightrag_webui/src/locales/fr.json b/lightrag_webui/src/locales/fr.json index 88cad3ae..c7f538dc 100644 --- a/lightrag_webui/src/locales/fr.json +++ b/lightrag_webui/src/locales/fr.json @@ -148,7 +148,7 @@ "hideUnselectedEdges": "Masquer les arêtes non sélectionnées", "edgeEvents": "Événements des arêtes", "maxQueryDepth": "Profondeur maximale de la requête", - "minDegree": "Degré minimum", + "maxNodes": "Nombre maximum de nœuds", "maxLayoutIterations": "Itérations maximales de mise en page", "depth": "Profondeur", "degree": "Degré", diff --git a/lightrag_webui/src/locales/zh.json b/lightrag_webui/src/locales/zh.json index 8e596f83..073d1253 100644 --- a/lightrag_webui/src/locales/zh.json +++ b/lightrag_webui/src/locales/zh.json @@ -148,7 +148,7 @@ "hideUnselectedEdges": "隐藏未选中的边", "edgeEvents": "边事件", "maxQueryDepth": "最大查询深度", - "minDegree": "最小邻边数", + "maxNodes": "最大返回节点数", "maxLayoutIterations": "最大布局迭代次数", "depth": "深度", "degree": "邻边", diff --git a/lightrag_webui/src/stores/settings.ts b/lightrag_webui/src/stores/settings.ts index 311e5061..4f037f78 100644 --- a/lightrag_webui/src/stores/settings.ts +++ b/lightrag_webui/src/stores/settings.ts @@ -27,8 +27,8 @@ interface SettingsState { graphQueryMaxDepth: number setGraphQueryMaxDepth: (depth: number) => void - graphMinDegree: number - setGraphMinDegree: (degree: number) => void + graphMaxNodes: number + setGraphMaxNodes: (nodes: number) => void graphLayoutMaxIterations: number setGraphLayoutMaxIterations: (iterations: number) => void @@ -77,7 +77,7 @@ const useSettingsStoreBase = create()( enableEdgeEvents: false, graphQueryMaxDepth: 3, - graphMinDegree: 0, + graphMaxNodes: 1000, graphLayoutMaxIterations: 15, queryLabel: defaultQueryLabel, @@ -130,7 +130,7 @@ const useSettingsStoreBase = create()( setGraphQueryMaxDepth: (depth: number) => set({ graphQueryMaxDepth: depth }), - setGraphMinDegree: (degree: number) => set({ graphMinDegree: degree }), + setGraphMaxNodes: (nodes: number) => set({ graphMaxNodes: nodes }), setEnableHealthCheck: (enable: boolean) => set({ enableHealthCheck: enable }), @@ -150,7 +150,7 @@ const useSettingsStoreBase = create()( { name: 'settings-storage', storage: createJSONStorage(() => localStorage), - version: 9, + version: 10, migrate: (state: any, version: number) => { if (version < 2) { state.showEdgeLabel = false @@ -196,6 +196,10 @@ const useSettingsStoreBase = create()( if (version < 9) { state.showFileName = false } + if (version < 10) { + delete state.graphMinDegree // 删除废弃参数 + state.graphMaxNodes = 1000 // 添加新参数 + } return state } }