Skip to content

Commit 5f04aaa

Browse files
authored
INTPYTHON-689 Remove Motor dependency (#170)
1 parent 3fc5df9 commit 5f04aaa

File tree

12 files changed

+2355
-1928
lines changed

12 files changed

+2355
-1928
lines changed

.github/workflows/_lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
# so linting on fewer versions makes CI faster.
3131
python-version:
3232
- "3.9"
33-
- "3.12"
33+
- "3.13"
3434
steps:
3535
- uses: actions/checkout@v4
3636
with:

.github/workflows/_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
matrix:
2020
python-version:
2121
- "3.9"
22-
- "3.12"
22+
- "3.13"
2323
name: "run test #${{ matrix.python-version }}"
2424
steps:
2525
- uses: actions/checkout@v4

libs/langchain-mongodb/langchain_mongodb/vectorstores.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def get_by_ids(self, ids: Sequence[str], /) -> list[Document]:
407407
_id = doc.pop("_id")
408408
text = doc.pop("text")
409409
del doc["embedding"]
410-
docs.append(Document(page_content=text, id=_id, metadata=doc))
410+
docs.append(Document(page_content=text, id=oid_to_str(_id), metadata=doc))
411411
return docs
412412

413413
def bulk_embed_and_insert_texts(

libs/langchain-mongodb/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ dev = [
3232
"mongomock>=4.2.0.post1",
3333
"pre-commit>=4.0",
3434
"mypy>=1.10",
35-
"simsimd>=5.0.0",
35+
"simsimd>=6.5.0",
3636
"langchain-ollama>=0.2.2",
3737
"langchain-openai>=0.2.14",
38-
"langchain-community>=0.3.14",
38+
"langchain-community>=0.3.27",
3939
"pypdf>=5.0.1",
4040
"langgraph>=0.2.72",
4141
"flaky>=3.8.1",

libs/langchain-mongodb/uv.lock

Lines changed: 1597 additions & 1277 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/langgraph-checkpoint-mongodb/langgraph/checkpoint/mongodb/aio.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
from contextlib import asynccontextmanager
88
from datetime import datetime
99
from importlib.metadata import version
10-
from typing import Any, Optional
10+
from typing import Any, Optional, cast
1111

1212
from langchain_core.runnables import RunnableConfig
13-
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase
1413
from pymongo import UpdateOne
1514
from pymongo.asynchronous.database import AsyncDatabase
1615
from pymongo.asynchronous.mongo_client import AsyncMongoClient
@@ -73,12 +72,12 @@ class AsyncMongoDBSaver(BaseCheckpointSaver):
7372
input=3, output=4
7473
"""
7574

76-
client: AsyncIOMotorClient | AsyncMongoClient
77-
db: AsyncIOMotorDatabase | AsyncDatabase
75+
client: AsyncMongoClient
76+
db: AsyncDatabase
7877

7978
def __init__(
8079
self,
81-
client: AsyncIOMotorClient | AsyncMongoClient,
80+
client: AsyncMongoClient,
8281
db_name: str = "checkpointing_db",
8382
checkpoint_collection_name: str = "checkpoints_aio",
8483
writes_collection_name: str = "checkpoint_writes_aio",
@@ -101,10 +100,10 @@ async def _setup(self) -> None:
101100
self._setup_future = asyncio.Future()
102101
if isinstance(self.client, AsyncMongoClient):
103102
num_indexes = len(
104-
await (await self.checkpoint_collection.list_indexes()).to_list() # type:ignore[misc]
103+
await (await self.checkpoint_collection.list_indexes()).to_list()
105104
)
106105
else:
107-
num_indexes = len(await self.checkpoint_collection.list_indexes().to_list()) # type:ignore[union-attr]
106+
num_indexes = len(await self.checkpoint_collection.list_indexes().to_list())
108107
if num_indexes < 2:
109108
await self.checkpoint_collection.create_index(
110109
keys=[("thread_id", 1), ("checkpoint_ns", 1), ("checkpoint_id", -1)],
@@ -117,10 +116,10 @@ async def _setup(self) -> None:
117116
)
118117
if isinstance(self.client, AsyncMongoClient):
119118
num_indexes = len(
120-
await (await self.writes_collection.list_indexes()).to_list() # type:ignore[misc]
119+
await (await self.writes_collection.list_indexes()).to_list()
121120
)
122121
else:
123-
num_indexes = len(await self.writes_collection.list_indexes().to_list()) # type:ignore[union-attr]
122+
num_indexes = len(await self.writes_collection.list_indexes().to_list())
124123
if num_indexes < 2:
125124
await self.writes_collection.create_index(
126125
keys=[
@@ -154,9 +153,9 @@ async def from_conn_string(
154153
155154
This includes creation of collections and indexes if they don't exist
156155
"""
157-
client: Optional[AsyncIOMotorClient] = None
156+
client: Optional[AsyncMongoClient] = None
158157
try:
159-
client = AsyncIOMotorClient(
158+
client = AsyncMongoClient(
160159
conn_string,
161160
driver=DriverInfo(
162161
name="Langgraph", version=version("langgraph-checkpoint-mongodb")
@@ -175,7 +174,7 @@ async def from_conn_string(
175174

176175
finally:
177176
if client:
178-
client.close()
177+
await client.close()
179178

180179
async def aget_tuple(self, config: RunnableConfig) -> Optional[CheckpointTuple]:
181180
"""Get a checkpoint tuple from the database asynchronously.
@@ -479,7 +478,7 @@ def list(
479478
while True:
480479
try:
481480
yield asyncio.run_coroutine_threadsafe(
482-
anext(aiter_),
481+
cast(Any, anext(aiter_)),
483482
self.loop,
484483
).result()
485484
except StopAsyncIteration:

libs/langgraph-checkpoint-mongodb/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ requires-python = ">=3.9"
1111
dependencies = [
1212
"langgraph-checkpoint>=2.0.23,<3.0.0",
1313
"langchain-mongodb>=0.6.1",
14-
"pymongo>=4.10,<4.14",
15-
"motor>3.6.0",
14+
"pymongo>=4.12,<4.14",
1615
]
1716

1817
[dependency-groups]

libs/langgraph-checkpoint-mongodb/tests/integration_tests/test_interrupts.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from langgraph.checkpoint.memory import InMemorySaver
1212
from langgraph.checkpoint.mongodb import MongoDBSaver
1313
from langgraph.graph import END, StateGraph
14-
from langgraph.graph.graph import CompiledGraph
1514

1615
# --- Configuration ---
1716
MONGODB_URI = os.environ.get("MONGODB_URI", "mongodb://localhost:27017")
@@ -77,16 +76,14 @@ def node_double(state: State) -> State:
7776

7877
# --- Compile Graph (with Interruption) ---
7978
# Using sync for simplicity in this demo
80-
graph: CompiledGraph = builder.compile(
81-
checkpointer=checkpointer, interrupt_after=["increment"]
82-
)
79+
graph = builder.compile(checkpointer=checkpointer, interrupt_after=["increment"])
8380

8481
# --- Configure ---
8582
config: RunnableConfig = {"configurable": {"thread_id": "thread_#1"}}
8683
initial_input = {"value": 10, "step": 0}
8784

8885
# --- 1st invoke, with Interruption
89-
interrupted_state = graph.invoke(initial_input, config=config)
86+
interrupted_state = graph.invoke(initial_input, config=config) # type:ignore[arg-type]
9087
assert interrupted_state == {"value": 10 + 1, "step": 1}
9188
state_history = list(graph.get_state_history(config))
9289
assert len(state_history) == 3
@@ -103,7 +100,7 @@ def node_double(state: State) -> State:
103100

104101
# --- 3rd invoke, but with an input ===> the CompiledGraph is restarted.
105102
new_input = {"value": 100, "step": -100}
106-
third_state = graph.invoke(new_input, config=config)
103+
third_state = graph.invoke(new_input, config=config) # type:ignore[arg-type]
107104
assert third_state == {"value": 101, "step": -99}
108105

109106
# The entire state history is preserved however

libs/langgraph-checkpoint-mongodb/tests/unit_tests/test_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55
from bson.errors import InvalidDocument
6-
from motor.motor_asyncio import AsyncIOMotorClient
6+
from pymongo import AsyncMongoClient
77

88
from langgraph.checkpoint.mongodb.aio import AsyncMongoDBSaver
99

@@ -14,7 +14,7 @@
1414

1515
async def test_asearch(input_data: dict[str, Any]) -> None:
1616
# Clear collections if they exist
17-
client: AsyncIOMotorClient = AsyncIOMotorClient(MONGODB_URI)
17+
client: AsyncMongoClient = AsyncMongoClient(MONGODB_URI)
1818
db = client[DB_NAME]
1919

2020
for clxn in await db.list_collection_names():

libs/langgraph-checkpoint-mongodb/tests/unit_tests/test_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_null_chars(input_data: dict[str, Any]) -> None:
9797
)
9898
assert saver.get_tuple(null_value_cfg).metadata["my_key"] == null_str # type: ignore
9999
assert (
100-
list(saver.list(None, filter={"my_key": null_str}))[0].metadata["my_key"] # type: ignore
100+
list(saver.list(None, filter={"my_key": null_str}))[0].metadata["my_key"]
101101
== null_str
102102
)
103103

0 commit comments

Comments
 (0)