run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
36.95k stars 5.3k forks source link

[Bug]: MilvusVectorStore not working with RecursiveRetriever #11969

Open Kushagra0409 opened 8 months ago

Kushagra0409 commented 8 months ago

Bug Description

In the DensexRetriver pack, I added a code to use milvus vector db, (I tried with elastic search too, it works fine with the existing dense-x code). However, upon querying, I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[229], line 2
      1 query_engine_chunk = dense_pack2.query_engine
----> 2 print(str(query_engine_chunk.query("This is a question")))

File ~/.local/lib/python3.10/site-packages/llama_index/core/base/base_query_engine.py:40, in BaseQueryEngine.query(self, str_or_query_bundle)
     38 if isinstance(str_or_query_bundle, str):
     39     str_or_query_bundle = QueryBundle(str_or_query_bundle)
---> 40 return self._query(str_or_query_bundle)

File ~/.local/lib/python3.10/site-packages/llama_index/core/query_engine/retriever_query_engine.py:186, in RetrieverQueryEngine._query(self, query_bundle)
    182 """Answer a query."""
    183 with self.callback_manager.event(
    184     CBEventType.QUERY, payload={EventPayload.QUERY_STR: query_bundle.query_str}
    185 ) as query_event:
--> 186     nodes = self.retrieve(query_bundle)
    187     response = self._response_synthesizer.synthesize(
    188         query=query_bundle,
    189         nodes=nodes,
    190     )
    192     query_event.on_end(payload={EventPayload.RESPONSE: response})

File ~/.local/lib/python3.10/site-packages/llama_index/core/query_engine/retriever_query_engine.py:142, in RetrieverQueryEngine.retrieve(self, query_bundle)
    141 def retrieve(self, query_bundle: QueryBundle) -> List[NodeWithScore]:
--> 142     nodes = self._retriever.retrieve(query_bundle)
    143     return self._apply_node_postprocessors(nodes, query_bundle=query_bundle)

File ~/.local/lib/python3.10/site-packages/llama_index/core/base/base_retriever.py:229, in BaseRetriever.retrieve(self, str_or_query_bundle)
    224 with self.callback_manager.as_trace("query"):
    225     with self.callback_manager.event(
    226         CBEventType.RETRIEVE,
    227         payload={EventPayload.QUERY_STR: query_bundle.query_str},
    228     ) as retrieve_event:
--> 229         nodes = self._retrieve(query_bundle)
    230         nodes = self._handle_recursive_retrieval(query_bundle, nodes)
    231         retrieve_event.on_end(
    232             payload={EventPayload.NODES: nodes},
    233         )

File ~/.local/lib/python3.10/site-packages/llama_index/core/retrievers/recursive_retriever.py:206, in RecursiveRetriever._retrieve(self, query_bundle)
    205 def _retrieve(self, query_bundle: QueryBundle) -> List[NodeWithScore]:
--> 206     retrieved_nodes, _ = self._retrieve_rec(query_bundle, query_id=None)
    207     return retrieved_nodes

File ~/.local/lib/python3.10/site-packages/llama_index/core/retrievers/recursive_retriever.py:179, in RecursiveRetriever._retrieve_rec(self, query_bundle, query_id, cur_similarity)
    174 elif isinstance(obj, BaseRetriever):
    175     with self.callback_manager.event(
    176         CBEventType.RETRIEVE,
    177         payload={EventPayload.QUERY_STR: query_bundle.query_str},
    178     ) as event:
--> 179         nodes = obj.retrieve(query_bundle)
    180         event.on_end(payload={EventPayload.NODES: nodes})
    182     nodes_to_add, additional_nodes = self._query_retrieved_nodes(
    183         query_bundle, nodes
    184     )

File ~/.local/lib/python3.10/site-packages/llama_index/core/base/base_retriever.py:229, in BaseRetriever.retrieve(self, str_or_query_bundle)
    224 with self.callback_manager.as_trace("query"):
    225     with self.callback_manager.event(
    226         CBEventType.RETRIEVE,
    227         payload={EventPayload.QUERY_STR: query_bundle.query_str},
    228     ) as retrieve_event:
--> 229         nodes = self._retrieve(query_bundle)
    230         nodes = self._handle_recursive_retrieval(query_bundle, nodes)
    231         retrieve_event.on_end(
    232             payload={EventPayload.NODES: nodes},
    233         )

File ~/.local/lib/python3.10/site-packages/llama_index/core/indices/vector_store/retrievers/retriever.py:94, in VectorIndexRetriever._retrieve(self, query_bundle)
     88     if query_bundle.embedding is None and len(query_bundle.embedding_strs) > 0:
     89         query_bundle.embedding = (
     90             self._embed_model.get_agg_embedding_from_queries(
     91                 query_bundle.embedding_strs
     92             )
     93         )
---> 94 return self._get_nodes_with_embeddings(query_bundle)

File ~/.local/lib/python3.10/site-packages/llama_index/core/indices/vector_store/retrievers/retriever.py:170, in VectorIndexRetriever._get_nodes_with_embeddings(self, query_bundle_with_embeddings)
    166 def _get_nodes_with_embeddings(
    167     self, query_bundle_with_embeddings: QueryBundle
    168 ) -> List[NodeWithScore]:
    169     query = self._build_vector_store_query(query_bundle_with_embeddings)
--> 170     query_result = self._vector_store.query(query, **self._kwargs)
    171     return self._build_node_list_from_query_result(query_result)

File ~/.local/lib/python3.10/site-packages/llama_index/vector_stores/milvus/base.py:277, in MilvusVectorStore.query(self, query, **kwargs)
    275 string_expr = ""
    276 if len(expr) != 0:
--> 277     string_expr = f" {query.filters.condition.value} ".join(expr)
    279 # Perform the search
    280 res = self._milvusclient.search(
    281     collection_name=self.collection_name,
    282     data=[query.query_embedding],
   (...)
    286     search_params=self.search_config,
    287 )

AttributeError: 'NoneType' object has no attribute 'condition'

Note that upon changing the recursiveRetriever with simple vector_index.as_retriever, the Milvus vector db works fine. Is this a bug that milvus vector db is facing with recursive retriever, and are there any workarounds to fix this error? Please guide me to the documentations if so.

Version

0.10.12

Steps to Reproduce

  1. create a vector store index with milvus db storage context
  2. use recursive retriever
  3. run query (please refer description)

Relevant Logs/Tracbacks

No response

dosubot[bot] commented 8 months ago

Hey @Kushagra0409, great to see you back here! 🚀

Thank you for providing the detailed error traceback. The error you're encountering with the MilvusVectorStore not working with the RecursiveRetriever in LlamaIndex v0.10.12, resulting in an AttributeError, is likely due to a compatibility or implementation issue between the MilvusVectorStore class and the expected interface or methods required by the RecursiveRetriever.

The AttributeError typically indicates that RecursiveRetriever is attempting to access a method or attribute that does not exist on MilvusVectorStore. Here are some steps you can take to resolve this issue:

  1. Check for Missing Methods or Attributes: Ensure that MilvusVectorStore implements all methods and attributes expected by RecursiveRetriever.

  2. Update LlamaIndex and Dependencies: Ensure that you are using compatible versions of LlamaIndex and its dependencies. It's possible that the version of LlamaIndex you are using (v0.10.12) has known issues or incompatibilities that have been resolved in later versions.

  3. Review LlamaIndex and Milvus Documentation: Check the documentation for both LlamaIndex and Milvus for any notes on compatibility or specific requirements for integrating Milvus as a vector store.

  4. Inspect RecursiveRetriever Implementation: Look into the implementation of RecursiveRetriever to understand what it expects from a vector store. This can give you clues on what might be missing or incorrectly implemented in MilvusVectorStore.

  5. Debugging and Logging: Add logging around the point where the AttributeError occurs to get more insight into what is missing or going wrong. This can help pinpoint the exact attribute or method that is causing the issue.

Unfortunately, without specific details on the AttributeError (e.g., the missing attribute or method name), these general steps are the best approach to diagnosing and resolving the issue. If you could provide more details about the error, it would be easier to provide a more specific solution.

Regarding your question about changes made to the LlamaIndex codebase between version 0.10.12 and the latest version 0.10.19, I'm unable to provide a detailed answer as I don't have access to the specific changes made between these versions. However, it's always a good idea to update to the latest version as it may contain bug fixes and improvements that could potentially resolve your issue.

I hope this helps! If you have any more questions or need further clarification, feel free to ask.

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.
logan-markewich commented 8 months ago

Seems like a bug with metadatafilters