AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

RePhraseQueryRetriever._Aget_relevant_documents Raises NotImplementedError

The async retrieval method `_aget_relevant_documents` in `RePhraseQueryRetriever` is unimplemented, causing `ainvoke` to raise `NotImplementedError` while the synchronous `invoke` works normally.

highConfidence 95%LangchainAffected V<=1.0.7

Origin Analysis

The async method stub was left unimplemented when the class was ported to `langchain-classic`; it raises `NotImplementedError` instead of mirroring the synchronous logic using async equivalents.
1. Create a FakeRetriever implementing both sync and async `_get_relevant_documents` and `_aget_relevant_documents`.\n2. Create a RunnableLambda that returns a rephrased query.\n3. Instantiate `RePhraseQueryRetriever(retriever=FakeRetriever(), llm_chain=chain)`.\n4. Call `asyncio.run(retriever.ainvoke("what is langchain?"))`.\n5. Observe `NotImplementedError` raised from `_aget_relevant_documents`.

Fixing Code Block

Edge Case Audit

This fix assumes both `self.llm_chain` and `self.retriever` support async invocation. If the wrapped retriever does not implement `_aget_relevant_documents`, its `ainvoke` may still raise `NotImplementedError` or fall back to the synchronous implementation depending on the class. Additionally, forwarding `run_manager.get_child()` in the `config` dict may conflict with callback managers supplied by the caller; ensure that the retriever and LLM chain do not inadvertently override or drop existing callbacks. Rollback: if async invocation issues arise, revert to the previous stub or use the synchronous `invoke` method. Consider adding an async-specific test to prevent regression.

Ecosystem Topology