Skip to content

Index uid and timestamp properties#1000

Merged
sscargal merged 1 commit into
MemMachine:mainfrom
edwinyyyu:index_important_properties
Apr 7, 2026
Merged

Index uid and timestamp properties#1000
sscargal merged 1 commit into
MemMachine:mainfrom
edwinyyyu:index_important_properties

Conversation

@edwinyyyu

Copy link
Copy Markdown
Contributor

Purpose of the change

Properties that are used often are not being indexed.

Description

Index Episode uid and timestamp. Node/Edge uid was already indexed.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g., code style improvements, linting)
  • Documentation update
  • Project Maintenance (updates to build scripts, CI, etc., that do not affect the main project)
  • Security (improves security without changing functionality)

How Has This Been Tested?

  • Unit Test
  • Integration Test
  • End-to-end Test
  • Test Script (please provide)
  • Manual verification (list step-by-step instructions)

Checklist

  • I have signed the commit(s) within this pull request
  • My code follows the style guidelines of this project (See STYLE_GUIDE.md)
  • I have performed a self-review of my own code
  • I have commented my code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • Confirmed all checks passed
  • Contributor has signed the commit(s)
  • Reviewed the code
  • Run, Tested, and Verified the change(s) work as expected

@edwinyyyu edwinyyyu marked this pull request as ready for review February 23, 2026 23:49
@edwinyyyu edwinyyyu requested a review from malatewang February 23, 2026 23:49
@edwinyyyu edwinyyyu requested review from jealous and o-love February 27, 2026 18:44
@sscargal sscargal self-requested a review April 6, 2026 21:46
@sscargal sscargal added the performance Issues relating to MemMachine performance label Apr 6, 2026
@sscargal sscargal added this to the v0.3.4 milestone Apr 6, 2026
Signed-off-by: Edwin Yu <edwinyyyu@gmail.com>

Copilot AI 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.

Pull request overview

This PR updates Neo4j graph-store initialization to ensure frequently queried episodic properties can be range-indexed (notably for cursor-ordered episode lookups that order by ("timestamp", "uid")).

Changes:

  • Pass range_index_hierarchies=[["uid"], ["timestamp", "uid"]] into Neo4jVectorGraphStoreParams during Neo4j driver/store construction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +168 to 169
"range_index_hierarchies": [["uid"], ["timestamp", "uid"]],
}

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

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

range_index_hierarchies is documented (in Neo4jVectorGraphStoreParams) as being applied to all node labels and relationship types. If the intent is specifically to speed up episodic queries, consider making this configurable (e.g., add a range_index_hierarchies field to Neo4jConf) or otherwise scoping it, to avoid creating potentially many additional indexes in deployments with many collections/relations.

Suggested change
"range_index_hierarchies": [["uid"], ["timestamp", "uid"]],
}
}
range_index_hierarchies = getattr(conf, "range_index_hierarchies", None)
if range_index_hierarchies is not None:
params_kwargs["range_index_hierarchies"] = range_index_hierarchies

Copilot uses AI. Check for mistakes.
Comment on lines 165 to 169
params_kwargs: dict[str, Any] = {
"driver": driver,
"force_exact_similarity_search": conf.force_exact_similarity_search,
"range_index_hierarchies": [["uid"], ["timestamp", "uid"]],
}

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

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

This change updates Neo4j graph store parameters but there is no unit test asserting that Neo4jVectorGraphStoreParams is constructed with the expected range_index_hierarchies. Since this behavior lives in DatabaseManager.async_get_neo4j_driver, please add/extend a test (similar to the existing kwargs-forwarding tests) to catch regressions.

Copilot uses AI. Check for mistakes.
Comment on lines 165 to 169
params_kwargs: dict[str, Any] = {
"driver": driver,
"force_exact_similarity_search": conf.force_exact_similarity_search,
"range_index_hierarchies": [["uid"], ["timestamp", "uid"]],
}

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

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

NebulaGraphVectorGraphStoreParams also supports range_index_hierarchies, and search_directional_nodes in episodic memory orders by ("timestamp", "uid"). If the performance issue exists for NebulaGraph too, consider passing the same range_index_hierarchies when constructing the Nebula graph store params for consistency; otherwise, it would help to clarify in the PR description that this indexing improvement is Neo4j-only.

Copilot uses AI. Check for mistakes.

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

LGTM. We can consider CoPilot's comments in the future if they are required.

@sscargal sscargal merged commit 3c265fc into MemMachine:main Apr 7, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Issues relating to MemMachine performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants