-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Description
Checked other resources
- This is a bug, not a usage question.
- I added a clear and descriptive title that summarizes this issue.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
- This is not related to the langchain-community package.
- I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
- I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.
Example Code
Code to reproduce the issue:
# imports
from langchain.chains.history_aware_retriever import create_history_aware_retriever
from langchain.retrievers import MergerRetriever
from langchain_core.vectorstores import InMemoryVectorStore
from langchain_openai import OpenAIEmbeddings
from langchain import hub
from langchain_core.documents import Document
from langchain_openai import ChatOpenAI
# simple retrievere
documents = [Document(id="1", page_content="foo")]
vector_store = InMemoryVectorStore(OpenAIEmbeddings())
vector_store.add_documents(documents=documents)
retriever = vector_store.as_retriever()
# history aware retriever
rephrase_prompt = hub.pull("langchain-ai/chat-langchain-rephrase")
history_aware_retriever = create_history_aware_retriever(
llm=ChatOpenAI(model="gpt-4.1-mini"),
retriever=chain.retrievers['docs'],
prompt=rephrase_prompt,
)
# hybrid retriever
hybrid_retriever = MergerRetriever(
retrievers=[
retriever,
history_aware_retriever
]
)
Error Message and Stack Trace (if applicable)
---------------------------------------------------------------------------
ValidationError Traceback (most recent call last)
Cell In[22], line 28
21 history_aware_retriever = create_history_aware_retriever(
22 llm=ChatOpenAI(model="gpt-4.1-mini"),
23 retriever=chain.retrievers['docs'],
24 prompt=rephrase_prompt,
25 )
27 # hybrid retriever
---> 28 hybrid_retriever = MergerRetriever(
29 retrievers=[
30 retriever,
31 history_aware_retriever
32 ]
33 )
File ~/OMD/llm-assistant-base/.venv/lib/python3.12/site-packages/langchain_core/load/serializable.py:115, in Serializable.__init__(self, *args, **kwargs)
113 def __init__(self, *args: Any, **kwargs: Any) -> None:
114 """""" # noqa: D419
--> 115 super().__init__(*args, **kwargs)
File ~/OMD/llm-assistant-base/.venv/lib/python3.12/site-packages/pydantic/main.py:253, in BaseModel.__init__(self, **data)
251 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
252 __tracebackhide__ = True
--> 253 validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
254 if self is not validated_self:
255 warnings.warn(
256 'A custom validator is returning a value other than `self`.\n'
257 "Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.\n"
258 'See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.',
259 stacklevel=2,
260 )
ValidationError: 1 validation error for MergerRetriever
retrievers.1
Input should be a valid dictionary or instance of BaseRetriever [type=model_type, input_value=RunnableBinding(bound=Run...'}, config_factories=[]), input_type=RunnableBinding]
For further information visit https://errors.pydantic.dev/2.11/v/model_type
Description
Obviously, MergerRetriever
cannot accept RunnableBinding
as an input retriever because of pydantic type check.
And RetrieverOutputLike
typing for returning value does not help.
System Info
System Information
OS: Darwin
OS Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041
Python Version: 3.12.11 (main, Jun 3 2025, 15:41:47) [Clang 17.0.0 (clang-1700.0.13.3)]
Package Information
langchain_core: 0.3.76
langchain: 0.3.27
langchain_community: 0.3.30
langsmith: 0.4.4
langchain_openai: 0.3.30
langchain_postgres: 0.0.15
langchain_text_splitters: 0.3.9
Optional packages not installed
langserve
Other Dependencies
aiohttp<4.0.0,>=3.8.3: Installed. No version info available.
async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
asyncpg>=0.30.0: Installed. No version info available.
dataclasses-json<0.7.0,>=0.6.7: Installed. No version info available.
httpx: 0.28.1
httpx-sse<1.0.0,>=0.4.0: Installed. No version info available.
jsonpatch<2.0,>=1.33: Installed. No version info available.
langchain-anthropic;: Installed. No version info available.
langchain-aws;: Installed. No version info available.
langchain-azure-ai;: Installed. No version info available.
langchain-cohere;: Installed. No version info available.
langchain-community;: Installed. No version info available.
langchain-core<0.4.0,>=0.2.13: Installed. No version info available.
langchain-core<1.0.0,>=0.3.72: Installed. No version info available.
langchain-core<1.0.0,>=0.3.74: Installed. No version info available.
langchain-core<2.0.0,>=0.3.75: Installed. No version info available.
langchain-deepseek;: Installed. No version info available.
langchain-fireworks;: Installed. No version info available.
langchain-google-genai;: Installed. No version info available.
langchain-google-vertexai;: Installed. No version info available.
langchain-groq;: Installed. No version info available.
langchain-huggingface;: Installed. No version info available.
langchain-mistralai;: Installed. No version info available.
langchain-ollama;: Installed. No version info available.
langchain-openai;: Installed. No version info available.
langchain-perplexity;: Installed. No version info available.
langchain-text-splitters<1.0.0,>=0.3.9: Installed. No version info available.
langchain-together;: Installed. No version info available.
langchain-xai;: Installed. No version info available.
langchain<2.0.0,>=0.3.27: Installed. No version info available.
langsmith-pyo3: Installed. No version info available.
langsmith<1.0.0,>=0.1.125: Installed. No version info available.
langsmith>=0.1.17: Installed. No version info available.
langsmith>=0.3.45: Installed. No version info available.
numpy<3,>=1.21: Installed. No version info available.
numpy>=1.26.2;: Installed. No version info available.
numpy>=2.1.0;: Installed. No version info available.
openai-agents: Installed. No version info available.
openai<2.0.0,>=1.99.9: Installed. No version info available.
opentelemetry-api: 1.37.0
opentelemetry-exporter-otlp-proto-http: 1.37.0
opentelemetry-sdk: 1.37.0
orjson: 3.11.2
packaging: 24.2
packaging>=23.2: Installed. No version info available.
pgvector<0.4,>=0.2.5: Installed. No version info available.
psycopg-pool<4,>=3.2.1: Installed. No version info available.
psycopg<4,>=3: Installed. No version info available.
pydantic: 2.11.7
pydantic-settings<3.0.0,>=2.10.1: Installed. No version info available.
pydantic<3.0.0,>=2.7.4: Installed. No version info available.
pydantic>=2.7.4: Installed. No version info available.
pytest: 8.4.1
PyYAML<7.0.0,>=5.3.0: Installed. No version info available.
PyYAML>=5.3: Installed. No version info available.
requests: 2.32.5
requests-toolbelt: 1.0.0
requests<3,>=2: Installed. No version info available.
requests<3.0.0,>=2.32.5: Installed. No version info available.
rich: 14.1.0
SQLAlchemy<3,>=1.4: Installed. No version info available.
sqlalchemy<3,>=2: Installed. No version info available.
SQLAlchemy<3.0.0,>=1.4.0: Installed. No version info available.
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
tiktoken<1,>=0.7: Installed. No version info available.
typing-extensions>=4.7: Installed. No version info available.
zstandard: 0.23.0