|
| 1 | +# Migration Guide: LangChain v1.0 |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +`langchain-redis` v0.3.0 adds support for LangChain v1.0. This guide helps you migrate your applications to use the latest version. |
| 6 | + |
| 7 | +## What Changed |
| 8 | + |
| 9 | +### Breaking Changes |
| 10 | + |
| 11 | +#### 1. Python Version Requirement |
| 12 | + |
| 13 | +**Minimum Python version is now 3.10+** |
| 14 | + |
| 15 | +- **Python 3.9 is no longer supported** (reaches end-of-life October 2025) |
| 16 | +- **Supported versions**: Python 3.10, 3.11, 3.12, 3.13 |
| 17 | + |
| 18 | +**Action Required:** |
| 19 | +- If you're on Python 3.9, upgrade to Python 3.10 or higher |
| 20 | +- If you're on Python 3.10-3.13, no action needed |
| 21 | + |
| 22 | +#### 2. Dependency Updates |
| 23 | + |
| 24 | +**Updated to LangChain v1.0** |
| 25 | + |
| 26 | +```toml |
| 27 | +langchain-core = "^1.0" # was ^0.3 |
| 28 | +``` |
| 29 | + |
| 30 | +**Action Required:** |
| 31 | +```bash |
| 32 | +# Update your requirements.txt or pyproject.toml |
| 33 | +pip install --upgrade langchain-redis langchain-core |
| 34 | + |
| 35 | +# Or with poetry |
| 36 | +poetry update langchain-redis langchain-core |
| 37 | +``` |
| 38 | + |
| 39 | +## What Did NOT Change |
| 40 | + |
| 41 | +**Good news**: The `langchain-redis` API remains completely unchanged! |
| 42 | + |
| 43 | +All three main components work seamlessly without any code changes: |
| 44 | + |
| 45 | +- ✅ **`RedisVectorStore`** - No changes required |
| 46 | +- ✅ **`RedisCache` / `RedisSemanticCache`** - No changes required |
| 47 | +- ✅ **`RedisChatMessageHistory`** - No changes required |
| 48 | +- ✅ **`RedisConfig`** - No changes required |
| 49 | + |
| 50 | +Your existing code will continue to work as-is after updating dependencies. |
| 51 | + |
| 52 | +## Migration Steps |
| 53 | + |
| 54 | +### Step 1: Check Your Python Version |
| 55 | + |
| 56 | +```bash |
| 57 | +python --version |
| 58 | +``` |
| 59 | + |
| 60 | +If you're on Python 3.9, upgrade to 3.10+: |
| 61 | + |
| 62 | +```bash |
| 63 | +# Using pyenv (recommended) |
| 64 | +pyenv install 3.10.15 # or 3.11, 3.12, 3.13 |
| 65 | +pyenv global 3.10.15 |
| 66 | + |
| 67 | +# Recreate your virtual environment |
| 68 | +python -m venv venv |
| 69 | +source venv/bin/activate # On Windows: venv\Scripts\activate |
| 70 | +``` |
| 71 | + |
| 72 | +### Step 2: Update Dependencies |
| 73 | + |
| 74 | +**Option A: Using pip** |
| 75 | +```bash |
| 76 | +pip install --upgrade langchain-redis langchain-core |
| 77 | +``` |
| 78 | + |
| 79 | +**Option B: Using poetry** |
| 80 | +```bash |
| 81 | +# Update pyproject.toml |
| 82 | +# python = ">=3.10,<3.14" |
| 83 | +# langchain-core = "^1.0" |
| 84 | + |
| 85 | +poetry lock |
| 86 | +poetry install |
| 87 | +``` |
| 88 | + |
| 89 | +**Option C: Using requirements.txt** |
| 90 | +```txt |
| 91 | +langchain-redis>=0.3.0 |
| 92 | +langchain-core>=1.0 |
| 93 | +``` |
| 94 | + |
| 95 | +### Step 4: Test Your Application |
| 96 | + |
| 97 | +```bash |
| 98 | +# Run your test suite |
| 99 | +pytest tests/ |
| 100 | + |
| 101 | +# Verify your application works |
| 102 | +python your_app.py |
| 103 | +``` |
| 104 | + |
| 105 | +## Example Migration |
| 106 | + |
| 107 | +### Before (works with both v0.2.x and v0.3.x): |
| 108 | + |
| 109 | +```python |
| 110 | +from langchain.globals import set_llm_cache |
| 111 | +from langchain.schema import Generation |
| 112 | +from langchain_openai import OpenAI |
| 113 | +from langchain_redis import RedisCache |
| 114 | + |
| 115 | +# Initialize cache |
| 116 | +cache = RedisCache(redis_url="redis://localhost:6379") |
| 117 | +set_llm_cache(cache) |
| 118 | + |
| 119 | +# Use as normal |
| 120 | +llm = OpenAI() |
| 121 | +result = llm.invoke("Hello!") |
| 122 | +``` |
| 123 | + |
| 124 | +### After (recommended for v0.3.0+): |
| 125 | + |
| 126 | +```python |
| 127 | +# Note that `langchain` became `langchain_core` |
| 128 | +from langchain_core.globals import set_llm_cache |
| 129 | +from langchain_core.outputs import Generation |
| 130 | +from langchain_openai import OpenAI |
| 131 | +from langchain_redis import RedisCache |
| 132 | + |
| 133 | +# Initialize cache (no changes needed) |
| 134 | +cache = RedisCache(redis_url="redis://localhost:6379") |
| 135 | +set_llm_cache(cache) |
| 136 | + |
| 137 | +# Use as normal (no changes needed) |
| 138 | +llm = OpenAI() |
| 139 | +result = llm.invoke("Hello!") |
| 140 | +``` |
| 141 | + |
| 142 | +## Troubleshooting |
| 143 | + |
| 144 | +### Issue: Import errors after upgrade |
| 145 | + |
| 146 | +**Symptom:** |
| 147 | +```python |
| 148 | +ImportError: cannot import name 'set_llm_cache' from 'langchain.globals' |
| 149 | +``` |
| 150 | + |
| 151 | +**Solution:** |
| 152 | +Update your imports to use `langchain_core.globals`: |
| 153 | +```python |
| 154 | +from langchain_core.globals import set_llm_cache |
| 155 | +``` |
| 156 | + |
| 157 | +### Issue: Python version conflict |
| 158 | + |
| 159 | +**Symptom:** |
| 160 | +``` |
| 161 | +ERROR: Package 'langchain-redis' requires a different Python: 3.9.x not in '>=3.10,<3.14' |
| 162 | +``` |
| 163 | + |
| 164 | +**Solution:** |
| 165 | +Upgrade to Python 3.10 or higher (see Step 1 above). |
| 166 | + |
| 167 | +### Issue: Dependency resolver conflicts |
| 168 | + |
| 169 | +**Symptom:** |
| 170 | +``` |
| 171 | +ERROR: Cannot install langchain-redis and langchain-core because these package versions have conflicting dependencies. |
| 172 | +``` |
| 173 | + |
| 174 | +**Solution:** |
| 175 | +```bash |
| 176 | +# Clear dependency cache |
| 177 | +pip cache purge |
| 178 | + |
| 179 | +# Install with updated resolver |
| 180 | +pip install --upgrade --force-reinstall langchain-redis langchain-core |
| 181 | +``` |
| 182 | + |
| 183 | +## FAQ |
| 184 | + |
| 185 | +### Q: Do I need to change my application code? |
| 186 | + |
| 187 | +**A:** No! The `langchain-redis` API is unchanged. You only need to update dependencies and optionally update import paths for future compatibility. |
| 188 | + |
| 189 | +### Q: What if I can't upgrade from Python 3.9? |
| 190 | + |
| 191 | +**A:** Stay on `langchain-redis` v0.3.x until you can upgrade Python. Python 3.9 reaches end-of-life in October 2025, so we recommend planning your upgrade soon. |
| 192 | + |
| 193 | +### Q: Will my existing Redis data still work? |
| 194 | + |
| 195 | +**A:** Yes! There are no changes to how data is stored in Redis. All existing indices, caches, and chat histories will continue to work. |
| 196 | + |
| 197 | +### Q: Can I use langchain-redis v0.3.0 with langchain-core 0.3.x? |
| 198 | + |
| 199 | +**A:** No, v0.3.0 requires langchain-core ^1.0. If you need to stay on langchain-core 0.3.x, use langchain-redis v0.2.x. |
| 200 | + |
| 201 | +### Q: Are there any performance improvements in v0.3.0? |
| 202 | + |
| 203 | +**A:** The migration to LangChain v1.0 includes upstream performance improvements and bug fixes. `langchain-redis` itself has no performance-related changes in this release. |
| 204 | + |
0 commit comments