You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I searched the LangChain documentation with the integrated search.
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).
Example Code
importnetworkxasnxfromlangchain_community.llms.ollamaimportOllamafromlangchain.chains.retrieval_qa.baseimportRetrievalQAfromlangchain_community.retrieversimportLlamaIndexGraphRetriever# Initialize the LLMllm=Ollama(model="llama3.2")
# Create a knowledge graphgraph=nx.Graph()
# Add nodes (countries)graph.add_node("United States", capital="Washington D.C.")
graph.add_node("Canada", capital="Ottawa")
graph.add_node("France", capital="Paris")
# Add relationships (borders)graph.add_edge("United States", "Canada")
graph.add_edge("France", "United States", relation="allies")
# Initialize the graph retrievergraph_retriever=LlamaIndexGraphRetriever(graph=graph, max_retriever_size=3)
graph_retriever.get_relevant_documents("what is the relationship between france and United States?")
Error Message and Stack Trace (if applicable)
gchain-ollama package and should be used instead. To use it run pip install -U :class:~langchain-ollamaand import asfrom :class:~langchain_ollama import OllamaLLM``. llm = Ollama(model="llama3.2") E:\Project\.Share\2024-12-11 Graph RAG\test\index.py:31: LangChainDeprecationWarning: The method BaseRetriever.get_relevant_documents was deprecated in langchain-core 0.1.46 and will be removed in 1.0. Use :meth:~invoke` instead.
graph_retriever.get_relevant_documents("what is the relationship between france and United States?")
Traceback (most recent call last):
File "D:\python\Lib\site-packages\langchain_community\retrievers\llama_index.py", line 62, in _get_relevant_documents
from llama_index.core.composability.base import (
ImportError: cannot import name 'QUERY_CONFIG_TYPE' from 'llama_index.core.composability.base' (D:\python\Lib\site-packages\llama_index\core\composability\base.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\Project.Share\2024-12-11 Graph RAG\test\index.py", line 31, in
graph_retriever.get_relevant_documents("what is the relationship between france and United States?")
File "D:\python\Lib\site-packages\langchain_core_api\deprecation.py", line 182, in warning_emitting_wrapper
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\langchain_core\retrievers.py", line 409, in get_relevant_documents
return self.invoke(query, config, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\langchain_core\retrievers.py", line 266, in invoke
raise e
File "D:\python\Lib\site-packages\langchain_core\retrievers.py", line 259, in invoke
result = self._get_relevant_documents(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\langchain_community\retrievers\llama_index.py", line 67, in _get_relevant_documents
raise ImportError(
ImportError: You need to install pip install llama-index to use this retriever.
In addition, here is the code in D:\python\Lib\site-packages\langchain_community\retrievers\llama_index.py
classLlamaIndexGraphRetriever(BaseRetriever):
"""`LlamaIndex` graph data structure retriever. It is used for question-answering with sources over an LlamaIndex graph data structure."""graph: Any=None"""LlamaIndex graph to query."""query_configs: List[Dict] =Field(default_factory=list)
"""List of query configs to pass to the query method."""def_get_relevant_documents(
self, query: str, *, run_manager: CallbackManagerForRetrieverRun
) ->List[Document]:
"""Get documents relevant for a query."""try:
fromllama_index.core.base.response.schemaimportResponsefromllama_index.core.composability.baseimport (
QUERY_CONFIG_TYPE,
ComposableGraph,
)
exceptImportError:
raiseImportError(
"You need to install `pip install llama-index` to use this retriever."
)
graph=cast(ComposableGraph, self.graph)
# for now, inject response_mode="no_text" into query configsforquery_configinself.query_configs:
query_config["response_mode"] ="no_text"query_configs=cast(List[QUERY_CONFIG_TYPE], self.query_configs)
response=graph.query(query, query_configs=query_configs)
response=cast(Response, response)
# parse source nodesdocs= []
forsource_nodeinresponse.source_nodes:
metadata=source_node.metadataor {}
docs.append(
Document(page_content=source_node.get_content(), metadata=metadata)
)
returndocs
Description
I'm trying to build the GraphRAG with langchain_community.
I imported LlamaIndexGraphRetriever class from langchain_community.retrievers
I used function get_relevant_documents to retrieval the graph but got error.
I install the latest version and several old versions of llama-index, but couldn't find the version with QUERY_CONFIG_TYPE.
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
In addition, here is the code in
D:\python\Lib\site-packages\langchain_community\retrievers\llama_index.py
Description
LlamaIndexGraphRetriever
class fromlangchain_community.retrievers
get_relevant_documents
to retrieval the graph but got error.System Info
networkx==3.2.1
langchain_community==0.3.11
langchain==0.3.11
The text was updated successfully, but these errors were encountered: