Skip to content

Fix compilation workflow - #16819

Merged
yingfeng merged 6 commits into
infiniflow:mainfrom
yingfeng:fixnav
Jul 10, 2026
Merged

yingfeng merged 6 commits into
infiniflow:mainfrom
yingfeng:fixnav

Conversation

@yingfeng

Copy link
Copy Markdown
Member

Dataset_nav can not support large number of documents, introducing AHC clustering as well as retrieval engine as the clustering database

@dosubot dosubot Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jul 10, 2026
@yingfeng yingfeng added the ci Continue Integration label Jul 10, 2026
@yingfeng
yingfeng marked this pull request as draft July 10, 2026 11:07
@yingfeng
yingfeng marked this pull request as ready for review July 10, 2026 11:07
@coderabbitai

coderabbitai Bot commented Jul 10, 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

Run ID: 07a973a2-129a-45ef-b073-0c07dd8754f0

📥 Commits

Reviewing files that changed from the base of the PR and between aa8d1cf and 3a7b1fa.

📒 Files selected for processing (1)
  • rag/advanced_rag/knowlege_compile/dataset_nav.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • rag/advanced_rag/knowlege_compile/dataset_nav.py

📝 Walkthrough

Walkthrough

The dataset navigation compiler now stores documents in hierarchical nav_doc and nav_cluster rows, using embeddings for clustering, splitting oversized clusters, and cascading deletions through empty ancestors.

Changes

Dataset navigation hierarchy

Layer / File(s) Summary
Navigation schema and row construction
conf/infinity_mapping.json, rag/advanced_rag/knowlege_compile/dataset_nav.py
Adds parent_kwd mapping support, navigation row builders, stable identifiers, document-store helpers, tokenized fields, and optional embedding vectors.
Clustered document upsert
rag/advanced_rag/knowlege_compile/dataset_nav.py
Extracts summaries, skips empty or unchanged documents, performs layered KNN descent, merges or creates clusters, writes hierarchy metadata, and triggers cluster splitting.
Removal and cluster splitting
rag/advanced_rag/knowlege_compile/dataset_nav.py
Deletes navigation documents, removes empty parent clusters recursively, partitions oversized clusters, and updates child ancestry and depth.ател

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

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant upsert_dataset_nav_doc
  participant embd_mdl
  participant RedisDistributedLock
  participant docStoreConn
  Caller->>upsert_dataset_nav_doc: provide document summary
  upsert_dataset_nav_doc->>embd_mdl: encode summary
  upsert_dataset_nav_doc->>RedisDistributedLock: acquire tenant lock
  upsert_dataset_nav_doc->>docStoreConn: search cluster hierarchy
  upsert_dataset_nav_doc->>docStoreConn: upsert nav_cluster and nav_doc
  upsert_dataset_nav_doc->>docStoreConn: split cluster when thresholds are exceeded
Loading

Poem

I’m a rabbit with a map in my paws,
Clusters bloom without pause.
Roots reach down, leaves align,
Embeddings draw every line.
Empty branches fade from view—
Hop, hop, the tree stays new! 🐇

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title is unrelated to the change; the PR is about Dataset_nav clustering, not compilation workflow. Rename it to describe the main change, e.g. "Add clustering-based navigation for Dataset_nav".
Description check ⚠️ Warning The description is too brief and misses the required Summary heading and background context from the template. Add a "### Summary" section and briefly explain the problem, the clustering/retrieval changes, and why they were needed.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
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.

@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: 5

🤖 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 `@rag/advanced_rag/knowlege_compile/dataset_nav.py`:
- Around line 561-566: In the lock acquisition handling around
lock.spin_acquire(), do not continue into the clustering upsert when acquisition
fails. After logging the exception, return from the enclosing operation or
re-raise the exception so the write block executes only after the distributed
lock is successfully acquired.
- Around line 435-437: Update the best-candidate advancement logic near
best_name and sim so best_parent is read from the same child node being
selected, rather than from the stale best node; ensure parent_for_new receives
the child’s parent_kwd and remains synchronized with best_name.
- Around line 899-901: In both loops around the child-row lookups, stop
inferring row type from the `kn` string or its `navc_` prefix. Use the
already-fetched `type_kwd` value to distinguish `nav_doc` from cluster rows,
then call `_nav_doc_id` for document rows and `_nav_cluster_id` for cluster rows
before `_es_get`.
- Around line 630-643: In the new-cluster creation logic, update the
_make_nav_cluster_row call to pass new_depth instead of depth_of_parent so the
cluster depth reflects its child position; also remove the redundant conditional
vector assignment using _vec_field.

In `@test/unit_test/rag/advanced_rag/knowlege_compile/test_dataset_nav.py`:
- Around line 308-310: Rename the ids_stable test method to test_ids_stable so
pytest collects and executes the assertions for _nav_doc_id and _nav_cluster_id.
🪄 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

Run ID: 78b1f269-b5c7-4357-9df9-3f2774e4a86d

📥 Commits

Reviewing files that changed from the base of the PR and between 2a83ad6 and 54c7649.

📒 Files selected for processing (3)
  • conf/infinity_mapping.json
  • rag/advanced_rag/knowlege_compile/dataset_nav.py
  • test/unit_test/rag/advanced_rag/knowlege_compile/test_dataset_nav.py

Comment on lines +435 to +437
best_name = child.get("name", best_name)
best_parent = best.get("parent_kwd", best_parent)
sim = child_sim

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="rag/advanced_rag/knowlege_compile/dataset_nav.py"

# Show the relevant area with line numbers
sed -n '380,480p' "$file" | cat -n

# Find the surrounding function and any uses of best_parent / parent_for_new
rg -n -C 4 "best_parent|parent_for_new|parent_kwd|best_name|child_sim|sim = child_sim" "$file"

# Print a slightly larger context around the suspect block
python3 - <<'PY'
from pathlib import Path
path = Path("rag/advanced_rag/knowlege_compile/dataset_nav.py")
lines = path.read_text().splitlines()
for i in range(400, 460):
    if i <= len(lines):
        print(f"{i:4d}: {lines[i-1]}")
PY

Repository: infiniflow/ragflow

Length of output: 14699


best_parent needs to advance with best_name. In rag/advanced_rag/knowlege_compile/dataset_nav.py:435-437, best.get("parent_kwd") still reads the old node, so once best moves to child, best_parent becomes the grandparent. That sends parent_for_new to the wrong cluster.

🤖 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/dataset_nav.py` around lines 435 - 437,
Update the best-candidate advancement logic near best_name and sim so
best_parent is read from the same child node being selected, rather than from
the stale best node; ensure parent_for_new receives the child’s parent_kwd and
remains synchronized with best_name.

Comment on lines +630 to +643
new_depth = depth_of_parent + 1
new_name = f"navc_{xxhash.xxh64(summary.encode()).hexdigest()[:12]}"
new_desc = await _llm_create_summary(chat_mdl, [summary])
new_cluster = _make_nav_cluster_row(
kb_id,
new_name,
new_desc,
parent_for_new,
depth_of_parent,
[doc_id],
doc_embedding,
)
if embd_mdl and doc_embedding:
new_cluster[_vec_field(len(doc_embedding))] = doc_embedding

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

file='rag/advanced_rag/knowlege_compile/dataset_nav.py'

echo '--- lines 560-690 ---'
sed -n '560,690p' "$file" | cat -n

echo '--- _make_nav_cluster_row definition ---'
rg -n "def _make_nav_cluster_row|_make_nav_cluster_row\(" "$file" -n -A 40 -B 20

echo '--- _vec_field definition ---'
rg -n "def _vec_field|_vec_field\(" "$file" -n -A 20 -B 10

echo '--- depth assignments around branch names ---'
rg -n "new_depth|depth_of_parent|nav_doc|merge branch|root branch|parent_for_new" "$file" -n -A 8 -B 8

Repository: infiniflow/ragflow

Length of output: 35931


🏁 Script executed:

#!/bin/bash
set -euo pipefail
file='rag/advanced_rag/knowlege_compile/dataset_nav.py'
sed -n '340,420p' "$file" | cat -n
echo '---'
sed -n '600,670p' "$file" | cat -n

Repository: infiniflow/ragflow

Length of output: 6100


Use new_depth for the new cluster. The cluster is created under parent_for_new, so its depth_int should be new_depth; otherwise the cluster and its nav_doc end up at the same depth. The extra vector assignment is redundant and can be removed.

🤖 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/dataset_nav.py` around lines 630 - 643, In
the new-cluster creation logic, update the _make_nav_cluster_row call to pass
new_depth instead of depth_of_parent so the cluster depth reflects its child
position; also remove the redundant conditional vector assignment using
_vec_field.

Comment on lines +308 to +310
def ids_stable(self, nav):
assert nav._nav_doc_id("x") == nav._nav_doc_id("x")
assert nav._nav_cluster_id("kb", "c") == nav._nav_cluster_id("kb", "c")

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

ids_stable is never collected — missing test_ prefix.

pytest only collects functions prefixed with test_, so ids_stable silently never runs and the ID-stability guarantee is untested.

💚 Proposed fix
-    def ids_stable(self, nav):
+    def test_ids_stable(self, nav):
         assert nav._nav_doc_id("x") == nav._nav_doc_id("x")
         assert nav._nav_cluster_id("kb", "c") == nav._nav_cluster_id("kb", "c")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def ids_stable(self, nav):
assert nav._nav_doc_id("x") == nav._nav_doc_id("x")
assert nav._nav_cluster_id("kb", "c") == nav._nav_cluster_id("kb", "c")
def test_ids_stable(self, nav):
assert nav._nav_doc_id("x") == nav._nav_doc_id("x")
assert nav._nav_cluster_id("kb", "c") == nav._nav_cluster_id("kb", "c")
🤖 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 `@test/unit_test/rag/advanced_rag/knowlege_compile/test_dataset_nav.py` around
lines 308 - 310, Rename the ids_stable test method to test_ids_stable so pytest
collects and executes the assertions for _nav_doc_id and _nav_cluster_id.

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rag/advanced_rag/knowlege_compile/dataset_nav.py (1)

900-918: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Split needs to rewrite the parent row and recurse descendant depths

  • Clear or recompute cluster_name’s doc_ids_kwd/doc_count_int after reparenting; the current row still reflects the pre-split membership.
  • Propagate depth_int to nested nav_cluster descendants too; the update here only adjusts the immediate children.
🤖 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/dataset_nav.py` around lines 900 - 918, The
split logic around _make_nav_cluster_row and the child reparenting loop must
update the parent cluster after membership changes and recursively adjust
descendant depths. Recompute cluster_name’s doc_ids_kwd and doc_count_int from
its final children (or clear them if appropriate), persist the revised parent
row, and traverse nested nav_cluster descendants to set each depth_int relative
to the new parent before upserting them.
🤖 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.

Outside diff comments:
In `@rag/advanced_rag/knowlege_compile/dataset_nav.py`:
- Around line 900-918: The split logic around _make_nav_cluster_row and the
child reparenting loop must update the parent cluster after membership changes
and recursively adjust descendant depths. Recompute cluster_name’s doc_ids_kwd
and doc_count_int from its final children (or clear them if appropriate),
persist the revised parent row, and traverse nested nav_cluster descendants to
set each depth_int relative to the new parent before upserting them.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e347da78-f4d7-49c2-960d-69464216d4f4

📥 Commits

Reviewing files that changed from the base of the PR and between 54c7649 and aa8d1cf.

📒 Files selected for processing (1)
  • rag/advanced_rag/knowlege_compile/dataset_nav.py

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (eca8e87) to head (3a7b1fa).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16819   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ 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 30739b7 into infiniflow:main Jul 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant