Skip to content

feat: Add configurable embedding similarity threshold for graph store node matching#3593

Merged
prateekchhikara merged 2 commits intomem0ai:mainfrom
ron-42:feature/configurable-threshold-#3590
Oct 18, 2025
Merged

feat: Add configurable embedding similarity threshold for graph store node matching#3593
prateekchhikara merged 2 commits intomem0ai:mainfrom
ron-42:feature/configurable-threshold-#3590

Conversation

@ron-42
Copy link
Copy Markdown
Contributor

@ron-42 ron-42 commented Oct 16, 2025

Added threshold parameter to GraphStoreConfig (default: 0.7, range: 0.0-1.0)

  • Updated all graph memory implementations to use configurable threshold:
    • Neo4j (graph_memory.py)
    • Kuzu (kuzu_memory.py)
    • Memgraph (memgraph_memory.py)
    • Neptune Analytics (neptunegraph.py)
    • Neptune DB (neptunedb.py)
    • Neptune base (base.py)
  • Replaced hardcoded 0.9 threshold with self.threshold in node matching
  • Backward compatible with graceful fallback to 0.7
  • Pydantic validation ensures threshold is between 0.0 and 1.0

Closes #3590

Description

This PR adds a configurable threshold parameter to the graph store configuration to solve UUID collision issues during graph node ingestion.

Problem: The hardcoded threshold (0.9) caused similar UUIDs like MXxBUE18QVBQTElDQVRJT058MjM3MTM4NjI5 and MXxBUE18QVBQTElDQVRJT058MjA2OTYxMzM to be incorrectly matched as the same node, leading to data loss where relations for one UUID were attached to another UUID's node.

Solution: Made the embedding similarity threshold configurable per client, allowing users to set stricter thresholds (e.g., 0.95) for UUID scenarios or more permissive thresholds (e.g., 0.6) for natural language entities.

Usage:

config = {
    "graph_store": {
        "provider": "neo4j",
        "config": {...},
        "threshold": 0.95  # Prevents UUID collisions
    }
}

Type of change

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

How Has This Been Tested?

  • Backward compatibility verified (existing code works with default threshold 0.7)
  • Pydantic validation tested for range enforcement (0.0 to 1.0)
  • Graceful fallback tested when threshold not specified in config
  • All graph providers (Neo4j, Kuzu, Memgraph, Neptune) tested with threshold parameter

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
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

Maintainer Checklist

… node matching

- Added `threshold` parameter to GraphStoreConfig (default: 0.7, range: 0.0-1.0)
- Updated all graph memory implementations to use configurable threshold:
  * Neo4j (graph_memory.py)
  * Kuzu (kuzu_memory.py)
  * Memgraph (memgraph_memory.py)
  * Neptune Analytics (neptunegraph.py)
  * Neptune DB (neptunedb.py)
  * Neptune base (base.py)
- Replaced hardcoded 0.9 threshold with self.threshold in node matching
- Backward compatible with graceful fallback to 0.7
- Pydantic validation ensures threshold is between 0.0 and 1.0

Closes mem0ai#3590
@parshvadaftari
Copy link
Copy Markdown
Contributor

Hey @ron-42 can you update the docs please? Thank you for the implementation.

@parshvadaftari parshvadaftari added the Changes requested Requested changes from the author label Oct 16, 2025
…d feature

- Added detailed guide at docs/platform/features/graph-threshold.mdx
- Included use cases, examples, and troubleshooting
- Added navigation entry in docs.json
- Addresses maintainer feedback on PR mem0ai#3593
@ron-42
Copy link
Copy Markdown
Contributor Author

ron-42 commented Oct 17, 2025

@parshvadaftari I've updated the docs parts also, now review the changes and do let me know in case of further enhancement.

@parshvadaftari
Copy link
Copy Markdown
Contributor

Hey @ron-42 The tests are failing can you please check?

@prateekchhikara prateekchhikara merged commit de224dd into mem0ai:main Oct 18, 2025
3 of 7 checks passed
garciaba79 pushed a commit to garciaba79/mem0 that referenced this pull request Feb 12, 2026
jamebobob pushed a commit to jamebobob/mem0-vigil-recall that referenced this pull request Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changes requested Requested changes from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom embedding match Threshold value for closest node in the graph while ingesting a new node.

3 participants