Add vector_store pgvector index on payload->>user_id #3790
+6
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Using PGVector, we experience fulls sequential DB scans while searching for memories for a given user.
The
mem0collection has indeed no indexes onpayload->>user_idand usage on large datasets leads to long query time and high DB resources consumption or saturation.Open to discussion: index on
agent_idandrun_idmay be usefull to other users ofmem0and having those index enabled/disabled by configuration could be useful to some users to avoid space and memory waste.Fixes # (issue)
Type of change
How Has This Been Tested?
Testing index benefit
In a database loaded with ~50k memories split over ~200 user_id, we run load tests with and without the index on
user_id.Postgres query plan and request duration is checked with and without index.
Testing PR modification applies correct index
Init local DB:
Check DB schema:
Run following python test script:
Run with:
hatch run dev_py_3_12:python test_pg_vector_idx.pyCheck schema again:
Cleanup:
Checklist:
I have commented my code, particularly in hard-to-understand areasI have made corresponding changes to the documentationI have added tests that prove my fix is effective or that my feature worksI have checked my code and corrected any misspellingsMaintainer Checklist