How to correctly use AsyncDuckDBSaver in Langgraph to avoid compiling every time, otherwise conn is closed #2361
-
async with CustomMemorySaver.from_conn_string("data/db_duck.db") as memory: The internal method of memory holds the conn, which may have already been closed when calling the method. There is no connection pool or other way to create a connection every time the method is called, instead of holding the conn Is there any other better way to avoid compiling every time and also avoid 'con is closed' Or modify this method to add @asynccontextmanager |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@tianshangwuyun you can just define the connection on our own and pass it to the DuckDB checkpointer like this conn = duckdb.connect(conn_string)
checkpointer = AsyncDuckDBSaver(conn=conn)
# use checkpointer here
# ...
conn.close() hope this helps! |
Beta Was this translation helpful? Give feedback.
ah, i see your point. calling
graph.compile()
should not cause any performance issues, so it's fine to re-compile. also, i would suggest using Postgres checkpointer -- with Postgres you can use a connection pool and that should address some of the concerns you mentioned