langgraph-checkpoint-redis


Namelanggraph-checkpoint-redis JSON
Version 0.0.1 PyPI version JSON
download
home_pagehttps://www.github.com/redis-developer/langgraph-redis
SummaryLibrary with a Redis implementation of LangGraph checkpoint saver.
upload_time2025-02-10 22:36:36
maintainerNone
docs_urlNone
authorRedis Inc.
requires_python<3.13,>=3.9
licenseMIT
keywords ai redis redis-client vector-database vector-search
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LangGraph Redis

This repository contains Redis implementations for LangGraph, providing both Checkpoint Savers and Stores functionality.

## Overview

The project consists of two main components:
1. **Redis Checkpoint Savers**: Implementations for storing and managing checkpoints using Redis
2. **Redis Stores**: Redis-backed key-value stores with optional vector search capabilities

## Dependencies

The project requires the following main dependencies:
- `redis>=5.2.1`
- `redisvl>=0.3.7`
- `langgraph-checkpoint>=2.0.10`

## Installation

Install the library using pip:

```bash
pip install langgraph-checkpoint-redis
```

## Redis Checkpoint Savers

### Important Notes

> [!IMPORTANT]
> When using Redis checkpointers for the first time, make sure to call `.setup()` method on them to create required indices. See examples below.

### Standard Implementation

```python
from langgraph.checkpoint.redis import RedisSaver

write_config = {"configurable": {"thread_id": "1", "checkpoint_ns": ""}}
read_config = {"configurable": {"thread_id": "1"}}

with RedisSaver.from_conn_string("redis://localhost:6379") as checkpointer:
    # Call setup to initialize indices
    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, {}, {})

    # Retrieve checkpoint
    loaded_checkpoint = checkpointer.get(read_config)

    # List all checkpoints
    checkpoints = list(checkpointer.list(read_config))
```

### Async Implementation

```python
from langgraph.checkpoint.redis.aio import AsyncRedisSaver

async def main():
    write_config = {"configurable": {"thread_id": "1", "checkpoint_ns": ""}}
    read_config = {"configurable": {"thread_id": "1"}}

    async with AsyncRedisSaver.from_conn_string("redis://localhost:6379") as checkpointer:
        # Call setup to initialize indices
        await checkpointer.asetup()
        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, {}, {})

        # Retrieve checkpoint
        loaded_checkpoint = await checkpointer.aget(read_config)

        # List all checkpoints
        checkpoints = [c async for c in checkpointer.alist(read_config)]

# Run the async main function
import asyncio
asyncio.run(main())
```

### Shallow Implementations

Shallow Redis checkpoint savers store only the latest checkpoint in Redis. These implementations are useful when retaining a complete checkpoint history is unnecessary.

```python
from langgraph.checkpoint.redis.shallow import ShallowRedisSaver
# For async version: from langgraph.checkpoint.redis.ashallow import AsyncShallowRedisSaver

write_config = {"configurable": {"thread_id": "1", "checkpoint_ns": ""}}
read_config = {"configurable": {"thread_id": "1"}}

with ShallowRedisSaver.from_conn_string("redis://localhost:6379") as checkpointer:
    checkpointer.setup()
    # ... rest of the implementation follows similar pattern
```

## Redis Stores

Redis Stores provide a persistent key-value store with optional vector search capabilities.

### Synchronous Implementation

```python
from langgraph.store.redis import RedisStore

# Basic usage
with RedisStore.from_conn_string("redis://localhost:6379") as store:
    store.setup()
    # Use the store...

# With vector search configuration
index_config = {
    "dims": 1536,  # Vector dimensions
    "distance_type": "cosine",  # Distance metric
    "fields": ["text"],  # Fields to index
}

with RedisStore.from_conn_string("redis://localhost:6379", index=index_config) as store:
    store.setup()
    # Use the store with vector search capabilities...
```

### Async Implementation

```python
from langgraph.store.redis.aio import AsyncRedisStore

async def main():
    async with AsyncRedisStore.from_conn_string("redis://localhost:6379") as store:
        await store.setup()
        # Use the store asynchronously...

asyncio.run(main())
```

## Implementation Details

### Indexing

The Redis implementation creates these main indices:

1. **Checkpoints Index**: Stores checkpoint metadata and versioning
2. **Channel Values Index**: Stores channel-specific data
3. **Writes Index**: Tracks pending writes and intermediate states

For Redis Stores with vector search:
1. **Store Index**: Main key-value store
2. **Vector Index**: Optional vector embeddings for similarity search

## Contributing

We welcome contributions! Here's how you can help:

### Development Setup

1. Clone the repository:
   ```bash
   git clone https://github.com/langchain-ai/langgraph
   cd langgraph
   ```

2. Install dependencies:
   ```bash
   poetry install
   ```

### Available Commands

The project includes several make commands for development:

- **Testing**:
  ```bash
  make test           # Run all tests
  make test_watch    # Run tests in watch mode
  ```

- **Linting and Formatting**:
  ```bash
  make lint          # Run all linters
  make lint_diff     # Lint only changed files
  make lint_package  # Lint only the package
  make lint_tests    # Lint only tests
  make format        # Format all files
  make format_diff   # Format only changed files
  ```

### Contribution Guidelines

1. Create a new branch for your changes
2. Write tests for new functionality
3. Ensure all tests pass: `make test`
4. Format your code: `make format`
5. Run linting checks: `make lint`
6. Submit a pull request with a clear description of your changes
7. Follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for commit messages

## License

This project is licensed under the MIT License.
            

Raw data

            {
    "_id": null,
    "home_page": "https://www.github.com/redis-developer/langgraph-redis",
    "name": "langgraph-checkpoint-redis",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.13,>=3.9",
    "maintainer_email": null,
    "keywords": "ai, redis, redis-client, vector-database, vector-search",
    "author": "Redis Inc.",
    "author_email": "applied.ai@redis.com",
    "download_url": "https://files.pythonhosted.org/packages/03/95/90a31f5fb9bdf6fab7f37dd84c5d288fc12c75595ab3bcee096fa8e037d5/langgraph_checkpoint_redis-0.0.1.tar.gz",
    "platform": null,
    "description": "# LangGraph Redis\n\nThis repository contains Redis implementations for LangGraph, providing both Checkpoint Savers and Stores functionality.\n\n## Overview\n\nThe project consists of two main components:\n1. **Redis Checkpoint Savers**: Implementations for storing and managing checkpoints using Redis\n2. **Redis Stores**: Redis-backed key-value stores with optional vector search capabilities\n\n## Dependencies\n\nThe project requires the following main dependencies:\n- `redis>=5.2.1`\n- `redisvl>=0.3.7`\n- `langgraph-checkpoint>=2.0.10`\n\n## Installation\n\nInstall the library using pip:\n\n```bash\npip install langgraph-checkpoint-redis\n```\n\n## Redis Checkpoint Savers\n\n### Important Notes\n\n> [!IMPORTANT]\n> When using Redis checkpointers for the first time, make sure to call `.setup()` method on them to create required indices. See examples below.\n\n### Standard Implementation\n\n```python\nfrom langgraph.checkpoint.redis import RedisSaver\n\nwrite_config = {\"configurable\": {\"thread_id\": \"1\", \"checkpoint_ns\": \"\"}}\nread_config = {\"configurable\": {\"thread_id\": \"1\"}}\n\nwith RedisSaver.from_conn_string(\"redis://localhost:6379\") as checkpointer:\n    # Call setup to initialize indices\n    checkpointer.setup()\n    checkpoint = {\n        \"v\": 1,\n        \"ts\": \"2024-07-31T20:14:19.804150+00:00\",\n        \"id\": \"1ef4f797-8335-6428-8001-8a1503f9b875\",\n        \"channel_values\": {\n            \"my_key\": \"meow\",\n            \"node\": \"node\"\n        },\n        \"channel_versions\": {\n            \"__start__\": 2,\n            \"my_key\": 3,\n            \"start:node\": 3,\n            \"node\": 3\n        },\n        \"versions_seen\": {\n            \"__input__\": {},\n            \"__start__\": {\n                \"__start__\": 1\n            },\n            \"node\": {\n                \"start:node\": 2\n            }\n        },\n        \"pending_sends\": [],\n    }\n\n    # Store checkpoint\n    checkpointer.put(write_config, checkpoint, {}, {})\n\n    # Retrieve checkpoint\n    loaded_checkpoint = checkpointer.get(read_config)\n\n    # List all checkpoints\n    checkpoints = list(checkpointer.list(read_config))\n```\n\n### Async Implementation\n\n```python\nfrom langgraph.checkpoint.redis.aio import AsyncRedisSaver\n\nasync def main():\n    write_config = {\"configurable\": {\"thread_id\": \"1\", \"checkpoint_ns\": \"\"}}\n    read_config = {\"configurable\": {\"thread_id\": \"1\"}}\n\n    async with AsyncRedisSaver.from_conn_string(\"redis://localhost:6379\") as checkpointer:\n        # Call setup to initialize indices\n        await checkpointer.asetup()\n        checkpoint = {\n            \"v\": 1,\n            \"ts\": \"2024-07-31T20:14:19.804150+00:00\",\n            \"id\": \"1ef4f797-8335-6428-8001-8a1503f9b875\",\n            \"channel_values\": {\n                \"my_key\": \"meow\",\n                \"node\": \"node\"\n            },\n            \"channel_versions\": {\n                \"__start__\": 2,\n                \"my_key\": 3,\n                \"start:node\": 3,\n                \"node\": 3\n            },\n            \"versions_seen\": {\n                \"__input__\": {},\n                \"__start__\": {\n                    \"__start__\": 1\n                },\n                \"node\": {\n                    \"start:node\": 2\n                }\n            },\n            \"pending_sends\": [],\n        }\n\n        # Store checkpoint\n        await checkpointer.aput(write_config, checkpoint, {}, {})\n\n        # Retrieve checkpoint\n        loaded_checkpoint = await checkpointer.aget(read_config)\n\n        # List all checkpoints\n        checkpoints = [c async for c in checkpointer.alist(read_config)]\n\n# Run the async main function\nimport asyncio\nasyncio.run(main())\n```\n\n### Shallow Implementations\n\nShallow Redis checkpoint savers store only the latest checkpoint in Redis. These implementations are useful when retaining a complete checkpoint history is unnecessary.\n\n```python\nfrom langgraph.checkpoint.redis.shallow import ShallowRedisSaver\n# For async version: from langgraph.checkpoint.redis.ashallow import AsyncShallowRedisSaver\n\nwrite_config = {\"configurable\": {\"thread_id\": \"1\", \"checkpoint_ns\": \"\"}}\nread_config = {\"configurable\": {\"thread_id\": \"1\"}}\n\nwith ShallowRedisSaver.from_conn_string(\"redis://localhost:6379\") as checkpointer:\n    checkpointer.setup()\n    # ... rest of the implementation follows similar pattern\n```\n\n## Redis Stores\n\nRedis Stores provide a persistent key-value store with optional vector search capabilities.\n\n### Synchronous Implementation\n\n```python\nfrom langgraph.store.redis import RedisStore\n\n# Basic usage\nwith RedisStore.from_conn_string(\"redis://localhost:6379\") as store:\n    store.setup()\n    # Use the store...\n\n# With vector search configuration\nindex_config = {\n    \"dims\": 1536,  # Vector dimensions\n    \"distance_type\": \"cosine\",  # Distance metric\n    \"fields\": [\"text\"],  # Fields to index\n}\n\nwith RedisStore.from_conn_string(\"redis://localhost:6379\", index=index_config) as store:\n    store.setup()\n    # Use the store with vector search capabilities...\n```\n\n### Async Implementation\n\n```python\nfrom langgraph.store.redis.aio import AsyncRedisStore\n\nasync def main():\n    async with AsyncRedisStore.from_conn_string(\"redis://localhost:6379\") as store:\n        await store.setup()\n        # Use the store asynchronously...\n\nasyncio.run(main())\n```\n\n## Implementation Details\n\n### Indexing\n\nThe Redis implementation creates these main indices:\n\n1. **Checkpoints Index**: Stores checkpoint metadata and versioning\n2. **Channel Values Index**: Stores channel-specific data\n3. **Writes Index**: Tracks pending writes and intermediate states\n\nFor Redis Stores with vector search:\n1. **Store Index**: Main key-value store\n2. **Vector Index**: Optional vector embeddings for similarity search\n\n## Contributing\n\nWe welcome contributions! Here's how you can help:\n\n### Development Setup\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/langchain-ai/langgraph\n   cd langgraph\n   ```\n\n2. Install dependencies:\n   ```bash\n   poetry install\n   ```\n\n### Available Commands\n\nThe project includes several make commands for development:\n\n- **Testing**:\n  ```bash\n  make test           # Run all tests\n  make test_watch    # Run tests in watch mode\n  ```\n\n- **Linting and Formatting**:\n  ```bash\n  make lint          # Run all linters\n  make lint_diff     # Lint only changed files\n  make lint_package  # Lint only the package\n  make lint_tests    # Lint only tests\n  make format        # Format all files\n  make format_diff   # Format only changed files\n  ```\n\n### Contribution Guidelines\n\n1. Create a new branch for your changes\n2. Write tests for new functionality\n3. Ensure all tests pass: `make test`\n4. Format your code: `make format`\n5. Run linting checks: `make lint`\n6. Submit a pull request with a clear description of your changes\n7. Follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for commit messages\n\n## License\n\nThis project is licensed under the MIT License.",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Library with a Redis implementation of LangGraph checkpoint saver.",
    "version": "0.0.1",
    "project_urls": {
        "Homepage": "https://www.github.com/redis-developer/langgraph-redis",
        "Repository": "https://www.github.com/redis-developer/langgraph-redis"
    },
    "split_keywords": [
        "ai",
        " redis",
        " redis-client",
        " vector-database",
        " vector-search"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0deb1ce2331a9aea3f26f468d56727acf7d3468b6d1d46371f0c3028b8ad5250",
                "md5": "d3d2dce6ac4f177ee1d95bfa41b22ecc",
                "sha256": "608ecdcc461345463b91d818e469bf32d4b31c8af56e03d2ef4bb90d54991ddb"
            },
            "downloads": -1,
            "filename": "langgraph_checkpoint_redis-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d3d2dce6ac4f177ee1d95bfa41b22ecc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.9",
            "size": 43031,
            "upload_time": "2025-02-10T22:36:35",
            "upload_time_iso_8601": "2025-02-10T22:36:35.081877Z",
            "url": "https://files.pythonhosted.org/packages/0d/eb/1ce2331a9aea3f26f468d56727acf7d3468b6d1d46371f0c3028b8ad5250/langgraph_checkpoint_redis-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "039590a31f5fb9bdf6fab7f37dd84c5d288fc12c75595ab3bcee096fa8e037d5",
                "md5": "4e158f8532f3a675e04d8d975f6c1253",
                "sha256": "75d1e73a4a45b0457ded1a2c9bfd529fa936a3ac71ca2ea861524eb3bbe31772"
            },
            "downloads": -1,
            "filename": "langgraph_checkpoint_redis-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "4e158f8532f3a675e04d8d975f6c1253",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.9",
            "size": 28116,
            "upload_time": "2025-02-10T22:36:36",
            "upload_time_iso_8601": "2025-02-10T22:36:36.813111Z",
            "url": "https://files.pythonhosted.org/packages/03/95/90a31f5fb9bdf6fab7f37dd84c5d288fc12c75595ab3bcee096fa8e037d5/langgraph_checkpoint_redis-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-10 22:36:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "redis-developer",
    "github_project": "langgraph-redis",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "langgraph-checkpoint-redis"
}
        
Elapsed time: 0.50781s