User based memorization with ConversationBufferMemory and CombinedMemory
Labels: name: area: memory, name: auto:bug, name: integration: redis

### System Info

langchain version: 0.0320
python version: 3.10

### Who can help?

_No response_

### Information

- [X] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [X] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

User based memorization with ConversationBufferMemory and CombinedMemory. Attaching my code below, Please let me know where I am doing wrong:

session_id= "user2"
vect_memory = VectorStoreRetrieverMemory(retriever=retriever)

_DEFAULT_TEMPLATE = """
                You are having a conversation with a human. Please interact like a human being and give an accurate answer.

                Relevant pieces of the previous conversation:
                {history}

                (You do not need to use these pieces of information if not relevant)

                Current conversation:
                {session_id}
                User: {input}
                Chatbot:
            """

PROMPT = PromptTemplate(
    input_variables=["history","session_id",  "input"],
    template=_DEFAULT_TEMPLATE
)
print(PROMPT)
message_history = RedisChatMessageHistory(url=redis_url, session_id=session_id)
conv_memory = ConversationBufferMemory(
    memory_key="session_id",
    chat_memory=message_history,
    input_key="input",
    prompt=PROMPT,
    return_messages=True
)
memory = CombinedMemory(memories=[conv_memory, vect_memory])

llm = OpenAI(temperature=0, model_name='gpt-3.5-turbo')  # Can be any valid LLM

conversation_with_summary = ConversationChain(
    llm=llm,
    prompt=PROMPT,
    memory=memory,
    verbose=True,

)
conversation_with_summary(input="hELLO")


It is not working on the base of session.



=================I am getting sthis error=======================
Traceback (most recent call last):
  File "C:\Users\ankit\PycharmProjects\spendidchatbot\chatbot.py", line 306, in <module>
    conversation_with_summary = ConversationChain(
  File "C:\Users\ankit\PycharmProjects\spendidchatbot\env_spen\lib\site-packages\langchain\load\serializable.py", line 97, in _init_
    super().__init__(**kwargs)
  File "C:\Users\ankit\PycharmProjects\spendidchatbot\env_spen\lib\site-packages\pydantic\v1\main.py", line 341, in _init_
    raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for ConversationChain
_root_
  Got unexpected prompt input variables. The prompt expects ['history', 'input', 'session_id'], but got ['user2', 'history'] as inputs from memory, and input as the normal input key. (type=value_error)


### Expected behavior

User based memorization with ConversationBufferMemory and CombinedMemory. Attaching my code below, Please let me know where I am doing wrong:

session_id= "user2"
vect_memory = VectorStoreRetrieverMemory(retriever=retriever)

_DEFAULT_TEMPLATE = """
                You are having a conversation with a human. Please interact like a human being and give an accurate answer.

                Relevant pieces of the previous conversation:
                {history}

                (You do not need to use these pieces of information if not relevant)

                Current conversation:
                {session_id}
                User: {input}
                Chatbot:
            """

PROMPT = PromptTemplate(
    input_variables=["history","session_id",  "input"],
    template=_DEFAULT_TEMPLATE
)
print(PROMPT)
message_history = RedisChatMessageHistory(url=redis_url, session_id=session_id)
conv_memory = ConversationBufferMemory(
    memory_key="session_id",
    chat_memory=message_history,
    input_key="input",
    prompt=PROMPT,
    return_messages=True
)
memory = CombinedMemory(memories=[conv_memory, vect_memory])

llm = OpenAI(temperature=0, model_name='gpt-3.5-turbo')  # Can be any valid LLM

conversation_with_summary = ConversationChain(
    llm=llm,
    prompt=PROMPT,
    memory=memory,
    verbose=True,

)
conversation_with_summary(input="hELLO")


It is not working on the base of session.

=================I am getting sthis error=======================
Traceback (most recent call last):
  File "C:\Users\ankit\PycharmProjects\spendidchatbot\chatbot.py", line 306, in <module>
    conversation_with_summary = ConversationChain(
  File "C:\Users\ankit\PycharmProjects\spendidchatbot\env_spen\lib\site-packages\langchain\load\serializable.py", line 97, in _init_
    super().__init__(**kwargs)
  File "C:\Users\ankit\PycharmProjects\spendidchatbot\env_spen\lib\site-packages\pydantic\v1\main.py", line 341, in _init_
    raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for ConversationChain
_root_
  Got unexpected prompt input variables. The prompt expects ['history', 'input', 'session_id'], but got ['user2', 'history'] as inputs from memory, and input as the normal input key. (type=value_error)