#19767·ragflow

[Bug]: Canvas Retrieval use_kg calls kg_retriever twice and duplicates KG chunk

Author: kabishou11Created Sep 17, 2026Updated Sep 17, 2026

Self Checks

  • I have searched for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (Language Policy).
  • Non-english title submissions will be closed directly (Language Policy).
  • Please do not modify this template :) and fill in all the required fields.

RAGFlow workspace code commit ID

main @ 1d9173072

RAGFlow image version

N/A — source-level agent Retrieval tool correctness, reproduced against main

Other environment information

Reproduced by inspecting agent/tools/retrieval.py::_retrieve_kb and AST regression tests under test/unit_test/agent/tools/test_retrieval_use_kg_once.py.

Actual behavior

When a canvas Retrieval tool runs with use_kg=True, _retrieve_kb invokes settings.kg_retriever.retrieval twice:

  1. Inside the if kbs: branch with the unfiltered kb_ids list, inserting the result while it still carries content_with_weight.
  2. Again after that branch with filtered_kb_ids, normalizing content_with_weightcontent, and inserting again.

The formalized prompt / JSON output therefore gets two KG chunks for one query, and graph retrieval pays for a second round-trip. The first call can also see empty / duplicate ids that filtered_kb_ids already dropped. Bot / chunk retrieval APIs only call KG once.

Expected behavior

One kg_retriever.retrieval call using filtered_kb_ids, and a single normalized KG chunk prepended.

Steps to reproduce

1. Configure a canvas Retrieval node with use_kg=True against a dataset that has a knowledge graph.
2. Run a query that returns a non-empty KG chunk.
3. Before the fix: kg_retriever.retrieval fires twice and two KG entries appear at the front of chunks / formalized_content.
4. After the fix: exactly one call, one normalized chunk.

Additional information

Fix PR: #19768.