Find answers from the community

Updated 10 months ago

Anyone know where i can find more info

Anyone know where i can find more info on chatstorage ? Persist to db, recall history load sessions and so forth?
L
h
15 comments
Its a pretty new concept -- I wrote it because someone was adding a redis memory module, and I didn't want to maintain two versions of the same sliding-window buffer logic πŸ˜…

Docs are here
https://docs.llamaindex.ai/en/stable/module_guides/storing/chat_stores.html#chat-stores

Happy to answer any questions though that are maybe missing from that page
Ok cool, yeah i read the docs, thought i might have missed some, but basically saving a conversation to json then reopen it as_chat will have a menory of the whole conversation ?
Yea, like you'll need to load the chat store, and pass it to the memory module with the appropriate key set.

Plain Text
chat_memory = ChatMemoryBuffer.from_defaults(
    token_limit=3000,
    chat_store=chat_store,
    chat_store_key="user1",  # <- points to what collection in the chat store to use
)


Then using that memory in a chat engine or agent, it will have access to the past chat history
I cant get it to work the storage is never created i e setup a redis stack to run against
mmm it works for me?

Plain Text
from llama_index import SimpleDirectoryReader, VectorStoreIndex
from llama_index.storage.chat_store import RedisChatStore
from llama_index.memory import ChatMemoryBuffer

chat_store = RedisChatStore(redis_url="redis://localhost:6379")
memory = ChatMemoryBuffer.from_defaults(chat_store=chat_store, chat_store_key="user123")

documents = SimpleDirectoryReader("./docs/examples/data/paul_graham").load_data()

index = VectorStoreIndex.from_documents(documents)

agent = index.as_chat_engine(memory=memory)

agent.chat("What did the author go growing up?")
agent.chat("Thanks!")

print("agent ", agent.chat_history)
print("-------")
print("chat_store ", chat_store.get_messages("user123"))
Also just running redis-stack on docker
Attachment
image.png
Ahh now i see it i loaded it in the wrong way, thanks logan!! Iam sorry but iam sure i will be back with stupid questions πŸ™‚
Are there any plans for more stores ?? Postgres ?
I'm not sure how storing a list would work in postgress. A JSON blob maybe?

The interface is fairly simple -- very open to community PRs ❀️
Ive been working with python for like 1 week πŸ™‚ so not yet i think, i can probably write a wrapper on the simplechat store to store in postgres
Yeah i know looked at it already πŸ™‚
ah sweet πŸ™‚
Iam thinking a chatstore table with a combined pk on sessionid and message id would work the. Just do inserts upserts deletes on the table would work, but i dont have the knowhow to do it yet though
hmm when running a
"
Stream = agent.stream_chat(prompt)
for response in Stream.response_gen:
responseBuffer += (response or "")
"

the assistans answer is not appended to the chatmemory
Add a reply
Sign up and join the conversation on Discord