-
I am using hybrid of RAGStringQueryEngine to query my pandas dataframe like below example:
However, someone suggested me to check it out. https://docs.llamaindex.ai/en/stable/examples/query_engine/knowledge_graph_rag_query_engine/?h=graph
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
Using the Here is an example of how to set up and use the from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.core.indices.knowledge_graph.retrievers import KnowledgeGraphRAGRetriever
from llama_index.llms.openai import OpenAI
from llama_index.core.prompts import BasePromptTemplate, PromptTemplate
# Load documents
documents = SimpleDirectoryReader("./data/paul_graham/").load_data()
index = VectorStoreIndex.from_documents(documents)
# Define the KnowledgeGraphRAGRetriever
retriever = KnowledgeGraphRAGRetriever(
storage_context=index.storage_context,
llm=OpenAI(model="gpt-3.5-turbo"),
retriever_mode="hybrid", # You can choose "keyword", "embedding", or "hybrid"
graph_traversal_depth=2,
max_knowledge_sequence=30,
verbose=True
)
# Define the QA prompt
qa_prompt = PromptTemplate(
"Context information is below.\n"
"---------------------\n"
"{context_str}\n"
"---------------------\n"
"Given the context information and not prior knowledge, "
"answer the query.\n"
"Query: {query_str}\n"
"Answer: "
)
# Query the retriever
query_str = "What did the author do growing up?"
nodes = retriever.retrieve(query_str)
context_str = "\n\n".join([n.node.get_content() for n in nodes])
response = retriever._llm.complete(
qa_prompt.format(context_str=context_str, query_str=query_str)
)
print(str(response)) This approach allows you to leverage the advanced capabilities of the |
Beta Was this translation helpful? Give feedback.
-
@dosu Thank you. However, I am not clear about tow things here....
|
Beta Was this translation helpful? Give feedback.
-
@dosu... Now I am using Nebula Graph store. The core of new Nebula is like below... it needs documents.
As per this link, Nebula needed, documnets... the request is how I pass my df_nodes to 'knowledgegraphindex' and use in the bundle as you suggested above.
Your suggestion from the top:
|
Beta Was this translation helpful? Give feedback.
To convert your pandas dataframe
df
with columnsID
,Pathway
, andProcess
into the required format fornodes
to be used withKnowledgeGraphIndex
, you can use the following code: