Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKQA over structured dataSQLRetrieval-augmented generation (RAG)Interacting with APIsChatbotsExtractionSummarizationTaggingWeb scrapingSynthetic data generationGraph queryingDiffbot Graph TransformerArangoDB QA chainNeo4j DB QA chainFalkorDBQAChainHugeGraph QA ChainKuzuQAChainMemgraph QA chainNebulaGraphQAChainNetworkX Graph QAGraphSparqlQAChainNeptune Open Cypher QA ChainGraph queryingNetworkX Graph QAOn this pageNetworkX Graph QAThis notebook goes over how to do question answering over a graph data structure.Create the graph‚ÄãIn this section, we construct an example graph. At the moment, this works best for small pieces of text.from langchain.indexes import GraphIndexCreatorfrom langchain.llms import OpenAIfrom langchain.document_loaders import TextLoaderindex_creator = GraphIndexCreator(llm=OpenAI(temperature=0))with open("../../../modules/state_of_the_union.txt") as f:    all_text = f.read()We will use just a small snippet, because extracting the knowledge triplets is a bit intensive at the moment.text = "\n".join(all_text.split("\n\n")[105:108])text    'It won‚Äôt look like much, but if you stop and look closely, you‚Äôll see a ‚ÄúField of dreams,‚Äù the ground on which America‚Äôs future will be built. \nThis is where Intel, the American company that helped build Silicon Valley, is going to build its $20 billion semiconductor ‚Äúmega site‚Äù. \nUp to eight state-of-the-art factories in one place. 10,000 new good-paying jobs. 'graph = index_creator.from_text(text)We can inspect the created graph.graph.get_triples()    [('Intel', '$20 billion semiconductor "mega site"', 'is going to build'),     ('Intel', 'state-of-the-art factories', 'is building'),     ('Intel', '10,000 new good-paying jobs', 'is creating'),     ('Intel', 'Silicon Valley', 'is helping build'),     ('Field of dreams',      "America's future will be built",      'is the ground
This notebook goes over how to do question answering over a graph data structure.
This notebook goes over how to do question answering over a graph data structure. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKQA over structured dataSQLRetrieval-augmented generation (RAG)Interacting with APIsChatbotsExtractionSummarizationTaggingWeb scrapingSynthetic data generationGraph queryingDiffbot Graph TransformerArangoDB QA chainNeo4j DB QA chainFalkorDBQAChainHugeGraph QA ChainKuzuQAChainMemgraph QA chainNebulaGraphQAChainNetworkX Graph QAGraphSparqlQAChainNeptune Open Cypher QA ChainGraph queryingNetworkX Graph QAOn this pageNetworkX Graph QAThis notebook goes over how to do question answering over a graph data structure.Create the graph‚ÄãIn this section, we construct an example graph. At the moment, this works best for small pieces of text.from langchain.indexes import GraphIndexCreatorfrom langchain.llms import OpenAIfrom langchain.document_loaders import TextLoaderindex_creator = GraphIndexCreator(llm=OpenAI(temperature=0))with open("../../../modules/state_of_the_union.txt") as f:    all_text = f.read()We will use just a small snippet, because extracting the knowledge triplets is a bit intensive at the moment.text = "\n".join(all_text.split("\n\n")[105:108])text    'It won‚Äôt look like much, but if you stop and look closely, you‚Äôll see a ‚ÄúField of dreams,‚Äù the ground on which America‚Äôs future will be built. \nThis is where Intel, the American company that helped build Silicon Valley, is going to build its $20 billion semiconductor ‚Äúmega site‚Äù. \nUp to eight state-of-the-art factories in one place. 10,000 new good-paying jobs. 'graph = index_creator.from_text(text)We can inspect the created graph.graph.get_triples()    [('Intel', '$20 billion semiconductor "mega site"', 'is going to build'),     ('Intel', 'state-of-the-art factories', 'is building'),     ('Intel', '10,000 new good-paying jobs', 'is creating'),     ('Intel', 'Silicon Valley', 'is helping build'),     ('Field of dreams',      "America's future will be built",      'is the ground