Hi everyone,
I am new to LangChain and Python development. I’m working on a project using LangChain and recently installed the latest LangChain packages (langchain 1.2.3 along with langchain-core 1.2.7 and langgraph).
My code imports like this:
from langchain.chains import RetrievalQA
but I get the error:
ModuleNotFoundError: No module named 'langchain.chains'
I suspect this is because LangChain recently changed their packaging and modularized the library, but I couldn’t find clear documentation on how to adjust my imports accordingly.
-
Is langchain.chains now part of langchain_core or another package?
-
How should I update my imports to work with the new modular LangChain v1 packages?
-
Or should I downgrade to an older LangChain version for the monolithic package structure?
As I’m still learning, any help or pointers to official docs/examples with the new package structure would be really appreciated.
Thanks a lot!
hi @Muhammad-Hassan-Deve
have you tried from langchain_classic.chains import RetrievalQA?
And btw "This class is deprecated. Use the 'create_retrieval_chain' constructor"
"""Chain for question-answering against an index.
This class is deprecated. See below for an example implementation using
`create_retrieval_chain`:
```python
from langchain_classic.chains import create_retrieval_chain
from langchain_classic.chains.combine_documents import (
create_stuff_documents_chain,
)
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
retriever = ... # Your retriever
model = ChatOpenAI()
system_prompt = (
"Use the given context to answer the question. "
"If you don't know the answer, say you don't know. "
"Use three sentence maximum and keep the answer concise. "
"Context: {context}"
)
prompt = ChatPromptTemplate.from_messages(
[
("system", system_prompt),
("human", "{input}"),
]
)
question_answer_chain = create_stuff_documents_chain(model, prompt)
chain = create_retrieval_chain(retriever, question_answer_chain)
chain.invoke({"input": query})
```
Example:
```python
from langchain_openai import OpenAI
from langchain_classic.chains import RetrievalQA
from langchain_community.vectorstores import FAISS
from langchain_core.vectorstores import VectorStoreRetriever
retriever = VectorStoreRetriever(vectorstore=FAISS(...))
retrievalQA = RetrievalQA.from_llm(llm=OpenAI(), retriever=retriever)
```
"""
1 Like
Thanks sir , my error solved 
so can you tell me how to reads its official packages and its modules and class and its parameters from its official docs because i don’t know which package have which modules
Example :
langchain_classic.chains RetrivalQA
or
langchain.chains RetrivalQA
Good to hear it helped 
I always look into the source code - I’ve pulled the repositories. The docs sometimes are not up to date.
ok sir ,you have many experience so tell me how to touch upto-date with the packages and its modules ,classes, parameters .
because i am newer and not know proper its packages and modules
I think the best way is to use the doc there LangChain overview | LangChain Reference
But unfortunately some of the parts are still “in progress”, which means “not available” yet.
Then the source code (repository) comes to the rescue.
And of course you can always ask here on the forum.