storage_context = StorageContext.from_defaults(graph_store=graph_store)
retriever = KnowledgeGraphRAGRetriever(
storage_context=storage_context,
...
)
what query engine do I pass that retriever to?
Ideally a RetrieverQueryEngine
from llama_inex.query_engine import RetrieverQueryEngine
query_engine = RetrieverQueryEngine.from_args(retriever, ...)
ok, coolio, I'll give that a try π€
There's a ton of kwargs in both those methods, so be sure to pass in whatever else you need (service context, other settings, etc.)
are there any special args that I should look into? I just learned about graph databases so I have little knowledge on this
So many. Idek what half of them do lol
But its there for your reading pleasure π
(we need to refactor our KG stuff, hopefully soon!)
what is the result of enabling this?
with_nl2graphquery (bool)
β Whether to combine NL2GraphQuery in context. default: False
Is this what allows us to pass natural language as the query to the KGRAGRetriever?
Yea that will supliment the results retrieved from the entity/synonym stuff with a graph query generated from natural language
Are there plans to improve the documentation for these properties/attribues. Its not really clear how some of them are intended to work... \o/
am I supposed to pass Cypher to these modules or engrish?
haha there are plans. It's one of our holiday hack projects π I would expect a complete re-write of our graph stuff tbh. We need to move from RDF triplets to LPG
Just english, it will figure the rest out (I hope)
sorry, and what about the entity and synonym stuff?
where can we learn more about what is going on with these properties?
This retriever is taking your query, and getting the LLM to generate entities and synonyms, and then using those to retrieve data from the graph
Probably reading the source code is the best option lol
how does the LLM get access to the entity types and relationship types in my neo4j database?
It doesnt -- it generates a bunch and then tries to retrieve them, if any match
(At least I think that's what its doing, I'm reading the code now haha)
I'm wondering where I should pass that data to the LLM? I guess in the prompt?
Yea in the query_str
would be the best place
Like some kind of pre-amble before your actual question
sorry, Logan, how do I lookup what the Optional[BasePromptTemplate]) (entity_extract_template) β A Query Key Entity Extraction Prompt (see Prompt Templates).
is and how I would format a custom one? Also how is the template used in the entire process? Like, should I put my entity types and relationships types in that template or the query_str
?
I keep getting rate errors on each query.
429 - Rate limit reached for requests Cause: You are sending requests too quickly.
Solution: Pace your requests. Read the Rate limit guide.
How do I control the rate at which the queries are being sent to OpenAI?
has anyone used RateLimiter
to control the rate of queries when calling a query_engine? what is the canonical approach to rate limiting with retreivers/query_engines?
Hi Logan, Sorry to poke at this topic again, how do we rate limit a query_engine call? When I tried using the knowledgegraph retriever with a query_engine, I always get rate limit errors, even for a single call. How do we handle this?
The code is straightforward:
query_engine = RetrieverQueryEngine.from_args(
retriever=graph_rag_retriever,
response_synthesizer=response_synthesizer,
service_context=service_context,
)
response = query_engine.query("the query")
RateLimitError: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details.
I just remembered we faced the same error with Neo4J. So instead of sending a 100 documents I only did 5, invoked sleep for 5 seconds, then sent there remaining in batches. Needs to be retrofitted unfortunately.
yea the above is the approach. This should be addressed when we refactor the knowledge graphs π
Thank you both for looking in, the issue is I don't understand how what you're saying applies. to my use case. I sending a single query to the query_engine. I'm not sending documents. can you elaborate a tiny bit? please and thank you!
You exceeded your current quota, please check your plan and billing details.
-- seems like your account has hit it's spending limit
error 429 is a rate limit error
I've tried two different accounts, both of which are not over budget in terms of monthly allowable balance
I'm not sure what else to say tbh. It should only be making 3-4 LLM calls. My only guess is somehow your account is restricted. I've never had this issue π€
Hi, i am trying to load in a neo4j Graph database for SubQuestionQueryEngine. Does anyne have a sniplet of code how to get this working?
To load a Neo4j graph database for use with a SubQuestionQueryEngine, you would typically need to follow these steps:
- Install the Neo4j Python client.
- Set up the connection parameters for the Neo4j database.
- Instantiate a Neo4jGraphStore with the connection parameters.
- Create a ServiceContext and a StorageContext.
- Build a KnowledgeGraphIndex with the StorageContext.
- Instantiate the SubQuestionQueryEngine with the KnowledgeGraphIndex.
Here is a code snippet of how this might work:
# Step 1: Install the Neo4j Python client (this should be done in your environment, not in the code)
# %pip install neo4j
# Step 2: Set up the connection parameters for the Neo4j database
username = "neo4j"
password = "your_password" # Replace with your actual password
url = "bolt://your_neo4j_host:7687" # Replace with your actual host and port
database = "neo4j" # Replace with your actual database name if different
# Step 3: Instantiate a Neo4jGraphStore with the connection parameters
from llama_index.graph_stores import Neo4jGraphStore
graph_store = Neo4jGraphStore(
username=username,
password=password,
url=url,
database=database,
)
# Step 4: Create a ServiceContext and a StorageContext
from llama_index import ServiceContext
from llama_index.storage.storage_context import StorageContext
service_context = ServiceContext.from_defaults()
storage_context = StorageContext.from_defaults(graph_store=graph_store)
# Step 5: Build a KnowledgeGraphIndex with the StorageContext
from llama_index import KnowledgeGraphIndex
# Assuming `documents` is a list of your documents
index = KnowledgeGraphIndex.from_documents(
documents,
storage_context=storage_context,
service_context=service_context,
# Set to True if you want to include embeddings
include_embeddings=False,
)
# Step 6: Instantiate the SubQuestionQueryEngine with the KnowledgeGraphIndex
# Replace `SubQuestionQueryEngine` with the actual class you are using, as it's not explicitly mentioned in the provided files
from llama_index.query_engine import SubQuestionQueryEngine
query_engine = SubQuestionQueryEngine(index)
Hi @rahul , thank you for the reply. I might be mistaken, but:
'''
KnowledgeGraphIndex.from_documents(
documents,
storage_context=storage_context,
service_context=service_context,
# Set to True if you want to include embeddings
include_embeddings=False,
)
'''
generates a new Graph_DB from my document list, which i do not want. I already did this step and it took about 4 hours to process all my data.
So now, that i have my neo4j graph DB, i want to query it. And since my questions are at least a page long, i need to use the subquestion retriever.
So i want each subquestion to be retrieved individually from the graph db. i have it figured out for the vector storage, but i want to combine both techniques to increse accuracy.
Do you have any idea how i could accieve this?