You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the PostgresChatMessageHistory class in the langchain-postgres package does not support asynchronous connection pooling using psycopg_pool.AsyncConnectionPool. This limitation leads to inefficiencies and potential resource exhaustion in high-load asynchronous applications, as each database operation may open a new connection instead of reusing existing ones.
When attempting to use PostgresChatMessageHistory with an AsyncConnectionPool, we encounter errors due to missing parameters and unexpected arguments. Specifically, the __init__ method does not accept a conn_pool parameter, and the parameter order causes issues with positional-only parameters.
What We Need:
Add support for asynchronous connection pooling by modifying the PostgresChatMessageHistory class to accept an AsyncConnectionPool instance.
Adjust the __init__ method to include a conn_pool parameter and modify the parameter order to avoid positional-only parameter issues.
Update asynchronous methods (aget_messages, aadd_messages, etc.) to utilize the connection pool when provided.
Ensure backward compatibility by maintaining existing functionality for sync_connection and async_connection.
Add unit tests to verify the new functionality with the connection pool.
Update documentation and README to reflect the changes and provide examples of using the class with an AsyncConnectionPool.
Code to Reproduce Error:
Attempting to use PostgresChatMessageHistory with an AsyncConnectionPool leads to errors.
importuuidimportasynciofromlangchain_postgres.chat_message_historiesimportPostgresChatMessageHistoryfrompsycopg_poolimportAsyncConnectionPoolfromlangchain_core.messagesimportAIMessage, HumanMessage, SystemMessage# Initialize the connection poolpool=AsyncConnectionPool(conninfo="postgresql://user:password@host:port/dbname")
asyncdefmain():
table_name="chat_history"session_id=str(uuid.uuid4())
# Attempt to create PostgresChatMessageHistory with conn_poolchat_history=PostgresChatMessageHistory(
table_name=table_name,
session_id=session_id,
conn_pool=pool,
)
# Add messages to the chat historyawaitchat_history.aadd_messages([
SystemMessage(content="System message"),
AIMessage(content="AI response"),
HumanMessage(content="Human message"),
])
# Retrieve messages from the chat historymessages=awaitchat_history.aget_messages()
print(messages)
# Run the async main functionasyncio.run(main())
Unexpected Keyword Argument 'conn_pool': The PostgresChatMessageHistory class does not currently accept a conn_pool parameter, leading to this error.
Parameter Unfilled Errors: The __init__ method uses positional-only parameters for table_name and session_id, causing issues when they are passed as keyword arguments.
Request:
Please update the PostgresChatMessageHistory class to support asynchronous connection pooling and adjust the parameter handling to resolve these errors. This enhancement will improve efficiency and resource management in asynchronous applications using the langchain-postgres package.
Currently, the
PostgresChatMessageHistory
class in thelangchain-postgres
package does not support asynchronous connection pooling usingpsycopg_pool.AsyncConnectionPool
. This limitation leads to inefficiencies and potential resource exhaustion in high-load asynchronous applications, as each database operation may open a new connection instead of reusing existing ones.When attempting to use
PostgresChatMessageHistory
with anAsyncConnectionPool
, we encounter errors due to missing parameters and unexpected arguments. Specifically, the__init__
method does not accept aconn_pool
parameter, and the parameter order causes issues with positional-only parameters.What We Need:
PostgresChatMessageHistory
class to accept anAsyncConnectionPool
instance.__init__
method to include aconn_pool
parameter and modify the parameter order to avoid positional-only parameter issues.aget_messages
,aadd_messages
, etc.) to utilize the connection pool when provided.sync_connection
andasync_connection
.AsyncConnectionPool
.Code to Reproduce Error:
Attempting to use
PostgresChatMessageHistory
with anAsyncConnectionPool
leads to errors.Errors Encountered:
Explanation:
PostgresChatMessageHistory
class does not currently accept aconn_pool
parameter, leading to this error.__init__
method uses positional-only parameters fortable_name
andsession_id
, causing issues when they are passed as keyword arguments.Request:
Please update the
PostgresChatMessageHistory
class to support asynchronous connection pooling and adjust the parameter handling to resolve these errors. This enhancement will improve efficiency and resource management in asynchronous applications using thelangchain-postgres
package.Related Issues
PostgresChatMessageHistory
with async connections when usingRunnableWithMessageHistory
? #122The text was updated successfully, but these errors were encountered: