Find answers from the community

Updated 4 weeks ago

Trying To Get The Nodes From The Retrieve Function

I am trying to get the nodes from the retrieve funcion
but I am getting empty list as 'nodes' results.

import openai
#from openai import OpenAI
import os
import sys
from collections import Counter
import json
sys.path.append('../..')

from dotenv import load_dotenv, finddotenv = load_dotenv(find_dotenv()) # read local .env file

openai.api_key = os.environ['OPENAI_API_KEY']
client = OpenAI()
import nest_asyncio
nest_asyncio.apply()

embed_model = OpenAIEmbedding(model='text-embedding-3-small')
llm = OpenAI(temperature=0, model="gpt-4o-mini")

documents = SimpleDirectoryReader(
"......../small_docs"
).load_data()

index = PropertyGraphIndex.from_documents(
documents,
)

from llama_index.core.indices.property_graph import VectorContextRetriever

vector_retriever = VectorContextRetriever(
index.property_graph_store,
embed_model=embed_model,
include_text=False,
similarity_top_k=2,
path_depth=1,
)

retriever2 = index.as_retriever(sub_retrievers=[vector_retriever])
i
L
6 comments
Thanks for your response. how can i fix that?
this code (without vectorcontexretriever) works fine: # use
retriever = index.as_retriever(
include_text=False, # include source chunk with matching paths
similarity_top_k=5, # top k for vector kg node retrieval
)
nodes = retriever.retrieve("who is bob?")
I think somehow the problem is VectorContextRetriever
I think you are missing the vector store
Plain Text
vector_retriever = VectorContextRetriever(
    index.property_graph_store,
    embed_model=embed_model,
    include_text=False,
    similarity_top_k=2,
    path_depth=1,
    vector_store=index.vector_store,
)
thnks bro, it worked.
Add a reply
Sign up and join the conversation on Discord