Skip to content

Commit

Permalink
Model store documentation and improvements (#1)
Browse files Browse the repository at this point in the history
* readme

* formatting

* add tests and some refactoring

* fix python versions in CICD

* udpates to workflows for consistency

* model_store to redis_model_store

* update readme example

* update workflow

* use yaml over yml

* add yamls back
  • Loading branch information
tylerhutcherson authored Jan 22, 2025
1 parent 231ce40 commit 75f479a
Show file tree
Hide file tree
Showing 25 changed files with 1,324 additions and 753 deletions.
File renamed without changes.
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml → .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
branches:
- main

env:
POETRY_VERSION: "1.8.3"

jobs:
check:
name: Style-check ${{ matrix.python-version }}
Expand All @@ -32,7 +35,7 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.3
version: ${{ env.POETRY_VERSION }}
- name: Install dependencies
run: |
poetry install --all-extras
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
- uses: release-drafter/release-drafter@v5
with:
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
config-name: release-drafter-config.yml
config-name: release-drafter-config.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.3

- name: Set Version
run: poetry version ${{ github.event.inputs.version }}
version: ${{ env.POETRY_VERSION }}

- name: Build package
run: poetry build
Expand All @@ -52,7 +49,7 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.3
version: ${{ env.POETRY_VERSION }}

- uses: actions/download-artifact@v4
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
branches:
- main

env:
POETRY_VERSION: "1.8.3"

jobs:
test:
name: Python ${{ matrix.python-version }} - ${{ matrix.connection }} [redis-stack ${{matrix.redis-stack-version}}]
Expand All @@ -15,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9, 3.10, 3.11]
python-version: ["3.9", "3.10", "3.11"]
connection: ['hiredis', 'plain']
redis-stack-version: ['6.2.6-v9', 'latest', 'edge']

Expand All @@ -36,7 +39,7 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.3
version: ${{ env.PYTHON_VERSION }}

- name: Install dependencies
run: |
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ docs/old_redis_model_store.ipynb
docs/test.py

__pycache__/
.mypy_cache/
.mypy_cache/
.pytest_cache/
.coverage
htmlcov/

dump.rdb
120 changes: 119 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,120 @@
# Redis Model Store
# 🧠 Redis Model Store

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![Language](https://img.shields.io/github/languages/top/redis-applied-ai/redis-model-store)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
![GitHub last commit](https://img.shields.io/github/last-commit/redis-applied-ai/redis-model-store)
[![pypi](https://badge.fury.io/py/redisvl.svg)](https://pypi.org/project/redis-model-store/)

Store, version, and manage your ML models in Redis with ease. `redis-model-store` provides a simple yet powerful interface for handling machine learning model artifacts in Redis.

## ✨ Features

- **🔄 Automatic Versioning**: Track and manage multiple versions of your models
- **📦 Smart Storage**: Large models are automatically sharded for optimal storage
- **🔌 Pluggable Serialization**: Works with any Python object (NumPy, PyTorch, TensorFlow, etc.)
- **🏃‍♂️ High Performance**: Efficient storage and retrieval using Redis pipelining
- **🛡️ Safe Operations**: Atomic operations with automatic cleanup on failures

## 🚀 Quick Start

### Installation

```bash
# Using pip
pip install redis-model-store

# Or using poetry
poetry add redis-model-store
```

### Basic Usage

Here's a simple example using scikit-learn:

```python
from redis import Redis
from redis_model_store import ModelStore
from sklearn.ensemble import RandomForestClassifier

# Connect to Redis and initialize store
redis = Redis(host="localhost", port=6379)
store = ModelStore(redis)

# Train your model
model = RandomForestClassifier()
model.fit(X_train, y_train)

# Save model with version tracking
version = store.save_model(
model,
name="my-classifier",
description="Random forest trained on dataset v1"
)

# List available models
models = store.list_models()
print(f"Available models: {models}")

# Load latest version
model = store.load_model("my-classifier")

# Load specific version
model = store.load_model("my-classifier", version=version)

# View all versions
versions = store.get_all_versions("my-classifier")
for v in versions:
print(f"Version: {v.version}, Created: {v.created_at}")
```

## 🛠️ Contributing

We welcome contributions! Here's how to get started:

### Development Setup

1. Clone the repository:
```bash
git clone https://github.com/redis-applied-ai/redis-model-store.git
cd redis-model-store
```

2. Install poetry if you haven't:
```bash
curl -sSL https://install.python-poetry.org | python3 -
```

3. Install dependencies:
```bash
poetry install --all-extras
```

### Linting and Tests

```bash
poetry run format
poetry run check-mypy
poetry run test
poetry run test-verbose
```

### Making Changes

1. Create a new branch:
```bash
git checkout -b feat/your-feature-name
```

2. Make your changes and ensure:
- All tests pass (covering new functionality)
- Code is formatted
- Type hints are valid
- Examples/docs added as notebooks to the `docs/` directory.

3. Push changes and open a PR


## 📚 Documentation

For more usage examples check out tbhis [Example Notebook](docs/redis_model_store.ipynb).
21 changes: 21 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import pytest

from testcontainers.compose import DockerCompose


@pytest.fixture(scope="session", autouse=True)
def redis_container():
# Set the default Redis version if not already set
os.environ.setdefault("REDIS_VERSION", "edge")

compose = DockerCompose("tests", compose_file_name="docker-compose.yaml", pull=True)
compose.start()

redis_host, redis_port = compose.get_service_host_and_port("redis", 6379)
redis_url = f"redis://{redis_host}:{redis_port}"
os.environ["REDIS_URL"] = redis_url

yield compose

compose.stop()
Loading

0 comments on commit 75f479a

Please sign in to comment.