Find answers from the community

Updated 2 months ago

Summarizing node list with text and metadata

I have a list of nodes like that
Plain Text
nodes= [TextNode(
            text=f"{original_code}",
            id_="parent_1",
            },
        TextNode(
                text=f"{chunk}",
                id_="child_1_1",
                metadata={
                 "KG_RELATIONS_KEY": [Relation(
                                      source_id="parent_1",
                                      target_id="child_1_1",
                                      label=get_node_rel_string(NodeRelationship.PARENT),
                                                    )]),....
                    ]

And I create PropertyGraphIndex using kg_extractors by ImplicitPathExtractor()
Plain Text
property_graph_index = PropertyGraphIndex(
    nodes=nodes,
    kg_extractors=[ImplicitPathExtractor()]  # Provide nodes directly to PropertyGraphIndex
)

but when I retrieve a node via property_graph_index.as_retriever()
the result that give me
Node ID: 807bc464-c42c-4824-bfcb-3dcac920237f Text: parent_1-> PARENT -> child_1_1 Score: 0.000
I just expectation that the result retrieve base on the vector embeding of the node.text
I have tried advise of Dosu bot in Github
Plain Text
from llama_index.core.indices.property_graph import VectorContextRetriever

# Assuming you have an embedding model set up
embed_model = OpenAIEmbedding(model_name="text-embedding-3-small")

vector_retriever = VectorContextRetriever(
    index.property_graph_store,
    embed_model=embed_model,
    similarity_top_k=2,  # Number of top similar nodes to retrieve
    path_depth=1,        # Depth of relations to follow after node retrieval
    include_text=True    # Include source chunk text with retrieved paths
)

retriever = property_graph_index.as_retriever(sub_retrievers=[vector_retriever])
nodes = retriever.retrieve("Your query text here")

but it always give a empty result

Anyone can help me explain for me or give me some advise ?
L
X
2 comments
tbh I'm not sure if using the ImplicitPathExtractor on its own is useful -- maybe try adding another extractor?
I found that ImplicitPathExtractor() gives my expected graph like image 1.
Also I try to find out that, each node in property_graph_store have embedding and text Attribute. But why I tried to retrieve, it just give id->relation->id or empty result
Attachments
image.png
image.png
Add a reply
Sign up and join the conversation on Discord