Skip to content

Conversation

@frederikb96
Copy link
Contributor

Description

This PR adds configurable default values for the infer parameter and custom deduplication prompts in OpenMemory, allowing users to control default behavior system-wide through the Settings UI.

Features:

  • default_infer setting: Controls whether LLM processing (fact extraction & deduplication) is enabled by default when infer parameter is not specified in API/MCP calls
  • custom_update_memory_prompt setting: Allows customizing the deduplication phase prompt (ADD/UPDATE/DELETE/NONE decisions)
  • Comprehensive parameter descriptions: Added detailed descriptions for LLM agents to understand parameter behavior
  • Settings UI: Added intuitive controls in the Settings page for both configuration options

Implementation:

  • REST API and MCP endpoints use Optional[bool] = None pattern for infer parameter
  • Config values loaded from PostgreSQL database and passed to mem0 core
  • Fallback chain: explicit parameter → database config → hardcoded default (True)
  • Proper None-checking to handle False values correctly

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Test Script (please provide)
  • Tested with custom MCP test script that verifies default_infer config behavior
  • Manually tested Settings UI toggles and verified behavior changes
  • Tested both TRUE and FALSE values for default_infer setting
  • Verified custom prompts are properly loaded and applied

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have checked my code and corrected any misspellings

Copy link
Contributor

@parshvadaftari parshvadaftari left a comment

Choose a reason for hiding this comment

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

Can you please incorporate the changes? Thanks!

Implements a configurable default value for the infer parameter across
memory operations, allowing users to control whether LLM processing is
enabled by default.

Configuration:
- Added default_infer field to mem0 MemoryConfig (default: True)
- Added default_infer to OpenMemory API configuration schema
- Configuration UI toggle in settings page under "Default Memory Processing Settings"
- Loaded from database configuration with proper None/False handling

API Changes:
- MCP add_memories: infer parameter now optional (Optional[bool])
- REST create_memory: infer parameter now optional with Field documentation
- When infer=None, applies memory_client.config.default_infer
- Updated tool descriptions to document infer parameter behavior

Behavior:
- infer=True: LLM extracts semantic facts and deduplicates
- infer=False: Stores exact verbatim text without transformation
- infer=None: Uses configured default_infer value (default: True)

This allows users to set their preferred default behavior while still
being able to override on a per-call basis.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@frederikb96 frederikb96 force-pushed the feature/configurable-defaults branch from 5c8134c to 11f3712 Compare October 23, 2025 17:54
The PUT endpoint was missing the critical database save operations.
This bug was introduced in upstream commit 639d26e (PR mem0ai#3583) when
adding the PATCH endpoint - the save/reset/return lines were accidentally
moved from PUT to PATCH instead of being duplicated in both.

Added missing lines to PUT endpoint:
- save_config_to_db(db, updated_config)
- reset_memory_client()
- return updated_config

This ensures config changes (like default_infer toggle) persist when
Save Configuration is clicked in the UI.

Refs: upstream mem0ai/mem0 commit 639d26e
@frederikb96
Copy link
Contributor Author

However, I realized that there was a bug introduced recently in commit 639d26e from @vedant381

In this screenshot, the lines 175-177 on the right side originally belonged to the PUT function. But there was a copy-paste error which led to moving the lines instead of copying them to
the new PATCH function :D

image

I also fixed it with another commit on this branch since this would otherwise break the whole config 🙂 Took me some time to figure that out - it was a difficult diff to read due to how diff showed only new lines introduced 😄

@frederikb96
Copy link
Contributor Author

Here test results:

Keep default toggled on in GUI:

image

And test:

mem0/.claude/tests on  feature/configurable-defaults [$⇕] via 🐍 v3.14.0 (.venv) 
❯ python 01-test-mcp-basic.py 

=== STEP 1: Delete All Memories ===
Result: meta=None content=[TextContent(type='text', text='Successfully deleted all memories', annotations=None, meta=None)] structuredContent={'result': 'Successfully deleted all memories'} isError=False

=== STEP 2: Add Memory ===
Input: The user likes coding and playing chess.

Result:
{
  "results": [
    {
      "id": "d2ee7eba-3e02-440f-a9e1-f9bdce7f9481",
      "memory": "Likes coding",
      "event": "ADD"
    },
    {
      "id": "8496d85f-2243-4cf4-87ff-df0641713bdd",
      "memory": "Likes playing chess",
      "event": "ADD"
    }
  ]
}

=== STEP 3: Search ===
Query: coding

Result:
{
  "results": [
    {
      "id": "d2ee7eba-3e02-440f-a9e1-f9bdce7f9481",
      "memory": "Likes coding",
      "hash": "92852dc8b92358ffee81ce58fbc73578",
      "created_at": "2025-10-23T11:40:55.312652-07:00",
      "updated_at": null,
      "score": 0.50719327
    },
    {
      "id": "8496d85f-2243-4cf4-87ff-df0641713bdd",
      "memory": "Likes playing chess",
      "hash": "c78f844272f9e64847ef334a355a283e",
      "created_at": "2025-10-23T11:40:55.345992-07:00",
      "updated_at": null,
      "score": 0.22972144
    }
  ]
}

Disable toggle:

image

And test:

mem0/.claude/tests on  feature/configurable-defaults [$+⇕] via 🐍 v3.14.0 (.venv) took 15s 
❯ python 01-test-mcp-basic.py 

=== STEP 1: Delete All Memories ===
Result: meta=None content=[TextContent(type='text', text='Successfully deleted all memories', annotations=None, meta=None)] structuredContent={'result': 'Successfully deleted all memories'} isError=False

=== STEP 2: Add Memory ===
Input: The user likes coding and playing chess.

Result:
{
  "results": [
    {
      "id": "413e3134-e8b1-4b5a-8403-f6898b7701d7",
      "memory": "The user likes coding and playing chess.",
      "event": "ADD",
      "actor_id": null,
      "role": "user"
    }
  ]
}

=== STEP 3: Search ===
Query: coding

Result:
{
  "results": [
    {
      "id": "413e3134-e8b1-4b5a-8403-f6898b7701d7",
      "memory": "The user likes coding and playing chess.",
      "hash": "3b5858fa6ab952f234ba78fe62eedf29",
      "created_at": "2025-10-23T11:41:15.415382-07:00",
      "updated_at": null,
      "score": 0.3419581
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants