Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix: The document-level graph search box is not displaying correctly. (#20899)

balibabuecfe88f3e958
diff --git a/internal/service/dataset_structure_graph.go b/internal/service/dataset_structure_graph.go
index 2bc558e3e0..32f4782d7c 100644
--- a/internal/service/dataset_structure_graph.go
+++ b/internal/service/dataset_structure_graph.go
@@ -643,6 +643,19 @@ func compilationTemplateKind(kind string) string {
return k
}
+// templateDisplayKind prefers the compilation template's own kind for the
+// response, falling back to the kind keywords stored on the entity rows. The
+// stored row keyword canonicalizes to "graph" (CanonicalCompilationKind)
+// while the normal-mode bucket answers the template kind ("knowledge_graph"),
+// which is the dialect the frontend renderer keys off — a keyword no-match
+// shell built with the row kind flips the UI to "unsupported representation".
+func templateDisplayKind(rowKind, templateKind string) string {
+ if templateKind != "" {
+ return templateKind
+ }
+ return rowKind
+}
+
// ErrInvalidStructureKind is returned when the request kind does not resolve to a
// supported dataset-structure kind. Handlers use errors.Is to map it to
// CodeArgumentError (400) while treating every other service error as a server
@@ -918,9 +931,7 @@ func (s *DatasetArtifactService) discoverDocumentGraphTemplateMeta(ctx context.C
if !strings.HasPrefix(templateID, "legacy:") {
if template, loadErr := templateDAO.GetTemplate(ctx, dao.DB, tenantID, templateID); loadErr == nil && template != nil {
templateName = template.Name
- if kind == "" {
- kind = template.Kind
- }
+ kind = templateDisplayKind(kind, template.Kind)
}
} else {
templateName = "Legacy (" + strings.TrimPrefix(templateID, "legacy:") + ")"
diff --git a/internal/service/dataset_structure_graph_test.go b/internal/service/dataset_structure_graph_test.go
index 3c6a58cf6e..2bacc420bc 100644
--- a/internal/service/dataset_structure_graph_test.go
+++ b/internal/service/dataset_structure_graph_test.go
@@ -142,6 +142,19 @@ func TestBuildDocumentGraphTemplateShells_PreservesTemplateMetadata(t *testing.T
}
}
+// TestTemplateDisplayKind_PrefersTemplateRow locks the shells-path kind rule:
+// the template row's kind wins over the canonical stored keyword ("graph"),
+// so keyword no-match shells answer in the same dialect as the normal-mode
+// bucket ("knowledge_graph") and the frontend keeps recognizing the template.
+func TestTemplateDisplayKind_PrefersTemplateRow(t *testing.T) {
+ if got := templateDisplayKind("graph", "knowledge_graph"); got != "knowledge_graph" {
+ t.Errorf("templateDisplayKind(graph, knowledge_graph) = %q, want knowledge_graph", got)
+ }
+ if got := templateDisplayKind("graph", ""); got != "graph" {
+ t.Errorf("templateDisplayKind(graph, \"\") = %q, want row-kind fallback graph", got)
+ }
+}
+
// TestStructureRowSourceOrder_MinChunkOrder verifies a row's source position is
// the smallest chunk_order_int among its source_chunk_ids, and that a row with
// no resolvable chunks reports ok=false (so it sorts to the end).
diff --git a/web/src/pages/chunk/representation/hooks/use-graph-entity-search.test.ts b/web/src/pages/chunk/representation/hooks/use-graph-entity-search.test.ts
index fb4c3c5d61..cdca57db35 100644
--- a/web/src/pages/chunk/representation/hooks/use-graph-entity-search.test.ts
+++ b/web/src/pages/chunk/representation/hooks/use-graph-entity-search.test.ts
@@ -127,3 +127,69 @@ describe('useGraphEntitySearch handleSelectEntity', () => {
expect(mockFetchDocumentStructureGraph).toHaveBeenLastCalledWith('');
});
});
+
+describe('useGraphEntitySearch keyword channel sync', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ jest.useFakeTimers();
+ });
+
+ afterEach(() => {
+ jest.useRealTimers();
+ });
+
+ // Repro: Enter a keyword with no match (graphKeywords='sun'), then type an
+ // existing entity into the expandable search input that takes over when the
+ // result kind is not a graph. The select must show the keyword that actually
+ // drives the current subgraph, not the stale failed one.
+ it('shows the expandable-input keyword that drives the fetch, not the stale graph keyword', () => {
+ const { result } = setupHook([{ id: 'e1', name: 'swallow' }]);
+
+ act(() => {
+ result.current.handleNoMatchEnter('sun');
+ });
+ expect(result.current.graphSelectValue).toBe('sun');
+
+ // The debounce timer is scheduled by an effect after the state-change
+ // render, so the keystroke and the timer advance need separate acts.
+ act(() => {
+ result.current.handleSearchKeywordChange('乾坤');
+ });
+ act(() => {
+ jest.advanceTimersByTime(500);
+ });
+
+ expect(mockFetchDocumentStructureGraph).toHaveBeenLastCalledWith('乾坤');
+ expect(result.current.graphSelectValue).toBe('乾坤');
+ });
+
+ // The two keyword sources must stay mutually exclusive: after an
+ // expandable-input search, picking an entity has to re-arm the fetch with
+ // the entity name instead of staying shadowed by the old searchKeyword.
+ it('picking an entity re-arms the fetch with the entity name after an expandable-input search', () => {
+ const { result } = setupHook([
+ { id: 'e1', name: 'swallow' },
+ { id: 'e2', name: '乾坤' },
+ ]);
+
+ act(() => {
+ result.current.handleSearchKeywordChange('乾坤');
+ });
+ act(() => {
+ jest.advanceTimersByTime(500);
+ });
+ expect(mockFetchDocumentStructureGraph).toHaveBeenLastCalledWith('乾坤');
+
+ act(() => {
+ result.current.handleSelectEntity('swallow');
+ });
+ // The cleared searchKeyword flushes through its debounce before the
+ // graph keyword drives the fetch again.
+ act(() => {
+ jest.advanceTimersByTime(500);
+ });
+
+ expect(mockFetchDocumentStructureGraph).toHaveBeenLastCalledWith('swallow');
+ expect(result.current.graphSelectValue).toBe('swallow');
+ });
+});
diff --git a/web/src/pages/chunk/representation/hooks/use-graph-entity-search.ts b/web/src/pages/chunk/representation/hooks/use-graph-entity-search.ts
index 5356cff247..345b4e8f31 100644
--- a/web/src/pages/chunk/representation/hooks/use-graph-entity-search.ts
+++ b/web/src/pages/chunk/representation/hooks/use-graph-entity-search.ts
@@ -69,6 +69,7 @@ export function useGraphEntitySearch(
}
setSelectedNodeId(name);
setGraphKeywords(name);
+ setSearchKeyword('');
const entity = (selectedTemplate?.entities ?? []).find(
(item) => getEntityDisplayName(item) === name,
);
@@ -139,7 +140,13 @@ export function useGraphEntitySearch(
isGraphKind,
entityOptions,
searchKeyword,
- graphSelectValue: selectedEntityName || graphKeywords,
+ // Mirror the fetch driver (debouncedSearchKeyword || graphKeywords): the
+ // two keyword inputs swap whenever the result kind flips isGraphKind, so
+ // when the expandable-input channel drove the current subgraph, show its
+ // keyword — not a stale graph keyword left behind by an earlier failed
+ // Enter search.
+ graphSelectValue:
+ selectedEntityName || debouncedSearchKeyword || graphKeywords,
highlightNodeId: selectedEntityName || null,
handleSelectEntity,
handleNoMatchEnter,