GraphQAChain Not Recognizing Knowledge Triples in LangChain #26109
Replies: 1 comment
-
Hey @kartikey-codes! I'm here to help you with any bugs, questions, or contributions you have. Let's tackle this together! I found a similar unsolved discussion that might be relevant to your issue: Issue with GraphQAChain: Inability to Recognize Context Beyond 2-3 Graph Triplets [1]. The Here is an example of how to add triples to the from langchain.chains import GraphQAChain
from langchain_community.graphs.networkx_graph import NetworkxEntityGraph, parse_triples
# Create an instance of NetworkxEntityGraph
graph = NetworkxEntityGraph()
# Example knowledge string
knowledge_str = "(subject1, predicate1, object1)<|>(subject2, predicate2, object2)"
# Parse the knowledge triples
triples = parse_triples(knowledge_str)
# Add each triple to the graph
for triple in triples:
graph.add_triple(triple)
# Now you can query the number of nodes
number_of_nodes = graph.get_number_of_nodes()
print(f"Number of nodes: {number_of_nodes}") Ensure that the Additionally, make sure that the To automate the process of creating a graph from text, you can use the from langchain_community.graphs.index_creator import GraphIndexCreator
from langchain_core.language_models import YourLanguageModel
# Initialize your language model
llm = YourLanguageModel()
# Create an instance of GraphIndexCreator
index_creator = GraphIndexCreator(llm=llm)
# Example text
text = "Descartes likes to drive antique scooters and play the mandolin."
# Create the graph from text
graph = index_creator.from_text(text)
# Now you can query the number of nodes
number_of_nodes = graph.get_number_of_nodes()
print(f"Number of nodes: {number_of_nodes}") This approach ensures that the triples are correctly extracted and added to the graph, allowing the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
Description
I'm using
GraphQAChain
fromlangchain.chains
andNetworkxEntityGraph
fromlangchain_community.graphs
to load and query a graph defined in a GML file. This graph contains various triples detailing dependencies and statuses of different backends. However, when querying the number of nodes using the chain, it responds with incorrect information, stating that there are no nodes in the graph.Expected Behavior:
The
GraphQAChain
should accurately interpret the loaded triples and provide correct data about the number of nodes or relevant information stored within the graph structure.Current Behavior:
Despite the graph apparently loading triples correctly (as shown in the console output), the
GraphQAChain
reports that no data is available to count the number of nodes, contradicting the visible loaded data.System Info
Beta Was this translation helpful? Give feedback.
All reactions