Repository navigation
Fix: handle id as keyword - #14729
Conversation
📝 WalkthroughWalkthroughThe PR broadens the ChangesMapping + Search Sort Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14729 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
memory/utils/es_conn.py (1)
209-210:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUpdate stale comment to reflect that
idis now a keyword.This comment has the same issue as in
rag/utils/es_conn.py. The comment states "id as 'text', not a 'keyword'", but the PR objective is to treatidas a keyword. Additionally, verify whether thecontinuestatement is still necessary ifidis now properly mapped as a keyword.🤖 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 `@memory/utils/es_conn.py` around lines 209 - 210, The comment and behavior in the branch that checks elif field == "id" need updating: change the comment to state that id is now mapped as a keyword (not text) and therefore safe to sort on, and remove the unconditional continue if sorting/ordering logic expects keyword fields; update the elif field == "id" branch in the function that builds ES sort/field lists (the branch using the local variable field) to either delete the special-case branch entirely or adjust it to allow id through as a keyword, and run the code-path that handles keyword fields so id is treated the same as other keyword fields.
🧹 Nitpick comments (1)
memory/utils/es_conn.py (1)
268-268: ⚡ Quick winConsider updating
unmapped_typeto"keyword"for consistency.The
get_forgotten_messagesandget_missing_field_messagemethods still useunmapped_type: "text"for non-numeric fields, while the mainsearchmethod now uses"keyword". For consistent sorting behavior across all methods, consider applying the same change here.♻️ Proposed fix for consistency
For line 268 in
get_forgotten_messages:else: - order_info = {"order": order, "unmapped_type": "text"} + order_info = {"order": order, "unmapped_type": "keyword"} orders.append({field: order_info})For line 313 in
get_missing_field_message:else: - order_info = {"order": order, "unmapped_type": "text"} + order_info = {"order": order, "unmapped_type": "keyword"} orders.append({field: order_info})Also applies to: 313-313
🤖 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 `@memory/utils/es_conn.py` at line 268, In get_forgotten_messages and get_missing_field_message update the unmapped_type used in the order_info dict from "text" to "keyword" so sorting behavior matches the main search method; locate the order_info assignment (e.g. order_info = {"order": order, "unmapped_type": "text"}) in both functions and change the value to "keyword".
🤖 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/utils/es_conn.py`:
- Around line 247-248: The code currently skips sorting on the id field with
`elif field == "id": continue` and the comment claims id is mapped as "text",
but conf/mapping.json now maps id as a keyword via the "kwd" dynamic template;
update the comment to reflect that id is a keyword and remove or conditionally
guard the `continue` so sorting on `id` is allowed. Specifically, in the block
checking `field == "id"` (and any adjacent sort-handling code), change the
comment to mention the "kwd" dynamic template mapping and either delete the
`continue` or replace it with a runtime check of the index mapping (e.g., only
skip if the field is non-keyword) so keyword id fields can be used for ordering.
Ensure references to the `field` variable, the `elif field == "id"` branch, and
conf/mapping.json's "kwd" pattern are preserved to locate the change.
---
Duplicate comments:
In `@memory/utils/es_conn.py`:
- Around line 209-210: The comment and behavior in the branch that checks elif
field == "id" need updating: change the comment to state that id is now mapped
as a keyword (not text) and therefore safe to sort on, and remove the
unconditional continue if sorting/ordering logic expects keyword fields; update
the elif field == "id" branch in the function that builds ES sort/field lists
(the branch using the local variable field) to either delete the special-case
branch entirely or adjust it to allow id through as a keyword, and run the
code-path that handles keyword fields so id is treated the same as other keyword
fields.
---
Nitpick comments:
In `@memory/utils/es_conn.py`:
- Line 268: In get_forgotten_messages and get_missing_field_message update the
unmapped_type used in the order_info dict from "text" to "keyword" so sorting
behavior matches the main search method; locate the order_info assignment (e.g.
order_info = {"order": order, "unmapped_type": "text"}) in both functions and
change the value to "keyword".
🪄 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: 310edc63-db97-4559-89a1-167cc7368686
📒 Files selected for processing (2)
memory/utils/es_conn.pyrag/utils/es_conn.py
| elif field == "id": | ||
| continue # id as "text", not a "keyword", order by it will cause error |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Check if id is mapped as keyword in the mapping configuration
# Search for the kwd dynamic template and id field mapping
rg -nC5 '"kwd"' conf/mapping.json
rg -nC3 '"id"' conf/mapping.jsonRepository: infiniflow/ragflow
Length of output: 362
Update the stale comment and reconsider the skip logic for id field.
The comment states "id as 'text', not a 'keyword'", but conf/mapping.json now maps id as a keyword field via the "kwd" dynamic template (pattern: ^(.*_(kwd|id|ids|uid|uids)|uid|id)$, type: keyword). Update the comment to reflect this change. Additionally, since id is now a keyword, verify whether the continue statement is still needed—sorting by keyword fields should not cause errors.
🤖 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/utils/es_conn.py` around lines 247 - 248, The code currently skips
sorting on the id field with `elif field == "id": continue` and the comment
claims id is mapped as "text", but conf/mapping.json now maps id as a keyword
via the "kwd" dynamic template; update the comment to reflect that id is a
keyword and remove or conditionally guard the `continue` so sorting on `id` is
allowed. Specifically, in the block checking `field == "id"` (and any adjacent
sort-handling code), change the comment to mention the "kwd" dynamic template
mapping and either delete the `continue` or replace it with a runtime check of
the index mapping (e.g., only skip if the field is non-keyword) so keyword id
fields can be used for ordering. Ensure references to the `field` variable, the
`elif field == "id"` branch, and conf/mapping.json's "kwd" pattern are preserved
to locate the change.
### What problem does this PR solve? Update mapping.json to treat id as a keyword. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
What problem does this PR solve?
Update mapping.json to treat id as a keyword.
Type of change