|
1 |
| -# Redis Model Store |
| 1 | +# 🧠 Redis Model Store |
2 | 2 |
|
3 | 3 | [](https://opensource.org/licenses/MIT)
|
4 | 4 | 
|
5 | 5 | [](https://github.com/psf/black)
|
6 | 6 | 
|
7 | 7 | [](https://pypi.org/project/redis-model-store/)
|
8 | 8 |
|
9 |
| -`redis-model-store` is a simple Python library designed to handle versioning and serialization of AI/ML models into Redis. It provides a streamlined way to manage your machine learning models in Redis. |
| 9 | +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. |
10 | 10 |
|
11 |
| -## Features |
| 11 | +## ✨ Features |
12 | 12 |
|
13 |
| -- **Pluggable Serialization**: Serialize/deserialize any Python object (Numpy arrays, Scikit-Learn, PyTorch, TensorFlow models, etc.). |
14 |
| -- **Sharding for Large Models**: Splits large serialized payloads into manageable chunks to optimize Redis storage. |
15 |
| -- **Version Management**: Automatically manages model versions in Redis, allowing you to store and retrieve specific versions. |
| 13 | +- **🔄 Automatic Versioning**: Track and manage multiple versions of your models |
| 14 | +- **📦 Smart Storage**: Large models are automatically sharded for optimal storage |
| 15 | +- **🔌 Pluggable Serialization**: Works with any Python object (NumPy, PyTorch, TensorFlow, etc.) |
| 16 | +- **🏃♂️ High Performance**: Efficient storage and retrieval using Redis pipelining |
| 17 | +- **🛡️ Safe Operations**: Atomic operations with automatic cleanup on failures |
16 | 18 |
|
| 19 | +## 🚀 Quick Start |
| 20 | + |
| 21 | +### Installation |
17 | 22 |
|
18 |
| -## Installation |
19 | 23 | ```bash
|
| 24 | +# Using pip |
20 | 25 | pip install redis-model-store
|
| 26 | + |
| 27 | +# Or using poetry |
| 28 | +poetry add redis-model-store |
21 | 29 | ```
|
22 | 30 |
|
23 |
| -## Usage |
| 31 | +### Basic Usage |
24 | 32 |
|
25 |
| -See the fully detailed [example notebook](docs/redis_model_store.ipynb) for more assistance in getting started. |
| 33 | +Here's a simple example using scikit-learn: |
26 | 34 |
|
27 |
| -### Init the ModelStore |
28 | 35 | ```python
|
29 |
| -from model_store import ModelStore |
30 | 36 | from redis import Redis
|
| 37 | +from model_store import ModelStore |
| 38 | +from sklearn.ensemble import RandomForestClassifier |
| 39 | + |
| 40 | +# Connect to Redis and initialize store |
| 41 | +redis = Redis(host="localhost", port=6379) |
| 42 | +store = ModelStore(redis) |
| 43 | + |
| 44 | +# Train your model |
| 45 | +model = RandomForestClassifier() |
| 46 | +model.fit(X_train, y_train) |
31 | 47 |
|
32 |
| -# Initialize the Redis client |
33 |
| -redis_client = Redis.from_url("redis://localhost:6379") |
| 48 | +# Save model with version tracking |
| 49 | +version = store.save_model( |
| 50 | + model, |
| 51 | + name="my-classifier", |
| 52 | + description="Random forest trained on dataset v1" |
| 53 | +) |
| 54 | + |
| 55 | +# List available models |
| 56 | +models = store.list_models() |
| 57 | +print(f"Available models: {models}") |
| 58 | + |
| 59 | +# Load latest version |
| 60 | +model = store.load_model("my-classifier") |
34 | 61 |
|
35 |
| -# Initialize the ModelStore with (optional) shard size |
36 |
| -model_store = ModelStore(redis_client, shard_size=1012 * 100) |
| 62 | +# Load specific version |
| 63 | +model = store.load_model("my-classifier", version=version) |
| 64 | + |
| 65 | +# View all versions |
| 66 | +versions = store.get_all_versions("my-classifier") |
| 67 | +for v in versions: |
| 68 | + print(f"Version: {v.version}, Created: {v.created_at}") |
37 | 69 | ```
|
38 | 70 |
|
39 |
| -### Store a model |
40 |
| -You can store any serializable Python object. |
41 |
| -```python |
42 |
| -from sklearn.ensemble import RandomForestClassifier |
43 |
| -from sklearn.datasets import load_iris |
44 |
| -from sklearn.model_selection import train_test_split |
| 71 | +## 🛠️ Contributing |
45 | 72 |
|
46 |
| -# Load sample data |
47 |
| -iris = load_iris() |
48 |
| -X_train, X_test, y_train, y_test = train_test_split( |
49 |
| - iris.data, iris.target, test_size=0.2, random_state=42 |
50 |
| -) |
| 73 | +We welcome contributions! Here's how to get started: |
51 | 74 |
|
52 |
| -# Train a simple RandomForest model |
53 |
| -model = RandomForestClassifier() |
54 |
| -model.fit(X_train, y_train) |
| 75 | +### Development Setup |
55 | 76 |
|
56 |
| -# Save the model to Redis |
57 |
| -version = model_store.save_model(model, name="random_forest", description="Random forest classifier model") |
| 77 | +1. Clone the repository: |
| 78 | +```bash |
| 79 | +git clone https://github.com/redis-applied-ai/redis-model-store.git |
| 80 | +cd redis-model-store |
58 | 81 | ```
|
59 | 82 |
|
60 |
| -### Load models |
61 |
| -```python |
62 |
| -# Grab the latest model |
63 |
| -model = model_store.load_model(name="random_forest") |
| 83 | +2. Install poetry if you haven't: |
| 84 | +```bash |
| 85 | +curl -sSL https://install.python-poetry.org | python3 - |
| 86 | +``` |
64 | 87 |
|
65 |
| -# Grab a specific model version |
66 |
| -model = model_store.load_model(name="random_forest", version=version) |
| 88 | +3. Install dependencies: |
| 89 | +```bash |
| 90 | +poetry install --all-extras |
| 91 | +``` |
| 92 | + |
| 93 | +### Linting and Tests |
| 94 | + |
| 95 | +```bash |
| 96 | +poetry run format |
| 97 | +poetry run check-mypy |
| 98 | +poetry run test |
| 99 | +poetry run test-verbose |
67 | 100 | ```
|
68 | 101 |
|
69 |
| -## |
| 102 | +### Making Changes |
| 103 | + |
| 104 | +1. Create a new branch: |
| 105 | +```bash |
| 106 | +git checkout -b feat/your-feature-name |
| 107 | +``` |
| 108 | + |
| 109 | +2. Make your changes and ensure: |
| 110 | + - All tests pass (covering new functionality) |
| 111 | + - Code is formatted |
| 112 | + - Type hints are valid |
| 113 | + - Examples/docs added as notebooks to the `docs/` directory. |
| 114 | + |
| 115 | +3. Push changes and open a PR |
| 116 | + |
| 117 | + |
| 118 | +## 📚 Documentation |
| 119 | + |
| 120 | +For more usage examples check out tbhis [Example Notebook](docs/redis_model_store.ipynb). |
0 commit comments