Skip to content

Commit 8535371

Browse files
authored
Add LangChain v1 support (#91)
This addresses issue #86 by enabling compatibility with LangChain v1.0+.
1 parent fd75d7d commit 8535371

File tree

12 files changed

+362
-209
lines changed

12 files changed

+362
-209
lines changed

.github/workflows/_compile_integration_test.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ jobs:
2020
strategy:
2121
matrix:
2222
python-version:
23-
- "3.9"
2423
- "3.10"
2524
- "3.11"
2625
- "3.12"
26+
- "3.13"
2727
name: "poetry run pytest -m compile tests/integration_tests #${{ matrix.python-version }}"
2828
steps:
2929
- uses: actions/checkout@v4
3030

31+
- name: Install system dependencies
32+
shell: bash
33+
run: |
34+
sudo apt-get update
35+
sudo apt-get install -y libopenblas-dev liblapack-dev gfortran
36+
3137
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
3238
uses: "./.github/actions/poetry_setup"
3339
with:

.github/workflows/_lint.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ jobs:
2929
# Starting new jobs is also relatively slow,
3030
# so linting on fewer versions makes CI faster.
3131
python-version:
32-
- "3.9"
33-
- "3.12"
32+
- "3.10"
33+
- "3.13"
3434
steps:
3535
- uses: actions/checkout@v4
3636

37+
- name: Install system dependencies
38+
shell: bash
39+
run: |
40+
sudo apt-get update
41+
sudo apt-get install -y libopenblas-dev liblapack-dev gfortran
42+
3743
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
3844
uses: "./.github/actions/poetry_setup"
3945
with:

.github/workflows/_test.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ jobs:
2020
strategy:
2121
matrix:
2222
python-version:
23-
- "3.9"
2423
- "3.10"
2524
- "3.11"
2625
- "3.12"
26+
- "3.13"
2727
name: "make test #${{ matrix.python-version }}"
2828
steps:
2929
- uses: actions/checkout@v4
3030

31+
- name: Install system dependencies
32+
shell: bash
33+
run: |
34+
sudo apt-get update
35+
sudo apt-get install -y libopenblas-dev liblapack-dev gfortran
36+
3137
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
3238
uses: "./.github/actions/poetry_setup"
3339
with:

libs/redis/docs/cache.ipynb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,10 @@
7979
},
8080
{
8181
"cell_type": "code",
82-
"execution_count": 3,
82+
"execution_count": null,
8383
"metadata": {},
8484
"outputs": [],
85-
"source": [
86-
"import time\n",
87-
"from getpass import getpass\n",
88-
"\n",
89-
"from langchain.globals import set_llm_cache\n",
90-
"from langchain.schema import Generation\n",
91-
"from langchain_openai import OpenAI, OpenAIEmbeddings\n",
92-
"\n",
93-
"from langchain_redis import RedisCache, RedisSemanticCache"
94-
]
85+
"source": "import time\nfrom getpass import getpass\n\nfrom langchain_core.globals import set_llm_cache\nfrom langchain_core.outputs import Generation\nfrom langchain_openai import OpenAI, OpenAIEmbeddings\n\nfrom langchain_redis import RedisCache, RedisSemanticCache"
9586
},
9687
{
9788
"cell_type": "markdown",

libs/redis/docs/chat_history.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@
7575
"metadata": {},
7676
"outputs": [],
7777
"source": [
78+
"import logging\n",
79+
"\n",
7880
"from langchain_core.chat_history import BaseChatMessageHistory\n",
7981
"from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
8082
"from langchain_core.runnables.history import RunnableWithMessageHistory\n",
8183
"from langchain_openai import ChatOpenAI\n",
8284
"\n",
8385
"from langchain_redis import RedisChatMessageHistory\n",
8486
"\n",
85-
"import logging\n",
86-
"\n",
8787
"logging.getLogger('redisvl').setLevel(logging.WARNING)"
8888
]
8989
},

libs/redis/docs/kitchensink.ipynb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,10 @@
9696
},
9797
{
9898
"cell_type": "code",
99-
"execution_count": 20,
99+
"execution_count": null,
100100
"metadata": {},
101101
"outputs": [],
102-
"source": [
103-
"from langchain_redis import RedisVectorStore, RedisCache, RedisChatMessageHistory\n",
104-
"from langchain_openai import OpenAIEmbeddings, OpenAI\n",
105-
"from langchain.globals import set_llm_cache\n",
106-
"from langchain_core.prompts import PromptTemplate\n",
107-
"from langchain_core.output_parsers import StrOutputParser\n",
108-
"import wikipedia"
109-
]
102+
"source": "from langchain_redis import RedisVectorStore, RedisCache, RedisChatMessageHistory\nfrom langchain_openai import OpenAIEmbeddings, OpenAI\nfrom langchain_core.globals import set_llm_cache\nfrom langchain_core.prompts import PromptTemplate\nfrom langchain_core.output_parsers import StrOutputParser\nimport wikipedia"
110103
},
111104
{
112105
"cell_type": "markdown",
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
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+

libs/redis/docs/langgraph_self_rag.ipynb

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -160,46 +160,11 @@
160160
},
161161
{
162162
"cell_type": "code",
163-
"execution_count": 18,
163+
"execution_count": null,
164164
"id": "565a6d44-2c9f-4fff-b1ec-eea05df9350d",
165165
"metadata": {},
166-
"outputs": [
167-
{
168-
"name": "stdout",
169-
"output_type": "stream",
170-
"text": [
171-
"00:26:48 redisvl.index.index INFO Index already exists, not overwriting.\n"
172-
]
173-
}
174-
],
175-
"source": [
176-
"from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
177-
"from langchain_community.document_loaders import WebBaseLoader\n",
178-
"from langchain_openai import OpenAIEmbeddings\n",
179-
"\n",
180-
"from langchain_redis import RedisVectorStore\n",
181-
"\n",
182-
"urls = [\n",
183-
" \"https://lilianweng.github.io/posts/2023-06-23-agent/\",\n",
184-
" \"https://lilianweng.github.io/posts/2023-03-15-prompt-engineering/\",\n",
185-
" \"https://lilianweng.github.io/posts/2023-10-25-adv-attack-llm/\",\n",
186-
"]\n",
187-
"\n",
188-
"docs = [WebBaseLoader(url).load() for url in urls]\n",
189-
"docs_list = [item for sublist in docs for item in sublist]\n",
190-
"\n",
191-
"text_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(\n",
192-
" chunk_size=250, chunk_overlap=0\n",
193-
")\n",
194-
"doc_splits = text_splitter.split_documents(docs_list)\n",
195-
"\n",
196-
"# Add to vectorDB\n",
197-
"vectorstore = RedisVectorStore.from_documents(\n",
198-
" doc_splits, OpenAIEmbeddings(), redis_url=REDIS_URL, index_name=\"rag-redis\"\n",
199-
")\n",
200-
"\n",
201-
"retriever = vectorstore.as_retriever()"
202-
]
166+
"outputs": [],
167+
"source": "from langchain_text_splitters import RecursiveCharacterTextSplitter\nfrom langchain_community.document_loaders import WebBaseLoader\nfrom langchain_openai import OpenAIEmbeddings\n\nfrom langchain_redis import RedisVectorStore\n\nurls = [\n \"https://lilianweng.github.io/posts/2023-06-23-agent/\",\n \"https://lilianweng.github.io/posts/2023-03-15-prompt-engineering/\",\n \"https://lilianweng.github.io/posts/2023-10-25-adv-attack-llm/\",\n]\n\ndocs = [WebBaseLoader(url).load() for url in urls]\ndocs_list = [item for sublist in docs for item in sublist]\n\ntext_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(\n chunk_size=250, chunk_overlap=0\n)\ndoc_splits = text_splitter.split_documents(docs_list)\n\n# Add to vectorDB\nvectorstore = RedisVectorStore.from_documents(\n doc_splits, OpenAIEmbeddings(), redis_url=REDIS_URL, index_name=\"rag-redis\"\n)\n\nretriever = vectorstore.as_retriever()"
203168
},
204169
{
205170
"cell_type": "markdown",

libs/redis/docs/vectorstores.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@
4545
},
4646
{
4747
"cell_type": "code",
48-
"execution_count": 2,
48+
"execution_count": null,
4949
"metadata": {},
5050
"outputs": [],
5151
"source": [
5252
"# ruff: noqa: E501\n",
5353
"import os\n",
5454
"\n",
55-
"from langchain.docstore.document import Document\n",
55+
"from langchain_core.documents import Document\n",
5656
"from sklearn.datasets import fetch_20newsgroups\n",
5757
"\n",
5858
"from langchain_redis import RedisVectorStore"

0 commit comments

Comments
 (0)