Skip to content

fix: Restrict the agent to using memory compatible with the embedding model. - #16699

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:fix/agent-memory-0707
Jul 7, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:fix/agent-memory-0707

Conversation

@dcc123456

Copy link
Copy Markdown
Collaborator

Summary

fix: Restrict the agent to using memory compatible with the embedding model.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 7, 2026
@dcc123456
dcc123456 requested a review from wangq8 July 7, 2026 08:21
@dcc123456 dcc123456 added the ci Continue Integration label Jul 7, 2026
@dcc123456
dcc123456 marked this pull request as draft July 7, 2026 08:22
@dcc123456
dcc123456 marked this pull request as ready for review July 7, 2026 08:22
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The IMemory interface adds required embd_id and llm_id string fields. memories-form-field.tsx introduces an exported hook useDisableDifferenceEmbeddingMemory that watches selected memory ids and disables options with mismatched embedding ids; MemoriesFormField now accepts an optional name prop.

Changes

Memory selection embedding constraint

Layer / File(s) Summary
IMemory interface fields
web/src/interfaces/database/memory.ts
Adds embd_id and llm_id string properties to the IMemory interface.
Embedding-aware option hook and form field wiring
web/src/components/memories-form-field.tsx
Adds useDisableDifferenceEmbeddingMemory to compute options with avatars and embd_id labels and disable mismatched options; updates MemoriesFormField to accept an optional name prop (default 'memory_ids') and use the hook's options with MultiSelect.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MemoriesFormField
  participant useDisableDifferenceEmbeddingMemory
  participant useFetchAllMemoryList
  participant MultiSelect

  MemoriesFormField->>useDisableDifferenceEmbeddingMemory: call with name
  useDisableDifferenceEmbeddingMemory->>useFetchAllMemoryList: fetch memories
  useFetchAllMemoryList-->>useDisableDifferenceEmbeddingMemory: memory list
  useDisableDifferenceEmbeddingMemory->>useDisableDifferenceEmbeddingMemory: read selected memoryIds via useWatch
  useDisableDifferenceEmbeddingMemory->>useDisableDifferenceEmbeddingMemory: compute options with disabled state
  useDisableDifferenceEmbeddingMemory-->>MemoriesFormField: options
  MemoriesFormField->>MultiSelect: render with options
Loading

Poem

A rabbit hops through fields of memory,
Sorting embd_ids so cheerfully,
Options grey when they don't match,
One embedding wins the batch! 🐰
Hop, hop, form field, all aligned and free.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The Summary section is present, but it lacks the background context requested by the template. Add 1-2 sentences explaining the problem or user impact that motivated restricting memory use to embedding-compatible memories.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly matches the change: limiting memory selection to embedding-compatible items.

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: 1

🧹 Nitpick comments (1)
web/src/components/memories-form-field.tsx (1)

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

Side effect (ref mutation) inside useMemo.

Populating memoryCacheRef.current (lines 30-32) inside a useMemo factory mutates a ref as part of the render phase, which violates React's pure-render expectations, even though the mutation is currently idempotent. Consider moving the cache population into a useEffect keyed on memoryListOrigin.

♻️ Suggested refactor
+  useEffect(() => {
+    memoryListOrigin?.forEach((memory) => {
+      memoryCacheRef.current.set(memory.id, memory);
+    });
+  }, [memoryListOrigin]);
+
   const memoryList = useMemo(() => {
-    memoryListOrigin?.forEach((memory) => {
-      memoryCacheRef.current.set(memory.id, memory);
-    });
-
     const selectedIds = Array.isArray(memoryIds) ? memoryIds : [];
🤖 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 `@web/src/components/memories-form-field.tsx` around lines 29 - 47, The memory
cache population inside `memoryList` is mutating `memoryCacheRef.current` during
`useMemo`, which should stay pure. Move the `memoryCacheRef.current.set(...)`
logic out of the `useMemo` factory and into a `useEffect` that runs when
`memoryListOrigin` changes, then keep `useMemo` only for deriving the merged
memory list from `memoryIds`, `memoryListOrigin`, and the cache.
🤖 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 `@web/src/components/memories-form-field.tsx`:
- Around line 54-73: The `options` memo in `memories-form-field.tsx` is
disabling already-selected memories when their `embd_id` differs from
`selectedEmbedId`, which makes legacy incompatible selections impossible to
remove in `MultiSelect`. Update the `disabled` logic so only unselected items
with mismatched `embd_id` are disabled, while existing selected values remain
removable; use the `options` mapping and the `selectedEmbedId`/`memoryList`
checks to locate the fix.

---

Nitpick comments:
In `@web/src/components/memories-form-field.tsx`:
- Around line 29-47: The memory cache population inside `memoryList` is mutating
`memoryCacheRef.current` during `useMemo`, which should stay pure. Move the
`memoryCacheRef.current.set(...)` logic out of the `useMemo` factory and into a
`useEffect` that runs when `memoryListOrigin` changes, then keep `useMemo` only
for deriving the merged memory list from `memoryIds`, `memoryListOrigin`, and
the cache.
🪄 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: f483dd19-7138-4e15-804e-7bc1894aac94

📥 Commits

Reviewing files that changed from the base of the PR and between 9eba452 and a406715.

📒 Files selected for processing (2)
  • web/src/components/memories-form-field.tsx
  • web/src/interfaces/database/memory.ts

Comment on lines +54 to +73
const options = useMemo(() => {
return memoryList
.filter(Boolean)
.map((item: IMemory) => {
return {
label: item.name,
icon: () => (
<RAGFlowAvatar
className="size-4"
avatar={item.avatar ?? ''}
name={item.name}
/>
),
suffix: <MemoryLabel text={item.embd_id} />,
value: item.id,
disabled:
item.embd_id !== selectedEmbedId && selectedEmbedId !== '',
};
});
}, [memoryList, selectedEmbedId]);

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 | 🏗️ Heavy lift

Already-selected mismatched memories become permanently stuck (cannot be removed).

disabled is computed over memoryList, which merges memoryListOrigin with selectedMemories (line 34-46). This means any already-selected memory whose embd_id differs from memoryIds?.[0] (the anchor) is also flagged disabled: true. Per the MultiSelect implementation (web/src/components/ui/multi-select.tsx), disabled option values are excluded from toggleOption, backspace removal, and clearExtraOptions/handleClear preservation logic — so a user who has legacy or pre-existing selections with mixed embd_ids (e.g., data saved before this restriction existed) will be unable to deselect the incompatible ones via the UI. This directly undermines the PR's goal of restricting memory to embedding-compatible options, since users get trapped with unremovable incompatible selections instead of being guided to fix them.

Consider excluding already-selected ids from the disabled computation (only disable unselected options with mismatched embd_id), so users can still remove existing mismatched selections.

🤖 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 `@web/src/components/memories-form-field.tsx` around lines 54 - 73, The
`options` memo in `memories-form-field.tsx` is disabling already-selected
memories when their `embd_id` differs from `selectedEmbedId`, which makes legacy
incompatible selections impossible to remove in `MultiSelect`. Update the
`disabled` logic so only unselected items with mismatched `embd_id` are
disabled, while existing selected values remain removable; use the `options`
mapping and the `selectedEmbedId`/`memoryList` checks to locate the fix.

@wangq8
wangq8 merged commit dd2f27d into infiniflow:main Jul 7, 2026
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants