PropertyGraphIndex
with SimplePropertyGraphStore
to store data from netwokx graph. The nodes and edges from the networkx
graph are upserted into the graph store as EntityNode
and Relation
instances. I can get data from the store using methods like graph_store.get
using properties
or ids
. But I don't understand how to query the index. The index is created using index = PropertyGraphIndex.from_existing(property_graph_store=graph_store)
. llm_synonym_retriever = LLMSynonymRetriever( index.property_graph_store, llm=llm, include_text=False, ) vector_context_retriever = VectorContextRetriever( index.property_graph_store, embed_model=HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5"), include_text=False, ) query_engine = index.as_query_engine( sub_retrievers=[ vector_context_retriever, llm_synonym_retriever, ], llm=llm, ) # llm is Ollama(model="llama3")
query_engine.query()
always returns empty response.response = query_engine.query("What is the email address of user Fname Lname?")
llm = Ollama( model="llama3", request_timeout=300.0, additional_kwargs={ "trust_remote_code": True, "generate_kwargs": {"temperature": 0.0, "do_sample": False}, }, ) embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5") llm.context_window = 4096 Settings.llm = llm Settings.chunk_size = 1024 Settings.embed_model = embed_model vector_store = SimpleVectorStore() storage_context = StorageContext.from_defaults(vector_store=vector_store) storage_context.vector_stores["default"] = vector_store user = { "id": "user_1", "name": "Stepan Ivan", "email": "user@example.com", "type": "user", } market = { "id": "market_1", "name": "Canada", "type": "market", } relation = Relation( label="market_member", source_id=user["id"], target_id=market["id"], properties={} ) graph_store = SimplePropertyGraphStore() graph_store.upsert_nodes( [ EntityNode(label=user["type"], name=user["id"], properties=user), EntityNode(label=market["type"], name=market["id"], properties=market), ] ) graph_store.upsert_relations([relation]) index = PropertyGraphIndex.from_existing( llm=llm, property_graph_store=graph_store, storage_context=storage_context, embed_kg_nodes=True, show_progress=True, ) llm_synonym_retriever = LLMSynonymRetriever( index.property_graph_store, llm=llm, include_text=False, ) vector_context_retriever = VectorContextRetriever( graph_store=index.property_graph_store, embed_model=embed_model, vector_store=index.vector_store, include_text=False, ) query_engine = index.as_query_engine( sub_retrievers=[ vector_context_retriever, llm_synonym_retriever, ], llm=llm, )
nodes = graph_store.get(properties={"email": "user@example.com"})
retriever.retrieve("query")
response = query_engine.query(...) for node in response.source_nodes: print(node.text)