generated from langchain-ai/integration-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INTPYTHON-377 langgraph-checkpoint-mongodb (#7)
- Loading branch information
1 parent
8514d09
commit 21c0680
Showing
38 changed files
with
37,046 additions
and
897 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,10 @@ jobs: | |
|
||
- name: Install dependencies | ||
shell: bash | ||
run: poetry install --with test | ||
run: poetry install --with dev | ||
|
||
- name: Start MongoDB | ||
uses: supercharge/[email protected] | ||
|
||
- name: Run core tests | ||
shell: bash | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# 🦜️🔗 LangChain MongoDB | ||
|
||
This repository contains 1 package with MongoDB integrations with LangChain: | ||
This is a Monorepo containing partner packages of MongoDB and LangChainAI. | ||
It includes integrations between MongoDB, Atlas, LangChain, and LangGraph. | ||
|
||
- [langchain-mongodb](https://pypi.org/project/langchain-mongodb/) | ||
It contains the following packages. | ||
|
||
- `langchain-mongodb` ([PyPI](https://pypi.org/project/langchain-mongodb/)) | ||
- `langgraph-checkpoint-mongodb` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.PHONY: test lint format help | ||
|
||
###################### | ||
# TESTING AND COVERAGE | ||
###################### | ||
|
||
test tests: | ||
poetry run pytest tests | ||
|
||
###################### | ||
# LINTING AND FORMATTING | ||
###################### | ||
|
||
# Define a variable for Python and notebook files. | ||
PYTHON_FILES=. | ||
MYPY_CACHE=.mypy_cache | ||
lint format: PYTHON_FILES=. | ||
lint_diff format_diff: PYTHON_FILES=$(shell git diff --name-only --relative --diff-filter=d main . | grep -E '\.py$$|\.ipynb$$') | ||
lint_package: PYTHON_FILES=langgraph | ||
lint_tests: PYTHON_FILES=tests | ||
lint_tests: MYPY_CACHE=.mypy_cache_test | ||
|
||
lint lint_diff lint_package lint_tests: | ||
poetry run ruff check . | ||
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES) --diff | ||
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff check --select I $(PYTHON_FILES) | ||
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) | ||
[ "$(PYTHON_FILES)" = "" ] || poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE) | ||
|
||
format format_diff: | ||
poetry run ruff format $(PYTHON_FILES) | ||
poetry run ruff check --select I --fix $(PYTHON_FILES) | ||
|
||
###################### | ||
# HELP | ||
###################### | ||
|
||
help: | ||
@echo '----' | ||
@echo 'format - run code formatters' | ||
@echo 'lint - run linters' | ||
@echo 'test - run unit tests' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# LangGraph Checkpoint MongoDB | ||
|
||
Implementation of LangGraph CheckpointSaver that uses MongoDB. | ||
|
||
## Usage | ||
|
||
```python | ||
from langgraph.checkpoint.mongodb import MongoDBSaver | ||
|
||
write_config = {"configurable": {"thread_id": "1", "checkpoint_ns": ""}} | ||
read_config = {"configurable": {"thread_id": "1"}} | ||
|
||
MONGODB_URI = "mongodb://localhost:27017" | ||
DB_NAME = "checkpoint_example" | ||
|
||
with MongoDBSaver.from_conn_string(MONGODB_URI, DB_NAME) as checkpointer: | ||
# call .setup() the first time you're using the checkpointer | ||
checkpointer.setup() | ||
checkpoint = { | ||
"v": 1, | ||
"ts": "2024-07-31T20:14:19.804150+00:00", | ||
"id": "1ef4f797-8335-6428-8001-8a1503f9b875", | ||
"channel_values": { | ||
"my_key": "meow", | ||
"node": "node" | ||
}, | ||
"channel_versions": { | ||
"__start__": 2, | ||
"my_key": 3, | ||
"start:node": 3, | ||
"node": 3 | ||
}, | ||
"versions_seen": { | ||
"__input__": {}, | ||
"__start__": { | ||
"__start__": 1 | ||
}, | ||
"node": { | ||
"start:node": 2 | ||
} | ||
}, | ||
"pending_sends": [], | ||
} | ||
|
||
# store checkpoint | ||
checkpointer.put(write_config, checkpoint, {}, {}) | ||
|
||
# load checkpoint | ||
checkpointer.get(read_config) | ||
|
||
# list checkpoints | ||
list(checkpointer.list(read_config)) | ||
``` | ||
|
||
### Async | ||
|
||
```python | ||
from langgraph.checkpoint.pymongo import AsyncMongoDBSaver | ||
|
||
async with AsyncMongoDBSaver.from_conn_string(MONGODB_URI) as checkpointer: | ||
checkpoint = { | ||
"v": 1, | ||
"ts": "2024-07-31T20:14:19.804150+00:00", | ||
"id": "1ef4f797-8335-6428-8001-8a1503f9b875", | ||
"channel_values": { | ||
"my_key": "meow", | ||
"node": "node" | ||
}, | ||
"channel_versions": { | ||
"__start__": 2, | ||
"my_key": 3, | ||
"start:node": 3, | ||
"node": 3 | ||
}, | ||
"versions_seen": { | ||
"__input__": {}, | ||
"__start__": { | ||
"__start__": 1 | ||
}, | ||
"node": { | ||
"start:node": 2 | ||
} | ||
}, | ||
"pending_sends": [], | ||
} | ||
|
||
# store checkpoint | ||
await checkpointer.aput(write_config, checkpoint, {}, {}) | ||
|
||
# load checkpoint | ||
await checkpointer.aget(read_config) | ||
|
||
# list checkpoints | ||
[c async for c in checkpointer.alist(read_config)] | ||
``` |
Oops, something went wrong.