mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-26 19:45:00 +02:00
docs: update how-to for mongodb (#1297)
* docs: update how-to for mongodb
This commit is contained in:
+914
-1010
File diff suppressed because it is too large
Load Diff
@@ -7,9 +7,9 @@
|
||||
"source": [
|
||||
"# How to create a custom checkpointer using Redis\n",
|
||||
"\n",
|
||||
"When creating LangGraph agents, you can also set them up so that they persist their state. This allows you to do things like interact with an agent multiple times and have it remember previous interactions. Make sure that you have Redis running on port 6379 for going through this guide.\n",
|
||||
"When creating LangGraph agents, you can also set them up so that they persist their state. This allows you to do things like interact with an agent multiple times and have it remember previous interactions.\n",
|
||||
"\n",
|
||||
"This reference implementation shows how to use Redis as the backend for persisting checkpoint state.\n",
|
||||
"This reference implementation shows how to use Redis as the backend for persisting checkpoint state. Make sure that you have Redis running on port `6379` for going through this guide.\n",
|
||||
"\n",
|
||||
"NOTE: this is just an reference implementation. You can implement your own checkpointer using a different database or modify this one as long as it conforms to the `BaseCheckpointSaver` interface."
|
||||
]
|
||||
@@ -93,7 +93,6 @@
|
||||
"source": [
|
||||
"\"\"\"Implementation of a langgraph checkpoint saver using Redis.\"\"\"\n",
|
||||
"from contextlib import asynccontextmanager, contextmanager\n",
|
||||
"from hashlib import md5\n",
|
||||
"from typing import (\n",
|
||||
" Any,\n",
|
||||
" AsyncGenerator,\n",
|
||||
@@ -108,12 +107,10 @@
|
||||
"\n",
|
||||
"from langgraph.checkpoint.base import (\n",
|
||||
" BaseCheckpointSaver,\n",
|
||||
" ChannelProtocol,\n",
|
||||
" ChannelVersions,\n",
|
||||
" Checkpoint,\n",
|
||||
" CheckpointMetadata,\n",
|
||||
" CheckpointTuple,\n",
|
||||
" EmptyChannelError,\n",
|
||||
" PendingWrite,\n",
|
||||
" get_checkpoint_id,\n",
|
||||
")\n",
|
||||
@@ -230,22 +227,6 @@
|
||||
" return writes\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def _get_next_version(\n",
|
||||
" serde: SerializerProtocol, current: Optional[str], channel: ChannelProtocol\n",
|
||||
") -> str:\n",
|
||||
" \"\"\"Implementation of get_next_version for the checkpointers\"\"\"\n",
|
||||
" if current is None:\n",
|
||||
" current_v = 0\n",
|
||||
" else:\n",
|
||||
" current_v = int(current.split(\".\")[0])\n",
|
||||
" next_v = current_v + 1\n",
|
||||
" try:\n",
|
||||
" next_h = md5(serde.dumps_typed(channel.checkpoint())[1]).hexdigest()\n",
|
||||
" except EmptyChannelError:\n",
|
||||
" next_h = \"\"\n",
|
||||
" return f\"{next_v:032}.{next_h}\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def _parse_redis_checkpoint_data(\n",
|
||||
" serde: SerializerProtocol,\n",
|
||||
" key: str,\n",
|
||||
@@ -492,20 +473,6 @@
|
||||
" if data and b\"checkpoint\" in data and b\"metadata\" in data:\n",
|
||||
" yield _parse_redis_checkpoint_data(self.serde, key.decode(), data)\n",
|
||||
"\n",
|
||||
" def get_next_version(self, current: Optional[str], channel: ChannelProtocol) -> str:\n",
|
||||
" \"\"\"Generate the next version ID for a channel.\n",
|
||||
"\n",
|
||||
" This method creates a new version identifier for a channel based on its current version.\n",
|
||||
"\n",
|
||||
" Args:\n",
|
||||
" current (Optional[str]): The current version identifier of the channel.\n",
|
||||
" channel (BaseChannel): The channel being versioned.\n",
|
||||
"\n",
|
||||
" Returns:\n",
|
||||
" str: The next version identifier, which is guaranteed to be monotonically increasing.\n",
|
||||
" \"\"\"\n",
|
||||
" return _get_next_version(self.serde, current, channel)\n",
|
||||
"\n",
|
||||
" def _get_checkpoint_key(\n",
|
||||
" self, conn, thread_id: str, checkpoint_ns: str, checkpoint_id: Optional[str]\n",
|
||||
" ) -> Optional[str]:\n",
|
||||
@@ -736,20 +703,6 @@
|
||||
" if data and b\"checkpoint\" in data and b\"metadata\" in data:\n",
|
||||
" yield _parse_redis_checkpoint_data(self.serde, key.decode(), data)\n",
|
||||
"\n",
|
||||
" def get_next_version(self, current: Optional[str], channel: ChannelProtocol) -> str:\n",
|
||||
" \"\"\"Generate the next version ID for a channel.\n",
|
||||
"\n",
|
||||
" This method creates a new version identifier for a channel based on its current version.\n",
|
||||
"\n",
|
||||
" Args:\n",
|
||||
" current (Optional[str]): The current version identifier of the channel.\n",
|
||||
" channel (BaseChannel): The channel being versioned.\n",
|
||||
"\n",
|
||||
" Returns:\n",
|
||||
" str: The next version identifier, which is guaranteed to be monotonically increasing.\n",
|
||||
" \"\"\"\n",
|
||||
" return _get_next_version(self.serde, current, channel)\n",
|
||||
"\n",
|
||||
" async def _aget_checkpoint_key(\n",
|
||||
" self, conn, thread_id: str, checkpoint_ns: str, checkpoint_id: Optional[str]\n",
|
||||
" ) -> Optional[str]:\n",
|
||||
|
||||
Reference in New Issue
Block a user