Implement something like Auto Merging Retriever but using two Supabase VectorStoreIndex #10690
Replies: 2 comments
-
🤖 Hey there, @rahulkrprajapati! Great to see you back in action here. I hope you've been doing awesome since our last code rendezvous. 😎👾 Sure, I can guide you on how to implement a retrieval function that operates on two Supabase VectorStoreIndex, one for nodes and the other for leaf nodes, to produce output similar to an Auto Merging Retriever. You can create a new class that inherits from class MyRetriever(AutoMergingRetriever):
def __init__(
self,
node_vector_retriever: VectorIndexRetriever,
leaf_node_vector_retriever: VectorIndexRetriever,
storage_context: StorageContext,
simple_ratio_thresh: float = 0.5,
verbose: bool = False,
callback_manager: Optional[CallbackManager] = None,
object_map: Optional[dict] = None,
objects: Optional[List[IndexNode]] = None,
) -> None:
super().__init__(
vector_retriever=node_vector_retriever,
storage_context=storage_context,
simple_ratio_thresh=simple_ratio_thresh,
verbose=verbose,
callback_manager=callback_manager,
object_map=object_map,
objects=objects,
)
self._leaf_node_vector_retriever = leaf_node_vector_retriever
def _retrieve(self, query_bundle: QueryBundle) -> List[NodeWithScore]:
initial_nodes = self._vector_retriever.retrieve(query_bundle)
initial_leaf_nodes = self._leaf_node_vector_retriever.retrieve(query_bundle)
# Merge the initial nodes and leaf nodes
initial_nodes.extend(initial_leaf_nodes)
cur_nodes, is_changed = self._try_merging(initial_nodes)
while is_changed:
cur_nodes, is_changed = self._try_merging(cur_nodes)
# sort by similarity
cur_nodes.sort(key=lambda x: x.get_score(), reverse=True)
return cur_nodes In this code, You can find more details about the
I hope this helps! If you have any further questions, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
-
Stack Trace
|
Beta Was this translation helpful? Give feedback.
-
I have defined two separate vector store indices one for nodes and the other for leaf nodes. How do I retrieve from these nodes such that the output is something like Auto Merging Retriever
Beta Was this translation helpful? Give feedback.
All reactions