-
Notifications
You must be signed in to change notification settings - Fork 815
Description
Type of issue
issue / bug
Language
Python
Description
Summary
Multiple documentation files contain outdated import statements using from langchain.retrievers import ..., which is incompatible with LangChain 1.0+. According to the v1 migration guide, all retriever imports should now use langchain_classic.retrievers instead.
Impact
23 documentation files contain code examples that will fail when users try to run them with LangChain 1.0+.
Error Users Will Encounter
ImportError: cannot import name 'ContextualCompressionRetriever' from 'langchain.retrievers'or
ModuleNotFoundError: No module named 'langchain.retrievers'Affected Files
Document Transformers (7 files)
/src/oss/python/integrations/document_transformers/cross_encoder_reranker.mdx:61/src/oss/python/integrations/document_transformers/openvino_rerank.mdx:294/src/oss/python/integrations/document_transformers/voyageai-reranker.mdx:295/src/oss/python/integrations/document_transformers/jina_rerank.mdx:68/src/oss/python/integrations/document_transformers/volcengine_rerank.mdx:298/src/oss/python/integrations/document_transformers/dashscope_rerank.mdx:266/src/oss/python/integrations/document_transformers/infinity_rerank.mdx:283
Retrievers (5 files)
/src/oss/python/integrations/retrievers/merger_retriever.mdx:13/src/oss/python/integrations/retrievers/flashrank-reranker.mdx:274/src/oss/python/integrations/retrievers/llmlingua.mdx:264/src/oss/python/integrations/retrievers/fleet_context.mdx:20/src/oss/python/integrations/retrievers/re_phrase.mdx:18
Provider Integrations (11 files)
/src/oss/python/integrations/providers/chroma.mdx:34/src/oss/python/integrations/providers/cohere.mdx:28,143/src/oss/python/integrations/providers/ragatouille.mdx:107/src/oss/python/integrations/providers/wikipedia.mdx:35/src/oss/python/integrations/providers/outline.mdx:23/src/oss/python/integrations/providers/vespa.mdx:28/src/oss/python/integrations/providers/metal.mdx:18/src/oss/python/integrations/providers/breebs.mdx:14/src/oss/python/integrations/providers/pubmed.mdx:27/src/oss/python/integrations/providers/chaindesk.mdx:18
Callbacks (1 file)
/src/oss/python/integrations/callbacks/uptrain.mdx:65
Current (Incorrect) Code
# ❌ This DOES NOT work in LangChain 1.0+
from langchain.retrievers import (
ContextualCompressionRetriever,
DocumentCompressorPipeline,
MergerRetriever,
)Expected (Correct) Code
According to the LangChain v1 migration guide (lines 26, 38-39):
# ✅ This works in LangChain 1.0+
from langchain_classic.retrievers import (
ContextualCompressionRetriever,
MergerRetriever,
)
from langchain_classic.retrievers.document_compressors import DocumentCompressorPipelineOr for ContextualCompressionRetriever specifically, the correct import path is:
# ✅ Alternative correct import (as seen in cohere-reranker.mdx:279-281)
from langchain_classic.retrievers.contextual_compression import (
ContextualCompressionRetriever,
)Steps to Reproduce
- Install LangChain 1.0+ (e.g.,
pip install langchain>=1.0.0) - Try to run any code example from the affected documentation pages
- Observe ImportError or ModuleNotFoundError
Example: merger_retriever.mdx
Location: Lines 13-16 in /src/oss/python/integrations/retrievers/merger_retriever.mdx
Current code:
from langchain.retrievers import (
ContextualCompressionRetriever,
DocumentCompressorPipeline,
MergerRetriever,
)Should be:
from langchain_classic.retrievers import (
ContextualCompressionRetriever,
MergerRetriever,
)
from langchain_classic.retrievers.document_compressors import DocumentCompressorPipelineReference Documentation
The LangChain v1 migration guide clearly states:
Retrievers (e.g.
MultiQueryRetrieveror anything from the previouslangchain.retrieversmodule)If you were using any of the following from the
langchainpackage, you'll need to installlangchain-classicand update your imports
Suggested Fix
- Replace all instances of
from langchain.retrievers importwithfrom langchain_classic.retrievers importin the affected files - Update installation instructions to include:
pip install langchain-classic - Add a note about LangChain 1.0+ compatibility requirements
Additional Context
- One file already uses the correct import pattern:
/src/oss/python/integrations/retrievers/cohere-reranker.mdx:279-281 - Migration guide files (langchain-v1.mdx, releases/langchain-v1.mdx) intentionally show old imports as examples of "what not to do" - these should NOT be changed
Environment
- LangChain Version: 1.0.3+
- Documentation Repository: https://github.com/langchain-ai/docs
- Affected Documentation Section: OSS Python integrations
Search Query Used
grep -r "from langchain\.retrievers import" src/oss/python/This returns 26 total matches, of which 23 are problematic (3 are in migration guides showing old vs new code).