2

I’m trying to use LangChain in my Python project. My current retriever.py contains:

from langchain.chains import RetrievalQA

But when I run my code, I get:

ImportError: cannot import name 'RetrievalQA' from 'langchain.chains'

My current environment:

Python 3.13.7  
langchain version: 1.0.5  
OS: Windows 11
1
  • Check sys.path for the search path. Commented Nov 9 at 17:18

1 Answer 1

0

In LangChain 1.x, the legacy RetrievalQA class is no longer exported from langchain.chains (API was reorganized). Your import works only on older 0.x versions.

You could Import the legacy class from its module path

from langchain.chains.retrieval_qa.base import RetrievalQA

(Works if the class still ships in your version, but it’s deprecated in favor of the functions above.)

Or you could try and Pin to a compatible older LangChain

pip install "langchain<0.1.0"

Then:

from langchain.chains import RetrievalQA
Sign up to request clarification or add additional context in comments.

1 Comment

from langchain_classic.chains.retrieval_qa.base import RetrievalQA

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.