Skip to content

Feat: Add graph keyword search and fix dataset synthesizing issue. - #17342

Merged
yingfeng merged 5 commits into
infiniflow:mainfrom
KevinHuSh:feat/agentic_search5
Jul 24, 2026
Merged

yingfeng merged 5 commits into
infiniflow:mainfrom
KevinHuSh:feat/agentic_search5

Conversation

@KevinHuSh

Copy link
Copy Markdown
Contributor

Summary

Add graph keyword search and fix dataset synthesizing issue.

@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jul 24, 2026
@KevinHuSh KevinHuSh added the ci Continue Integration label Jul 24, 2026
@KevinHuSh
KevinHuSh marked this pull request as draft July 24, 2026 07:36
@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8e0f32c4-8372-47a8-a017-eff97b4048e5

📥 Commits

Reviewing files that changed from the base of the PR and between a0b8c54 and 0608c75.

📒 Files selected for processing (1)
  • api/apps/services/dataset_api_service.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/apps/services/dataset_api_service.py

📝 Walkthrough

Walkthrough

The pull request adds shared structure-graph sampling and keyword retrieval for document and dataset APIs, extends artifact graph query controls, corrects description-field handling across graph pipelines, and changes fallback or eligibility behavior in several components.

Changes

Structure graph retrieval

Layer / File(s) Summary
Graph sampling foundation
api/apps/services/structure_graph_common.py, rag/advanced_rag/knowlege_compile/structure.py, conf/infinity_mapping.json
Adds graph projection, deduplication, relation filtering, bucket sampling, keyword subgraphs, and searchable entity metadata.
Dataset structure retrieval
api/apps/services/dataset_api_service.py, api/apps/restful_apis/dataset_api.py
Adds keyword-focused dataset structures, sampled template buckets, legacy fallback handling, and updated task mappings.
Document structure graph retrieval
api/apps/restful_apis/chunk_api.py
Adds keyword mode, metadata-only bucket discovery, sampled buckets, and separate RAPTOR graph handling.
Artifact graph controls
api/apps/services/dataset_api_service.py, api/apps/restful_apis/dataset_api.py
Adds keyword-based overview selection, bounded top_n overrides, and relation-connected entity filtering.

Description field corrections

Layer / File(s) Summary
Description field production
rag/advanced_rag/knowlege_compile/structure.py, rag/advanced_rag/knowlege_compile/wiki.py
Uses description for compiled and merged entities and generated schema prompts.
Description field consumption
rag/advanced_rag/harness/tools/navigation.py, rag/advanced_rag/knowlege_compile/runner.py
Reads the corrected description field in navigation, parsed entities, and graph summaries.

Independent behavior fixes

Layer / File(s) Summary
Runtime and template behavior
agent/component/llm.py, rag/flow/compiler/compiler.py, rag/svr/task_executor_refactor/dataset_structure_merger.py
Adds LLM initialization fallback, removes base compiler validation, and treats resolved templates as dataset-merge templates.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant StructureAPI
  participant DatasetService
  participant GraphCommon
  participant DocumentStore
  Client->>StructureAPI: Request structure graph with keywords
  StructureAPI->>DatasetService: Forward keywords and graph options
  DatasetService->>GraphCommon: Request keyword_subgraph or build_bucket
  GraphCommon->>DocumentStore: Search entities and relations
  DocumentStore-->>GraphCommon: Return projected graph rows
  GraphCommon-->>DatasetService: Return focused or sampled subgraph
  DatasetService-->>StructureAPI: Assemble graph buckets
  StructureAPI-->>Client: Return structure graph
Loading

Suggested labels: 🐞 bug

Poem

I’m a rabbit with graphs in my den,
Sampling nodes again and again.
Keywords hop, relations gleam,
Descriptions spell out the dream.
Buckets tidy, errors light—
Maps grow clear beneath moonlight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: graph keyword search plus dataset synthesizing fixes.
Description check ✅ Passed The description includes the required Summary section and clearly states the PR's purpose.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@KevinHuSh
KevinHuSh marked this pull request as ready for review July 24, 2026 07:37
@dosubot dosubot Bot added 🌈 python Pull requests that update Python code 💞 feature Feature request, pull request that fullfill a new feature. labels Jul 24, 2026
@yingfeng yingfeng added ci Continue Integration and removed ci Continue Integration labels Jul 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
rag/advanced_rag/harness/tools/navigation.py (1)

540-540: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Simplify the duplicated description lookups.

Both expressions repeat the corrected field access and provide no fallback:

  • rag/advanced_rag/harness/tools/navigation.py#L540-L540: replace the duplicated lookup with payload.get("description").
  • rag/advanced_rag/knowlege_compile/runner.py#L170-L170: replace the duplicated lookup with entity.get("description").

As per coding guidelines, prefer deletion of duplicate code and compatibility-only surfaces.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/advanced_rag/harness/tools/navigation.py` at line 540, Remove the
duplicated description lookups: in rag/advanced_rag/harness/tools/navigation.py
at line 540, use a single payload.get("description") access; apply the
corresponding change in rag/advanced_rag/knowlege_compile/runner.py at line 170
using entity.get("description").

Source: Coding guidelines

rag/advanced_rag/knowlege_compile/structure.py (1)

448-448: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant duplicate lookup on Line 448. payload.get("description") or payload.get("description") evaluates the same key twice. This is a leftover from the discription→description rename; confirm no second fallback field was intended, then collapse to a single term.

♻️ Proposed cleanup
-    description = payload.get("description") or payload.get("description") or payload.get("definition_excerpt") or ""
+    description = payload.get("description") or payload.get("definition_excerpt") or ""
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/advanced_rag/knowlege_compile/structure.py` at line 448, Update the
description fallback assignment in the payload-processing logic to look up the
"description" key only once, then preserve the existing fallback to
"definition_excerpt" and the empty-string default; confirm no alternate field is
required before removing the duplicate lookup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@agent/component/llm.py`:
- Around line 91-98: Update the model-resolution flow that initializes
self.chat_mdl so failures use the component’s established error/default-output
path and return immediately instead of leaving chat_mdl as None. Ensure
_prepare_prompt_variables() cannot proceed to access chat_mdl.max_length or
bundle methods after resolution failure. Narrow the exception handling to only
expected model/configuration errors, allowing programming errors to propagate.

In `@api/apps/restful_apis/dataset_api.py`:
- Around line 667-673: Update the top_n_arg assignment in the request parameter
parsing to remove the fallback value 6, preserving only the top_n and topN
lookups so omitted input remains None. Keep the existing top_n conversion and
guard unchanged, allowing dataset_api_service.get_wiki_graph to apply its
documented default budget of 128.

In `@rag/svr/task_executor_refactor/dataset_structure_merger.py`:
- Around line 166-167: Remove the stale commented-out config assignment and
trailing commented expression beside dataset_merge in the dataset merge
eligibility logic, leaving only the active dataset_merge behavior.
- Around line 166-167: Update the structure-merge eligibility in
run_structure_merge() to read the persisted template config and set
dataset_merge from config["dataset_merge"], defaulting to false when config is
missing, non-dict, or the key is absent. Ensure templates without an enabled
dataset_merge flag are not treated as dataset-wide artifact graphs.

---

Nitpick comments:
In `@rag/advanced_rag/harness/tools/navigation.py`:
- Line 540: Remove the duplicated description lookups: in
rag/advanced_rag/harness/tools/navigation.py at line 540, use a single
payload.get("description") access; apply the corresponding change in
rag/advanced_rag/knowlege_compile/runner.py at line 170 using
entity.get("description").

In `@rag/advanced_rag/knowlege_compile/structure.py`:
- Line 448: Update the description fallback assignment in the payload-processing
logic to look up the "description" key only once, then preserve the existing
fallback to "definition_excerpt" and the empty-string default; confirm no
alternate field is required before removing the duplicate lookup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 15e9c44f-8e42-4b8f-a447-57447fe0c2fb

📥 Commits

Reviewing files that changed from the base of the PR and between bd355de and 9ae067f.

📒 Files selected for processing (12)
  • agent/component/llm.py
  • api/apps/restful_apis/chunk_api.py
  • api/apps/restful_apis/dataset_api.py
  • api/apps/services/dataset_api_service.py
  • api/apps/services/structure_graph_common.py
  • conf/infinity_mapping.json
  • rag/advanced_rag/harness/tools/navigation.py
  • rag/advanced_rag/knowlege_compile/runner.py
  • rag/advanced_rag/knowlege_compile/structure.py
  • rag/advanced_rag/knowlege_compile/wiki.py
  • rag/flow/compiler/compiler.py
  • rag/svr/task_executor_refactor/dataset_structure_merger.py
💤 Files with no reviewable changes (1)
  • rag/flow/compiler/compiler.py

Comment thread agent/component/llm.py
Comment on lines +91 to +98
try:
model_types = resolve_model_type(self._canvas.get_tenant_id(), self._param.llm_id)
model_type = "chat" if "chat" in model_types else model_types[0]
chat_model_config = resolve_model_config(self._canvas.get_tenant_id(), model_type, self._param.llm_id)
self.chat_mdl = LLMBundle(self._canvas.get_tenant_id(), chat_model_config, max_retries=self._param.max_retries, retry_interval=self._param.delay_after_error)
except Exception as e:
logging.warning(f"Fail to load LLM configuration for component. {e}")
self.chat_mdl = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== candidate files =="
git ls-files | rg '(^|/)agent/component/llm\.py$|api/db/services/dialog_service\.py$' || true

echo
echo "== agent/component/llm.py outline =="
ast-grep outline agent/component/llm.py || true

echo
echo "== relevant llm.py sections =="
wc -l agent/component/llm.py
sed -n '1,240p' agent/component/llm.py

echo
echo "== dialog_service relevant lines =="
wc -l api/db/services/dialog_service.py
sed -n '1880,1960p' api/db/services/dialog_service.py

Repository: infiniflow/ragflow

Length of output: 13645


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== rest of relevant llm.py sections =="
sed -n '240,528p' agent/component/llm.py

echo
echo "== direct chat_mdl usages in agent/component/llm.py =="
rg -n "self\.chat_mdl|chat_mdl" agent/component/llm.py

echo
echo "== inspect llm_service LLMBundle definition =="
fd -a 'llm_service\.py$' . | while read -r f; do
  echo "--- $f"
  wc -l "$f"
  rg -n "class LLMBundle|def (bind_tools|async_chat_streamly_delta|chat|__init__|_.*chat|chat_with_retrieval)" "$f" -C 4
done
sed -n '1,340p' api/db/services/llm_service.py

Repository: infiniflow/ragflow

Length of output: 31619


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== api/db/services/tenant_llm_service.py relevant section =="
sed -n '500,535p' api/db/services/tenant_llm_service.py
wc -l api/db/services/tenant_llm_service.py

echo
echo "== broader dialog_service chat_mdl usages =="
rg -n "chat_mdl|bind_tools\(|\.bind_tools\(" api/db/services/dialog_service.py -C 3

Repository: infiniflow/ragflow

Length of output: 14565


Do not continue with chat_mdl=None.

When model resolution fails, _prepare_prompt_variables() keeps self.chat_mdl as None for text-only requests, but the component later reads self.chat_mdl.max_length and calls bundle methods directly. Set the output via the component’s normal error/default-output path before returning, and narrow the bare except Exception so programming errors are not swallowed.

🧰 Tools
🪛 Ruff (0.15.21)

[warning] 96-96: Do not catch blind exception: Exception

(BLE001)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@agent/component/llm.py` around lines 91 - 98, Update the model-resolution
flow that initializes self.chat_mdl so failures use the component’s established
error/default-output path and return immediately instead of leaving chat_mdl as
None. Ensure _prepare_prompt_variables() cannot proceed to access
chat_mdl.max_length or bundle methods after resolution failure. Narrow the
exception handling to only expected model/configuration errors, allowing
programming errors to propagate.

Source: Linters/SAST tools

Comment thread api/apps/restful_apis/dataset_api.py Resolved
Comment on lines +166 to +167
# config = saved.get("config") or {}
dataset_merge = True # bool(config.get("dataset_merge")) if isinstance(config, dict) else False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the commented-out implementation.

Delete the stale config assignment and trailing commented expression once the eligibility contract is decided.

As per coding guidelines, **/*: Remove dead tests, commented-out code, stale documentation, and “move later” notes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/svr/task_executor_refactor/dataset_structure_merger.py` around lines 166
- 167, Remove the stale commented-out config assignment and trailing commented
expression beside dataset_merge in the dataset merge eligibility logic, leaving
only the active dataset_merge behavior.

Source: Coding guidelines


🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

rg -n -C 3 '\bdataset_merge\b' --glob '*.py' .

Repository: infiniflow/ragflow

Length of output: 3426


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
git ls-files | rg '(^|/)dataset_structure_merger\.py$|(^|/)runner\.py$|(^|/)dataset_api\.py$' || true

echo
echo "== dataset_structure_merger.py outline =="
ast-grep outline rag/svr/task_executor_refactor/dataset_structure_merger.py --view expanded || true

echo
echo "== relevant dataset_structure_merger.py lines =="
sed -n '1,230p' rag/svr/task_executor_refactor/dataset_structure_merger.py | cat -n

echo
echo "== relevant runner.py lines =="
sed -n '240,330p' rag/advanced_rag/knowlege_compile/runner.py | cat -n

echo
echo "== dataset_api references =="
sed -n '660,720p' api/apps/restful_apis/dataset_api.py | cat -n

echo
echo "== dataset_merge occurrences =="
rg -n -C 2 '\bdataset_merge\b' --glob '*.py' .

Repository: infiniflow/ragflow

Length of output: 21298


Use config["dataset_merge"] for structure-merge eligibility.

run_structure_merge() now accepts every matching template, so templates whose persisted config["dataset_merge"] is false or absent are still rebuilt as dataset-wide artifact graphs. Restore the persisted flag from the template config, or update the per-document compile path to the same rule if dataset-wide merge is intentional.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/svr/task_executor_refactor/dataset_structure_merger.py` around lines 166
- 167, Update the structure-merge eligibility in run_structure_merge() to read
the persisted template config and set dataset_merge from
config["dataset_merge"], defaulting to false when config is missing, non-dict,
or the key is absent. Ensure templates without an enabled dataset_merge flag are
not treated as dataset-wide artifact graphs.

@yingfeng yingfeng added ci Continue Integration and removed ci Continue Integration labels Jul 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
api/apps/services/dataset_api_service.py (1)

1798-1939: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add observability for the new retrieval flows.

Please log branch selection, template-discovery counts, keyword no-match/fallback outcomes, legacy-row recovery, and top_n overrides without logging raw keyword values. As per coding guidelines: **/*.py: Add logging for new flows.

Also applies to: 2960-3002, 3084-3351

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/apps/services/dataset_api_service.py` around lines 1798 - 1939, Add
structured logging to the get_dataset_structure retrieval flow covering branch
selection, discovered template counts, keyword no-match and fallback outcomes,
legacy-row recovery, and any top_n overrides. Place logs around the keyword and
normal branches plus template-less recovery, and include dataset/context
identifiers and counts without logging raw keyword values. Apply the same
observability to the related retrieval flows in the additional ranges.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@api/apps/services/dataset_api_service.py`:
- Around line 1798-1939: Add structured logging to the get_dataset_structure
retrieval flow covering branch selection, discovered template counts, keyword
no-match and fallback outcomes, legacy-row recovery, and any top_n overrides.
Place logs around the keyword and normal branches plus template-less recovery,
and include dataset/context identifiers and counts without logging raw keyword
values. Apply the same observability to the related retrieval flows in the
additional ranges.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b692a0bf-64b3-432b-8251-52c27aab72c2

📥 Commits

Reviewing files that changed from the base of the PR and between 5028307 and a0b8c54.

📒 Files selected for processing (2)
  • api/apps/services/dataset_api_service.py
  • conf/infinity_mapping.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • conf/infinity_mapping.json

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (cd9db94) to head (0608c75).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17342   +/-   ##
=======================================
  Coverage   90.65%   90.65%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          650      650           
  Misses         39       39           
  Partials       28       28           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yingfeng
yingfeng merged commit 742837c into infiniflow:main Jul 24, 2026
3 of 6 checks passed
huang-aoqin added a commit to tecpie/ragflow that referenced this pull request Sep 4, 2026
infiniflow#17342 remapped public index types to structure_* merge tasks, so GraphRAG
finished instantly with no entities. Keep structure_graph/structure_mindmap
as separate merge entrypoints.

Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. 🌈 python Pull requests that update Python code size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants