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
Copy file name to clipboardExpand all lines: tutorial/markdown/generated/vector-search-cookbook/langgraph-couchbase_persistence_langgraph.md
+39-23Lines changed: 39 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,12 +53,18 @@ This package provides a seamless way to persist LangGraph agent states in Couchb
53
53
54
54
## Setup environment
55
55
56
-
Requires Couchbase Python SDK and langgraph package
56
+
Requires Couchbase Python SDK, LangGraph, and langchain-openai.
57
+
58
+
Set `OPENAI_API_KEY` before running. For local Couchbase runs, this notebook also reads `CB_CONN_STR`, `CB_USER`, `CB_PASS`, `CB_BUCKET_NAME`, and `CB_SCOPE_NAME` from the environment.
59
+
60
+
For the local example below, create bucket `test`, scope `langgraph`, and the `checkpoints` / `checkpoint_writes` collections first, or provide equivalent names through the environment variables. The default `CB_*` values shown later are for local development only.
@@ -88,7 +105,7 @@ We are using a tool `get_weather` which gives the weather information based on t
88
105
from typing import Literal
89
106
from langchain_core.tools import tool
90
107
from langchain_openai import ChatOpenAI
91
-
fromlanggraph.prebuiltimportcreate_react_agent
108
+
fromlangchain.agentsimportcreate_agent
92
109
93
110
94
111
@tool
@@ -106,7 +123,7 @@ tools = [get_weather]
106
123
model = ChatOpenAI(model_name="gpt-4.1-mini", temperature=0)
107
124
```
108
125
109
-
### Couchbase Connection and intialization
126
+
### Couchbase Connection and initialization
110
127
111
128
There are 2 ways to initialize a saver.
112
129
@@ -125,7 +142,7 @@ Below is usage of CouchbaseSaver (for synchronous use of graph, i.e. `.invoke()`
125
142
-`.get_tuple` - Fetch a checkpoint tuple using a given configuration (`thread_id` and `checkpoint_id`).
126
143
-`.list` - List checkpoints that match a given configuration and filter criteria.
127
144
128
-
Here we will create a Couchbase connection. We are using local setup with bucket `test`, `langgraph` scope. You may change bucket and scope if required. We will also require `checkpoints` and `checkpoint_writes` as collections inside.
145
+
Here we will create a Couchbase connection. We are using local setup with bucket `test`, `langgraph` scope. You may change bucket and scope if required. We will also require `checkpoints` and `checkpoint_writes` as collections inside the configured scope.
129
146
130
147
Then a [ReAct Agent](https://langchain-ai.github.io/langgraph/how-tos/create-react-agent/) is created with GPT Model, weather tool and Couchbase checkpointer.
131
148
@@ -136,19 +153,20 @@ LangGraph's graph is invoked with message for GPT, storing all the state in Couc
136
153
from langgraph_checkpointer_couchbase import CouchbaseSaver
This is the asynchronous example, Here we will create a Couchbase connection. We are using local setup with bucket `test`, `langgraph` scope. We will also require `checkpoints` and `checkpoint_writes` as collections inside. These are the methods supported by the library
229
+
This is the asynchronous example, Here we will create a Couchbase connection. We are using local setup with bucket `test`, `langgraph` scope. We will also require `checkpoints` and `checkpoint_writes` as collections inside the configured scope. These are the methods supported by the library
212
230
213
231
-`.aput` - Store a checkpoint with its configuration and metadata.
214
232
-`.aput_writes` - Store intermediate writes linked to a checkpoint (i.e. pending writes).
@@ -226,13 +244,10 @@ from acouchbase.cluster import Cluster as ACluster
0 commit comments