Skip to content

Conversation

@amritpal-singh-98
Copy link

@amritpal-singh-98 amritpal-singh-98 commented Sep 24, 2025

Description

Currently, creating multiple [Async]Memory instances pointing to the same Kuzu DB file will raise an error (Could not set lock on file : /path/to/database/example.kuzu). This is due to limitations in the way that Kuzu handles file locking and concurrency - see Connections and Concurrency | Kuzu. Specifically, in order to use the same Kuzu DB file, connections need to use the same kuzu.Database object. This PR ensures that kuzu.Database objects are reused when attempting to connect to the same .kuzu DB file.

This allows multiple [Async]Memory instances to point to the same Kuzu DB file without error and function as expected. (This is often the case in Jupyter notebooks and async code, for example.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Small change - tested accessing the same Kuzu DB file from two separate mem0 Memory and AsyncMemory instances and validated that read/write operations to the same underlying Kuzu DB file works as expected. Previously an error related to file locking was raised when attempting to create the second mem0 [Async]Memory instance pointing to the same Kuzu DB.

Please delete options that are not relevant.

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
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added 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

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Made sure Checks passed

Refactor database connection handling to reuse kuzu.Database instances to allow for concurrent use of the same underlying Kuzu DB file.
@CLAassistant
Copy link

CLAassistant commented Sep 24, 2025

CLA assistant check
All committers have signed the CLA.

Refactor MemoryGraph to use WeakValueDictionary for database objects.
@amritpal-singh-98 amritpal-singh-98 changed the title Reuse kuzu.Database connections in MemoryGraph Enable Kuzu Concurrency Sep 25, 2025
@amritpal-singh-98 amritpal-singh-98 changed the title Enable Kuzu Concurrency Fix: Enable Kuzu Concurrency Sep 25, 2025
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