Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QUERY_CONFIG_TYPE is no longer supported in llama_index. #28683

Open
5 tasks done
91d906h4 opened this issue Dec 12, 2024 · 0 comments
Open
5 tasks done

QUERY_CONFIG_TYPE is no longer supported in llama_index. #28683

91d906h4 opened this issue Dec 12, 2024 · 0 comments

Comments

@91d906h4
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • 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

import networkx as nx
from langchain_community.llms.ollama import Ollama
from langchain.chains.retrieval_qa.base import RetrievalQA
from langchain_community.retrievers import LlamaIndexGraphRetriever

# Initialize the LLM
llm = Ollama(model="llama3.2")

# Create a knowledge graph
graph = 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 retriever
graph_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

class LlamaIndexGraphRetriever(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:
            from llama_index.core.base.response.schema import Response
            from llama_index.core.composability.base import (
                QUERY_CONFIG_TYPE,
                ComposableGraph,
            )
        except ImportError:
            raise ImportError(
                "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 configs
        for query_config in self.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 nodes
        docs = []
        for source_node in response.source_nodes:
            metadata = source_node.metadata or {}
            docs.append(
                Document(page_content=source_node.get_content(), metadata=metadata)
            )
        return docs

Description

  1. I'm trying to build the GraphRAG with langchain_community.
  2. I imported LlamaIndexGraphRetriever class from langchain_community.retrievers
  3. I used function get_relevant_documents to retrieval the graph but got error.
  4. I install the latest version and several old versions of llama-index, but couldn't find the version with QUERY_CONFIG_TYPE.

System Info

networkx==3.2.1
langchain_community==0.3.11
langchain==0.3.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant