Skip to content

refactor: use ULIDs instead of uuids #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions langgraph/store/redis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import asyncio
import json
import math
import uuid
from contextlib import contextmanager
from datetime import datetime, timezone
from typing import Any, Iterable, Iterator, Optional, Sequence, cast
from ulid import ULID

from langgraph.store.base import (
BaseStore,
Expand Down Expand Up @@ -223,7 +223,7 @@ def _batch_put_ops(
# Generate IDs for PUT operations
for _, op in put_ops:
if op.value is not None:
generated_doc_id = uuid.uuid4().hex
generated_doc_id = str(ULID())
namespace = _namespace_to_text(op.namespace)
doc_ids[(namespace, op.key)] = generated_doc_id

Expand Down
4 changes: 2 additions & 2 deletions langgraph/store/redis/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import asyncio
import json
import uuid
import weakref
from contextlib import asynccontextmanager
from datetime import datetime, timezone
from types import TracebackType
from typing import Any, AsyncIterator, Iterable, Optional, Sequence, cast
from ulid import ULID

from langgraph.store.base import (
BaseStore,
Expand Down Expand Up @@ -398,7 +398,7 @@ async def _batch_put_ops(
# Generate IDs for PUT operations
for _, op in put_ops:
if op.value is not None:
generated_doc_id = uuid.uuid4().hex
generated_doc_id = str(ULID())
namespace = _namespace_to_text(op.namespace)
doc_ids[(namespace, op.key)] = generated_doc_id

Expand Down
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ python = ">=3.9,<3.13"
langgraph-checkpoint = "^2.0.10"
redisvl = "^0.3.9"
redis = "^5.2.1"
python-ulid = "^3.0.0"
langgraph = "^0.2.70"

[tool.poetry.group.dev.dependencies]
Expand Down
8 changes: 6 additions & 2 deletions tests/test_async_store.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""Tests for AsyncRedisStore."""

import uuid
from typing import Any, AsyncGenerator, Dict, Sequence, cast

import pytest
from langchain_anthropic import ChatAnthropic
from langchain_core.messages import BaseMessage, HumanMessage
from langchain_core.runnables import RunnableConfig
from langchain_openai import OpenAIEmbeddings
from redis.asyncio import Redis
from ulid import ULID

from langgraph.checkpoint.redis import AsyncRedisSaver
from langgraph.constants import START
from langgraph.graph import MessagesState, StateGraph
from langgraph.store.base import (
Expand Down Expand Up @@ -286,6 +289,7 @@ async def test_list_namespaces(store: AsyncRedisStore) -> None:
for namespace in test_namespaces:
await store.adelete(namespace, "dummy")


# TODO
@pytest.mark.skip(reason="Skipping for v0.0.1 release")
@pytest.mark.asyncio
Expand Down Expand Up @@ -527,7 +531,7 @@ def call_model(
# Store new memories if the user asks the model to remember
if "remember" in last_message.content.lower(): # type:ignore[union-attr]
memory = "User name is Bob"
store.put(namespace, str(uuid.uuid4()), {"data": memory})
store.put(namespace, str(ULID()), {"data": memory})

messages = [{"role": "system", "content": system_msg}]
messages.extend([msg.model_dump() for msg in state["messages"]])
Expand Down
10 changes: 5 additions & 5 deletions tests/test_store.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import uuid
from typing import Any, Dict, Sequence, cast

import pytest
from langchain_anthropic import ChatAnthropic
from langchain_core.messages import BaseMessage, HumanMessage
from langchain_core.runnables import RunnableConfig
from langchain_openai import OpenAIEmbeddings
from redis import Redis
from ulid import ULID

from langgraph.checkpoint.redis import RedisSaver
from langgraph.graph import START, MessagesState, StateGraph
from langgraph.store.base import (
BaseStore,
Expand All @@ -19,9 +22,6 @@
SearchItem,
SearchOp,
)
from redis import Redis

from langgraph.checkpoint.redis import RedisSaver
from langgraph.store.redis import RedisStore
from tests.conftest import VECTOR_TYPES
from tests.embed_test_utils import CharacterEmbeddings
Expand Down Expand Up @@ -464,7 +464,7 @@ def call_model(
# Store new memories if the user asks the model to remember
if "remember" in last_message.content.lower(): # type:ignore[union-attr]
memory = "User name is Bob"
store.put(namespace, str(uuid.uuid4()), {"data": memory})
store.put(namespace, str(ULID()), {"data": memory})

messages = [{"role": "system", "content": system_msg}]
messages.extend([msg.model_dump() for msg in state["messages"]])
Expand Down
8 changes: 4 additions & 4 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
from langchain_core.tools import tool
from langchain_core.tools.base import BaseTool
from langchain_openai import ChatOpenAI
from redis import Redis
from redis.exceptions import ConnectionError as RedisConnectionError

from langgraph.checkpoint.base import (
WRITES_IDX_MAP,
Checkpoint,
CheckpointMetadata,
create_checkpoint,
empty_checkpoint,
)
from langgraph.prebuilt import create_react_agent
from redis import Redis
from redis.exceptions import ConnectionError as RedisConnectionError

from langgraph.checkpoint.redis import BaseRedisSaver, RedisSaver
from langgraph.prebuilt import create_react_agent


@pytest.fixture
Expand Down