Skip to content
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

db query_text and query_date is broken due to mismatched arguments (and other issue) #1347

Closed
1 task
madgrizzle opened this issue May 7, 2024 · 1 comment
Closed
1 task

Comments

@madgrizzle
Copy link
Contributor

madgrizzle commented May 7, 2024

Describe the bug

results = self.storage.query_text(query_string, count, start)

First:
The functions that call query_text and query_date send the equivalent of "limit" and "offset" in different order and therefore they are mismatched.
In BaseRecallMemory, query_text is called as follows:
results = self.storage.query_text(query_string, count, start)
in SQLStorageConnector, query_text definition is:
def query_text(self, offset=0, limit=None):

count is equivalent to limit and start is equivalent to offset, but they are listed in different order and therefore they get swapped. So, if the intent was to get the first 5 results from page 0, you end up getting all the results (because limit=0) after message 5 (because offset=5). Easy fix.

Second:
The query will search all messages, including the system prompt and any tool messages. If you get a system message in the return, you have a high chance of exceeding the context size and summarize will fail because it never summarizes the last message. I don't see the value in searching the system prompt since it's already being returned anyway. I suspect tool messages aren't relevant either and would think these search functions are intended to focus on what the user said and what the llm said. So I propose to include two additional filters to those functions:

                .filter(self.db_model.role != 'system')
                .filter(self.db_model.role != 'tool') 

Third:
Issue #1343
This should be fixed in db.py as well. I'm just not sure yet if it will break sqllite to make the fix in SQLStorageConnector or implement an override in PostgresStorageConnector

I've tested and used both of these changes and its returning what's expected.

Please describe your setup

  • How did you install memgpt?
    • pip install pymemgpt
@sarahwooders
Copy link
Collaborator

I believe this is closed by #1355, but please re-open if not!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants