documents = SimpleDirectoryReader("./data").load_data() kg_index = KnowledgeGraphIndex.from_documents(documents=documents, storage_context=storage_context, max_triplets_per_chunk=2, space_name=space_name, edge_types=edge_types, llm=llm, embed_model=embed_model, rel_prop_names=rel_prop_names, tags=tags, include_embeddings=True) kg_index.storage_context.persist(persist_dir='./storage_graph') hybrid_query_engine = kg_index.as_query_engine(include_text=True, llm=llm, response_mode="tree_summarize", embedding_mode="hybrid", similarity_top_k=3, explore_global_knowledge=True) query_text = "What is education?" response = hybrid_query_engine.query(query_text)
Query failed. Query: WITH map{`true`: '-[', `false`: '<-['} AS arrow_l, map{`true`: ']->', `false`: ']-'} AS arrow_r, map{`relationship`: "relationship"} AS edge_type_map MATCH p=(start)-[e:`relationship`*..2]-() WHERE id(start) IN $subjs WITH start, id(start) AS vid, nodes(p) AS nodes, e AS rels [...]
# Connect to Nebula Graph os.environ["GRAPHD_HOST"] = "127.0.0.1" os.environ["NEBULA_USER"] = "root" os.environ["NEBULA_PASSWORD"] = "nebula" os.environ["NEBULA_ADDRESS"] = "127.0.0.1:9669" %reload_ext ngql connection_string = f"--address {os.environ['GRAPHD_HOST']} --port 9669 --user root --password {os.environ['NEBULA_PASSWORD']}" %ngql {connection_string}
%ngql CREATE SPACE IF NOT EXISTS my_test_space(vid_type=FIXED_STRING(256), partition_num=1, replica_factor=1); %ngql SHOW SPACES; %%ngql USE my_test_space; CREATE TAG IF NOT EXISTS entity(name string); CREATE EDGE IF NOT EXISTS relationship(relationship string); %ngql CREATE TAG INDEX IF NOT EXISTS entity_index ON entity(name(256));
space_name = "my_test_space" edge_types, rel_prop_names = ["relationship"], ["relationship"] tags = ["entity"] graph_store = NebulaGraphStore( space_name=space_name, edge_types=edge_types, rel_prop_names=rel_prop_names, tags=tags, ) storage_context = StorageContext.from_defaults(graph_store=graph_store) documents = SimpleDirectoryReader("./data").load_data() kg_index = KnowledgeGraphIndex.from_documents(documents=documents, storage_context=storage_context, max_triplets_per_chunk=2, space_name=space_name, edge_types=edge_types, llm=llm, embed_model=embed_model, rel_prop_names=rel_prop_names, tags=tags, include_embeddings=True, show_progress=True) kg_index.storage_context.persist(persist_dir='./storage_graph')
kg_index.get_networkx_graph()
Query failed. Query: WITH map{`true`: '-[', `false`: '<-['} AS arrow_l, map{`true`: ']->', `false`: ']-'} AS arrow_r, map{`relationship`: "relationship"} AS edge_type_map MATCH p=(start)-[e:`relationship`*..1]-() WHERE id(start) IN $subjs WITH start, id(start) AS vid, nodes(p) AS nodes, e AS rels, length(p) AS rel_count, arrow_l, arrow_r, edge_type_map WITH REDUCE(s = vid + '{', key IN [key_ in ['name', ''] WHERE properties(start)[key_] IS NOT NULL] | s + key + ': ' + COALESCE(TOSTRING(properties(start)[key]), 'null') + ', ') + '}' AS subj, [item in [i IN RANGE(0, rel_count - 1)|[nodes[i], nodes[i + 1], rels[i], typeid(rels[i]) > 0, type(rels[i]) ]] | [ arrow_l[tostring(item[3])] + item[4] + ':' + REDUCE(s = '{', key IN SPLIT(edge_type_map[item[4]], ',') | s + key + ': ' + COALESCE(TOSTRING(properties(item[2])[key]), 'null') + ', ') + '}' + arrow_r[tostring(item[3])], REDUCE(s = id(item[1]) + '{', key IN [key_ in ['name', ''] WHERE properties(item[1])[key_] IS NOT NULL] | s + key + ': ' + COALESCE(TOSTRING(properties(item[1])[key]), 'null') + ', ') + '}' ] ] AS rels WITH REPLACE(subj, ', }', '}') AS subj, REDUCE(acc = collect(NULL), l in rels | acc + l) AS flattened_rels RETURN subj, REPLACE(REDUCE(acc = subj, l in flattened_rels | acc + ' ' + l), ', }', '}') AS flattened_rels LIMIT 100, Param: {'subjs': Value( lVal=NList( values=[Value( sVal='Europe'), Value( sVal='Northern hemisphere'), Value( sVal='Arctic ocean'), [...] sVal='Third largest economy')]))}Error message: Scan vertices or edges need to specify a limit number, or limit number can not push down.