langgraph-checkpoint-postgres 2.0.13__tar.gz → 2.0.14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/PKG-INFO +1 -1
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/langgraph/checkpoint/postgres/__init__.py +11 -1
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/langgraph/checkpoint/postgres/aio.py +11 -1
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/langgraph/checkpoint/postgres/shallow.py +22 -2
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/langgraph/store/postgres/aio.py +16 -13
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/langgraph/store/postgres/base.py +37 -18
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/pyproject.toml +1 -1
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/README.md +0 -0
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/langgraph/checkpoint/postgres/_ainternal.py +0 -0
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/langgraph/checkpoint/postgres/_internal.py +0 -0
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/langgraph/checkpoint/postgres/base.py +0 -0
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/langgraph/checkpoint/postgres/py.typed +0 -0
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/langgraph/store/postgres/__init__.py +0 -0
- {langgraph_checkpoint_postgres-2.0.13 → langgraph_checkpoint_postgres-2.0.14}/langgraph/store/postgres/py.typed +0 -0
|
@@ -317,7 +317,17 @@ class PostgresSaver(BasePostgresSaver):
|
|
|
317
317
|
checkpoint["id"],
|
|
318
318
|
checkpoint_id,
|
|
319
319
|
Jsonb(self._dump_checkpoint(copy)),
|
|
320
|
-
self._dump_metadata(
|
|
320
|
+
self._dump_metadata(
|
|
321
|
+
{
|
|
322
|
+
**{
|
|
323
|
+
k: v
|
|
324
|
+
for k, v in config["configurable"].items()
|
|
325
|
+
if not k.startswith("__")
|
|
326
|
+
},
|
|
327
|
+
**config.get("metadata", {}),
|
|
328
|
+
**metadata,
|
|
329
|
+
}
|
|
330
|
+
),
|
|
321
331
|
),
|
|
322
332
|
)
|
|
323
333
|
return next_config
|
|
@@ -275,7 +275,17 @@ class AsyncPostgresSaver(BasePostgresSaver):
|
|
|
275
275
|
checkpoint["id"],
|
|
276
276
|
checkpoint_id,
|
|
277
277
|
Jsonb(self._dump_checkpoint(copy)),
|
|
278
|
-
self._dump_metadata(
|
|
278
|
+
self._dump_metadata(
|
|
279
|
+
{
|
|
280
|
+
**{
|
|
281
|
+
k: v
|
|
282
|
+
for k, v in config["configurable"].items()
|
|
283
|
+
if not k.startswith("__")
|
|
284
|
+
},
|
|
285
|
+
**config.get("metadata", {}),
|
|
286
|
+
**metadata,
|
|
287
|
+
}
|
|
288
|
+
),
|
|
279
289
|
),
|
|
280
290
|
)
|
|
281
291
|
return next_config
|
|
@@ -423,7 +423,17 @@ class ShallowPostgresSaver(BasePostgresSaver):
|
|
|
423
423
|
thread_id,
|
|
424
424
|
checkpoint_ns,
|
|
425
425
|
Jsonb(self._dump_checkpoint(copy)),
|
|
426
|
-
self._dump_metadata(
|
|
426
|
+
self._dump_metadata(
|
|
427
|
+
{
|
|
428
|
+
**{
|
|
429
|
+
k: v
|
|
430
|
+
for k, v in config["configurable"].items()
|
|
431
|
+
if not k.startswith("__")
|
|
432
|
+
},
|
|
433
|
+
**config.get("metadata", {}),
|
|
434
|
+
**metadata,
|
|
435
|
+
}
|
|
436
|
+
),
|
|
427
437
|
),
|
|
428
438
|
)
|
|
429
439
|
return next_config
|
|
@@ -742,7 +752,17 @@ class AsyncShallowPostgresSaver(BasePostgresSaver):
|
|
|
742
752
|
thread_id,
|
|
743
753
|
checkpoint_ns,
|
|
744
754
|
Jsonb(self._dump_checkpoint(copy)),
|
|
745
|
-
self._dump_metadata(
|
|
755
|
+
self._dump_metadata(
|
|
756
|
+
{
|
|
757
|
+
**{
|
|
758
|
+
k: v
|
|
759
|
+
for k, v in config["configurable"].items()
|
|
760
|
+
if not k.startswith("__")
|
|
761
|
+
},
|
|
762
|
+
**config.get("metadata", {}),
|
|
763
|
+
**metadata,
|
|
764
|
+
}
|
|
765
|
+
),
|
|
746
766
|
),
|
|
747
767
|
)
|
|
748
768
|
return next_config
|
|
@@ -39,14 +39,14 @@ class AsyncPostgresStore(AsyncBatchedBaseStore, BasePostgresStore[_ainternal.Con
|
|
|
39
39
|
"""Asynchronous Postgres-backed store with optional vector search using pgvector.
|
|
40
40
|
|
|
41
41
|
!!! example "Examples"
|
|
42
|
-
Basic setup and
|
|
42
|
+
Basic setup and usage:
|
|
43
43
|
```python
|
|
44
44
|
from langgraph.store.postgres import AsyncPostgresStore
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
) as store:
|
|
49
|
-
await store.setup()
|
|
46
|
+
conn_string = "postgresql://user:pass@localhost:5432/dbname"
|
|
47
|
+
|
|
48
|
+
async with AsyncPostgresStore.from_conn_string(conn_string) as store:
|
|
49
|
+
await store.setup() # Run migrations. Done once
|
|
50
50
|
|
|
51
51
|
# Store and retrieve data
|
|
52
52
|
await store.aput(("users", "123"), "prefs", {"theme": "dark"})
|
|
@@ -58,38 +58,41 @@ class AsyncPostgresStore(AsyncBatchedBaseStore, BasePostgresStore[_ainternal.Con
|
|
|
58
58
|
from langchain.embeddings import init_embeddings
|
|
59
59
|
from langgraph.store.postgres import AsyncPostgresStore
|
|
60
60
|
|
|
61
|
+
conn_string = "postgresql://user:pass@localhost:5432/dbname"
|
|
62
|
+
|
|
61
63
|
async with AsyncPostgresStore.from_conn_string(
|
|
62
|
-
|
|
64
|
+
conn_string,
|
|
63
65
|
index={
|
|
64
66
|
"dims": 1536,
|
|
65
67
|
"embed": init_embeddings("openai:text-embedding-3-small"),
|
|
66
68
|
"fields": ["text"] # specify which fields to embed. Default is the whole serialized value
|
|
67
69
|
}
|
|
68
70
|
) as store:
|
|
69
|
-
await store.setup() #
|
|
71
|
+
await store.setup() # Run migrations. Done once
|
|
70
72
|
|
|
71
73
|
# Store documents
|
|
72
74
|
await store.aput(("docs",), "doc1", {"text": "Python tutorial"})
|
|
73
75
|
await store.aput(("docs",), "doc2", {"text": "TypeScript guide"})
|
|
74
|
-
#
|
|
75
|
-
await store.aput(("docs",), "doc3", {"text": "Other guide"}, index=False)
|
|
76
|
+
await store.aput(("docs",), "doc3", {"text": "Other guide"}, index=False) # don't index
|
|
76
77
|
|
|
77
78
|
# Search by similarity
|
|
78
|
-
results = await store.asearch(("docs",),
|
|
79
|
+
results = await store.asearch(("docs",), "programming guides", limit=2)
|
|
79
80
|
```
|
|
80
81
|
|
|
81
82
|
Using connection pooling for better performance:
|
|
82
83
|
```python
|
|
83
84
|
from langgraph.store.postgres import AsyncPostgresStore, PoolConfig
|
|
84
85
|
|
|
86
|
+
conn_string = "postgresql://user:pass@localhost:5432/dbname"
|
|
87
|
+
|
|
85
88
|
async with AsyncPostgresStore.from_conn_string(
|
|
86
|
-
|
|
89
|
+
conn_string,
|
|
87
90
|
pool_config=PoolConfig(
|
|
88
91
|
min_size=5,
|
|
89
92
|
max_size=20
|
|
90
93
|
)
|
|
91
94
|
) as store:
|
|
92
|
-
await store.setup()
|
|
95
|
+
await store.setup() # Run migrations. Done once
|
|
93
96
|
# Use store with connection pooling...
|
|
94
97
|
```
|
|
95
98
|
|
|
@@ -102,7 +105,7 @@ class AsyncPostgresStore(AsyncBatchedBaseStore, BasePostgresStore[_ainternal.Con
|
|
|
102
105
|
Note:
|
|
103
106
|
Semantic search is disabled by default. You can enable it by providing an `index` configuration
|
|
104
107
|
when creating the store. Without this configuration, all `index` arguments passed to
|
|
105
|
-
`put` or `aput`will have no effect.
|
|
108
|
+
`put` or `aput` will have no effect.
|
|
106
109
|
"""
|
|
107
110
|
|
|
108
111
|
__slots__ = (
|
|
@@ -536,18 +536,35 @@ class PostgresStore(BaseStore, BasePostgresStore[_pg_internal.Conn]):
|
|
|
536
536
|
"""Postgres-backed store with optional vector search using pgvector.
|
|
537
537
|
|
|
538
538
|
!!! example "Examples"
|
|
539
|
-
Basic setup and
|
|
539
|
+
Basic setup and usage:
|
|
540
540
|
```python
|
|
541
541
|
from langgraph.store.postgres import PostgresStore
|
|
542
|
+
from psycopg import Connection
|
|
542
543
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
544
|
+
conn_string = "postgresql://user:pass@localhost:5432/dbname"
|
|
545
|
+
|
|
546
|
+
# Using direct connection
|
|
547
|
+
with Connection.connect(conn_string) as conn:
|
|
548
|
+
store = PostgresStore(conn)
|
|
549
|
+
store.setup() # Run migrations. Done once
|
|
547
550
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
+
# Store and retrieve data
|
|
552
|
+
store.put(("users", "123"), "prefs", {"theme": "dark"})
|
|
553
|
+
item = store.get(("users", "123"), "prefs")
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
Or using the convenient from_conn_string helper:
|
|
557
|
+
```python
|
|
558
|
+
from langgraph.store.postgres import PostgresStore
|
|
559
|
+
|
|
560
|
+
conn_string = "postgresql://user:pass@localhost:5432/dbname"
|
|
561
|
+
|
|
562
|
+
with PostgresStore.from_conn_string(conn_string) as store:
|
|
563
|
+
store.setup()
|
|
564
|
+
|
|
565
|
+
# Store and retrieve data
|
|
566
|
+
store.put(("users", "123"), "prefs", {"theme": "dark"})
|
|
567
|
+
item = store.get(("users", "123"), "prefs")
|
|
551
568
|
```
|
|
552
569
|
|
|
553
570
|
Vector search using LangChain embeddings:
|
|
@@ -555,23 +572,25 @@ class PostgresStore(BaseStore, BasePostgresStore[_pg_internal.Conn]):
|
|
|
555
572
|
from langchain.embeddings import init_embeddings
|
|
556
573
|
from langgraph.store.postgres import PostgresStore
|
|
557
574
|
|
|
558
|
-
|
|
559
|
-
|
|
575
|
+
conn_string = "postgresql://user:pass@localhost:5432/dbname"
|
|
576
|
+
|
|
577
|
+
with PostgresStore.from_conn_string(
|
|
578
|
+
conn_string,
|
|
560
579
|
index={
|
|
561
580
|
"dims": 1536,
|
|
562
581
|
"embed": init_embeddings("openai:text-embedding-3-small"),
|
|
563
582
|
"fields": ["text"] # specify which fields to embed. Default is the whole serialized value
|
|
564
583
|
}
|
|
565
|
-
)
|
|
566
|
-
|
|
584
|
+
) as store:
|
|
585
|
+
store.setup() # Do this once to run migrations
|
|
567
586
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
587
|
+
# Store documents
|
|
588
|
+
store.put(("docs",), "doc1", {"text": "Python tutorial"})
|
|
589
|
+
store.put(("docs",), "doc2", {"text": "TypeScript guide"})
|
|
590
|
+
store.put(("docs",), "doc2", {"text": "Other guide"}, index=False) # don't index
|
|
572
591
|
|
|
573
|
-
|
|
574
|
-
|
|
592
|
+
# Search by similarity
|
|
593
|
+
results = store.search(("docs",), "programming guides", limit=2)
|
|
575
594
|
```
|
|
576
595
|
|
|
577
596
|
Note:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|