-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Optimize memory fetching by moving sorting and slicing to DB #1531
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look fine but the question is there any other part of the system that also used them, we need to check
as of my knowledge it's also used in twitter client. I can try later this week if it will work with twitter client enabled as well |
@odilitime works with twitter on 0.1.7-alpha.1 just fine https://x.com/Bino_io |
closed in favor of #2135 |
refactor: Optimize memory fetching by moving sorting and slicing to DB (PR #1531 remake)
refactor: Optimize memory fetching by moving sorting and slicing to DB (PR elizaOS#1531 remake)
Relates to:
No
Risks
Low
IDatabaseAdapter
, other database adapters are still working because thelimit
parameter is optional.getMemoriesByRoomIds
function can opt into thelimit
functionality, but it is not necessary.Background
What does this PR do?
This PR improves the performance of memory-fetching functionality by:
limit
parameter to restrict the number of results fetched from the database.Why was this change made?
In our database with 60,000 memories, fetching memories by room IDs took 40 seconds, significantly affecting the performance of the agent. After applying this fix, the query execution time dropped to just 0.02 seconds. This improvement was observed using Supabase analytics.
What kind of change is this?
Improvements
Documentation changes needed?
My changes do not require a change to the project documentation.
Testing
Where should a reviewer start?
packages/adapter-postgres/src/index.ts
to understand how sorting and limiting were implemented in the database query.packages/core/src/runtime.ts
for the integration of thelimit
parameter.Detailed testing steps
limit
parameter.createdAt DESC
) is maintained.Database changes
ORDER BY createdAt DESC
and optionalLIMIT
in the PostgreSQL adapter.Discord username
nikita_zhou
Screenshots
I will attach screenshots of:
Using Postgres adapter
Using SQLite adapter
Linting