langchain - 💡(How to fix) Fix bug: RePhraseQueryRetriever._aget_relevant_documents raises NotImplementedError

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

The sync method _get_relevant_documents (line 61) has a full implementation — it invokes the LLM chain to rephrase the query, then calls the inner retriever. However, _aget_relevant_documents (line 86–92) is just a stub:

https://github.com/langchain-ai/langchain/blob/a1e2daf098a96699d3b8a191698e67c4137f79c9/libs/langchain/langchain_classic/retrievers/re_phraser.py#L86-L92

Suggested fix: Mirror the sync implementation using ainvoke:

async def _aget_relevant_documents(self, query, *, run_manager):
    re_phrased_question = await self.llm_chain.ainvoke(
        query, {"callbacks": run_manager.get_child()}
    )
    return await self.retriever.ainvoke(
        re_phrased_question,
        config={"callbacks": run_manager.get_child()},
    )

I have a fix ready with tests and would be happy to open a PR if confirmed. Thanks!

Error Message

Error Message and Stack Trace (if applicable)

Root Cause

The sync method _get_relevant_documents (line 61) has a full implementation — it invokes the LLM chain to rephrase the query, then calls the inner retriever. However, _aget_relevant_documents (line 86–92) is just a stub:

https://github.com/langchain-ai/langchain/blob/a1e2daf098a96699d3b8a191698e67c4137f79c9/libs/langchain/langchain_classic/retrievers/re_phraser.py#L86-L92

Suggested fix: Mirror the sync implementation using ainvoke:

async def _aget_relevant_documents(self, query, *, run_manager):
    re_phrased_question = await self.llm_chain.ainvoke(
        query, {"callbacks": run_manager.get_child()}
    )
    return await self.retriever.ainvoke(
        re_phrased_question,
        config={"callbacks": run_manager.get_child()},
    )

I have a fix ready with tests and would be happy to open a PR if confirmed. Thanks!

Fix Action

Fix / Workaround

  • 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 posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Code Example

from langchain_core.documents import Document
from langchain_core.retrievers import BaseRetriever
from langchain_core.runnables import RunnableLambda
from langchain_classic.retrievers.re_phraser import RePhraseQueryRetriever


class FakeRetriever(BaseRetriever):
    def _get_relevant_documents(self, query, *, run_manager=None):
        return [Document(page_content=f"relevant: {query}")]

    async def _aget_relevant_documents(self, query, *, run_manager=None):
        return [Document(page_content=f"relevant: {query}")]


chain = RunnableLambda(lambda q: "rephrased query")
retriever = RePhraseQueryRetriever(retriever=FakeRetriever(), llm_chain=chain)

# ✅ Sync works fine
result = retriever.invoke("what is langchain?")
print(f"Sync OK: {len(result)} doc(s)")

# ❌ Async raises NotImplementedError
import asyncio
result = asyncio.run(retriever.ainvoke("what is langchain?"))

---



---

async def _aget_relevant_documents(self, query, *, run_manager):
    re_phrased_question = await self.llm_chain.ainvoke(
        query, {"callbacks": run_manager.get_child()}
    )
    return await self.retriever.ainvoke(
        re_phrased_question,
        config={"callbacks": run_manager.get_child()},
    )
RAW_BUFFERClick to expand / collapse

Submission checklist

  • 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 posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

#37620

Reproduction Steps / Example Code (Python)

from langchain_core.documents import Document
from langchain_core.retrievers import BaseRetriever
from langchain_core.runnables import RunnableLambda
from langchain_classic.retrievers.re_phraser import RePhraseQueryRetriever


class FakeRetriever(BaseRetriever):
    def _get_relevant_documents(self, query, *, run_manager=None):
        return [Document(page_content=f"relevant: {query}")]

    async def _aget_relevant_documents(self, query, *, run_manager=None):
        return [Document(page_content=f"relevant: {query}")]


chain = RunnableLambda(lambda q: "rephrased query")
retriever = RePhraseQueryRetriever(retriever=FakeRetriever(), llm_chain=chain)

# ✅ Sync works fine
result = retriever.invoke("what is langchain?")
print(f"Sync OK: {len(result)} doc(s)")

# ❌ Async raises NotImplementedError
import asyncio
result = asyncio.run(retriever.ainvoke("what is langchain?"))

Error Message and Stack Trace (if applicable)

Description

The sync method _get_relevant_documents (line 61) has a full implementation — it invokes the LLM chain to rephrase the query, then calls the inner retriever. However, _aget_relevant_documents (line 86–92) is just a stub:

https://github.com/langchain-ai/langchain/blob/a1e2daf098a96699d3b8a191698e67c4137f79c9/libs/langchain/langchain_classic/retrievers/re_phraser.py#L86-L92

Suggested fix: Mirror the sync implementation using ainvoke:

async def _aget_relevant_documents(self, query, *, run_manager):
    re_phrased_question = await self.llm_chain.ainvoke(
        query, {"callbacks": run_manager.get_child()}
    )
    return await self.retriever.ainvoke(
        re_phrased_question,
        config={"callbacks": run_manager.get_child()},
    )

I have a fix ready with tests and would be happy to open a PR if confirmed. Thanks!

System Info

OS: Darwin OS Version: Darwin Kernel Version 25.5.0 Python Version: 3.12.11

Package Information

langchain_core: 1.4.0 langchain_classic: 1.0.7

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING