Open rahulkrprajapati opened 4 months ago
🤖
Hey @rahulkrprajapati, good to see you back! Hope you're doing great. Let's dive into this intriguing issue you've encountered.
Based on the information you've provided, it seems like the recursive call is happening due to the _retrieve
method in the AutoMergingRetriever
class. This method retrieves the initial nodes and then attempts to merge them. If any changes occur during the merging process, the code enters a while loop where it continues to try merging the current nodes until no more changes occur.
The recursion is happening because the _try_merging
method, which is called inside the while loop, can potentially change the is_changed
variable to True
again, causing the loop to continue indefinitely. This can happen if the conditions for merging nodes in the _get_parents_and_merge
and _fill_in_nodes
methods are continuously met.
To fix this issue, you could add a condition to break the loop after a certain number of iterations or when no significant changes are made to the nodes. Here's an example of how you can do this:
MAX_ITERATIONS = 10 # Set a maximum number of iterations
def _retrieve(self, query_bundle: QueryBundle) -> List[NodeWithScore]:
"""Retrieve nodes given query.
Implemented by the user.
"""
initial_nodes = self._vector_retriever.retrieve(query_bundle)
cur_nodes, is_changed = self._try_merging(initial_nodes)
iterations = 0
while is_changed and iterations < MAX_ITERATIONS:
prev_nodes = cur_nodes.copy()
cur_nodes, is_changed = self._try_merging(cur_nodes)
iterations += 1
# Break the loop if no significant changes are made to the nodes
if cur_nodes == prev_nodes:
break
# sort by similarity
cur_nodes.sort(key=lambda x: x.get_score(), reverse=True)
return cur_nodes
In this code, the while loop will break after MAX_ITERATIONS
iterations or when the current nodes are the same as the previous nodes, indicating that no significant changes are being made. This should prevent the infinite recursion issue.
As for the get_document
method in the SupabaseVectorStore
class, I wasn't able to find specific information about its implementation in the LlamaIndex repository. It's possible that this method is used to retrieve a document from the vector store using its document ID, but without more information or context, it's hard to say for sure. If you could provide more details about this method and how it's used in your code, I might be able to give a more accurate answer.
I hope this helps! If you have any more questions or need further clarification, feel free to ask.
There's a slight correction:
while is_changed and iterations < self.MAX_ITERATIONS:
prev_nodes = cur_nodes.copy()
cur_nodes, is_changed = self._try_merging(cur_nodes)
iterations += 1
# Break the loop if no significant changes are made to the nodes
if cur_nodes == prev_nodes:
break
Hmm. Trying to think of a way to make this change generalize across the codebase.
Maybe if get_document()
was implemented in the base vector store class, the typing could be updated to satisfy mypy where this function is used
the sad part about that is, we would need to invest considerable effort to implement that method for (most) vector dbs
Would love to help out.
I think having just three options for the docstore is a bummer 😔. Would love to have a few more options available. And Supabase just seemed like a good alternative given my use cases. It'll be awesome if I'm able to make it work for more vector dbs.
@rahulkrprajapati yea totally agree, would like to have more docstore options (right now we have simple, redis, mongodb, postgress, firestore, and dynamodb)
Willing to help. Working with qdrant and stuck at this point as well.
Feature Description
Since supabase as a docStore is not supported. I tried implementing a AutoMergingRetriever using two VectorStoreIndex.
Changes I made:
added
get_document
toSupabaseVectorStore
using:changed two lines in
auto_merging_retriever.py
:in function
_get_parents_and_merge
and: in function
_fill_in_nodes
:define a custom retriever :
Usage:
Reason
AutoMergingRetriever pipeline using Supabase
Value of Feature
Complete Supabase RAG pipeline that can be used as a backend for any Frontend frameworks ready for consumption.