-
Notifications
You must be signed in to change notification settings - Fork 4.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
Implement vector memory #13352
Implement vector memory #13352
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
llama-index-core/llama_index/core/agent/custom/pipeline_worker.py
Outdated
Show resolved
Hide resolved
self.vector_index.delete_nodes([last_node_id]) | ||
|
||
self.vector_index.insert_nodes([super_node]) | ||
self.chat_store.add_message(self.chat_store_key, ChatMessage(content=node_id)) |
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.
A little confused on the flow here
The chat store is keeping track of the inserted node ids (effectively maintaining order)? Not 100% sure what override last is for
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.
so I think override_last
is needed since we're updating the "batch" as we go. So if its not the end of the batch, we gotta delete the last entered node, and replace it in favor with the newly updated one... i.e. one that has the latest message.
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.
The chat_store
is acting as a temp buffer (I think you had mentioned before, and I'm just getting caught up with now) to track the current user batch i.e., group.
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.
yeah tbh it's a bit hacky, and we're not using chatstore for its intended purpose. but if we want to batch messages together we need some way of making sure the latest node is 1) always updated, but 2) can still be returned as part of vector search
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.
see working PR here for removing chat_store as buffer: #13729
2849ed5
to
5e1a231
Compare
llama-index-core/llama_index/core/memory/simple_composable_memory.py
Outdated
Show resolved
Hide resolved
chat_store: BaseChatStore = Field(default_factory=SimpleChatStore) | ||
# NOTE/TODO: we need this to store id's for the messages | ||
# This is not needed once vector stores implement delete_all capabilities | ||
chat_store_key: str = Field(default=DEFAULT_CHAT_STORE_KEY) |
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.
hm i guess we don't have delete_all
in the vector store yet, so we still need to maintain a list of all the ids
maybe fine for now, but may want to change this later to make vector memory less brittle (right now the chat store is in memory, so if we try to reinitialize the vector memory module there's no easy way to delete old data in vector memory)
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.
I think we have a clear()
method now that should delete all. Tbh, wasn't 100% clear on what this note meant. Are you saying that we only need chat_store
to maintain the id's
. And, since we have "clear()we can implement this without the
chat_store`?
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.
yeah basically. i think we still need the cur_user_msg_key for batching, but we no longer need to have a chat store track all user ids
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.
Sorry, I'm still hung up on this, but if we do a delete_all on the vector store, wouldn't that remove all past batches in addition to the current running batch? I think we would want to delete the current running batch so that we can start a new one with the incoming user message?
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.
left this for a future PR, but have started a working branch/PR for this that removes chat_store
. I have effectively got it working, but it needs further polishing.
UPDATE
BaseComposableMemory
andSimpleComposableMemory
for better separation of concernsVectorMemory
andChatMemoryBuffer
to aSimpleComposableMemory
which will do a simple composition on the messages that are retrieved by all of its memory sourcesvector_memory.ipynb
and added newcomposable_memory.ipynb
(added these to docs as well)OLDER
was way harder than i originally anticipated, summary of main changes:
general interface stuff:
input
argument toget
function in memoryput_messages
to memorymemory.set(..)
calls in the agent withmemory.put_messages
in terms of updating stateBaseChatStoreMemory
for all memory modules that depend on a chat storeimplemented vector memory:
delete_ref_doc
work