Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Milvus vector database:AttributeError: 'NoneType' object has no attribute 'condition' #13581

Closed
shizhengLi opened this issue May 19, 2024 · 2 comments · Fixed by #13591
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized

Comments

@shizhengLi
Copy link

shizhengLi commented May 19, 2024

Bug Description

In function "get_question_retriever", when I pass all_nodes, which is a list of IndexNode, to the VectorStoreIndex, I get an error for MilvusVectorStore.

Traceback (most recent call last):
  File "/home/r/nodes2retrievers.py", line 221, in <module>
    nodes = qr.retrieve(" What is the rationale for continuing treatment with lorlatinib beyond disease progression in ALK-positive NSCLC patients, even though it is positioned as the final targeted ALK TKI treatment before chemotherapy")
  File "/home//anaconda3/envs/rag/lib/python3.9/site-packages/llama_index/core/base/base_retriever.py", line 229, in retrieve
    nodes = self._retrieve(query_bundle)
  File "/home//anaconda3/envs/rag/lib/python3.9/site-packages/llama_index/core/retrievers/recursive_retriever.py", line 206, in _retrieve
    retrieved_nodes, _ = self._retrieve_rec(query_bundle, query_id=None)
  File "/home//anaconda3/envs/rag/lib/python3.9/site-packages/llama_index/core/retrievers/recursive_retriever.py", line 179, in _retrieve_rec
    nodes = obj.retrieve(query_bundle)
  File "/home/lishizheng/anaconda3/envs/rag/lib/python3.9/site-packages/llama_index/core/base/base_retriever.py", line 229, in retrieve
    nodes = self._retrieve(query_bundle)
  File "/home//anaconda3/envs/rag/lib/python3.9/site-packages/llama_index/core/indices/vector_store/retrievers/retriever.py", line 94, in _retrieve
    return self._get_nodes_with_embeddings(query_bundle)
  File "/home//anaconda3/envs/rag/lib/python3.9/site-packages/llama_index/core/indices/vector_store/retrievers/retriever.py", line 170, in _get_nodes_with_embeddings
    query_result = self._vector_store.query(query, **self._kwargs)
  File "/home//anaconda3/envs/rag/lib/python3.9/site-packages/llama_index/vector_stores/milvus/base.py", line 409, in query
    string_expr = f" {query.filters.condition.value} ".join(expr)
AttributeError: 'NoneType' object has no attribute 'condition'

However, when I pass the all_nodes to FaissVectorStore, There is no problem.


import os
import nest_asyncio
from llama_index.core.retrievers import RecursiveRetriever
from llama_index.core.storage.docstore import SimpleDocumentStore
from llama_index.core import Settings
from llama_index.core.schema import MetadataMode,IndexNode
nest_asyncio.apply()
from llama_index.core.node_parser import(
    SentenceSplitter
)

from llama_index.vector_stores.milvus import MilvusVectorStore
from llama_index.vector_stores.faiss import FaissVectorStore
import faiss

from llama_index.core import (
    VectorStoreIndex,
    ServiceContext,
    StorageContext,
    Document
)
from llama_index.core import Settings
from llama_index.core.schema import IndexNode
import re
from llama_index.core.schema import BaseNode, IndexNode
from modify_files.modify_keywordRetriever import KeywordTableGPTRetriever, KeywordTableRAKERetriever
from llama_index.core import RAKEKeywordTableIndex
nest_asyncio.apply()

from llama_index.core import Settings
import textwrap

import openai
openai.api_key=
openai.base_url=
import json

def get_question_retriever(doc_store_path,  similarity_top_k=5):
    all_nodes = []
    total_nodes = getnodes(doc_store_path)
    total_nodes = list(map(mapfun,total_nodes))
    ori2index = generate_index_nodes(total_nodes=total_nodes, mode="sq")
    for k, v in ori2index.items():
        all_nodes = all_nodes + v["sq"]
    all_nodes_dict = {node.node_id:node for node in total_nodes}  

    # dimensions of text-ada-embedding-002
    # d = 1536
    #faiss_index = faiss.IndexFlatL2(d)
    # For Faiss vector database, it can pass the test
   # vector_store = FaissVectorStore(faiss_index=faiss_index)

    
    # For Milnus vector database
    vector_store = MilvusVectorStore( 
        uri="./milvus_llamaindex.db",
        dim=1536, 
        overwrite=True
    )
    storage_context = StorageContext.from_defaults(vector_store=vector_store)


# =========================================
#   These lines of code resulted in an error.
# =========================================

    index = VectorStoreIndex(
        nodes=all_nodes, storage_context=storage_context, show_progress=True
    )

# =============================================

    vector_sq_retri = index.as_retriever(similarity_top_k = similarity_top_k)
    vector_sq_retri = RecursiveRetriever(
            "vector",
            retriever_dict={"vector":vector_sq_retri},
            node_dict = all_nodes_dict,
            verbose = True
        )
    return vector_sq_retri





if __name__ == "__main__":
  
    #queretriever
    qr = get_question_retriever("../formatDocStore.json",similarity_top_k=5)
    nodes = qr.retrieve(" What is the rationale for continuing treatment with lorlatinib beyond disease progression in ALK-positive NSCLC patients, even though it is positioned as the final targeted ALK TKI treatment before chemotherapy")
    print(nodes[0].text)


Thanks for your patience.

Version

llama-index==0.10.18

Steps to Reproduce

Just run the code.

Relevant Logs/Tracbacks

No response

@shizhengLi shizhengLi added bug Something isn't working triage Issue needs to be triaged/prioritized labels May 19, 2024
Copy link

dosubot bot commented May 19, 2024

To address the AttributeError: 'NoneType' object has no attribute 'condition' when using MilvusVectorStore in the llama-index library, it's essential to ensure that every component involved in the query process is correctly initialized and configured. This error typically indicates that an expected object or attribute hasn't been properly set up. Here are the key steps to troubleshoot and potentially fix the issue:

  1. MilvusVectorStore Initialization: Double-check that the MilvusVectorStore is correctly initialized, including parameters like uri, collection_name, dim, and embedding_field. Ensure the uri accurately points to your Milvus server and that dim matches your embeddings' dimension.

  2. Collection and Index Configuration: Make sure the Milvus collection exists and is correctly configured. If you're using overwrite=True, confirm this is intentional as it will delete and recreate the collection. Also, verify your index_config and search_config.

  3. Embeddings and Metadata Handling: When adding nodes, ensure each BaseNode object's embedding and metadata are correctly populated, matching the specified dimension and correctly formatted metadata.

  4. Query Configuration: When querying, ensure the VectorStoreQuery object is correctly set up, including the query mode, any filters, and the top-k similar nodes to retrieve.

  5. Debugging and Logging: Implement logging at critical points to track the flow and identify where the error occurs. This can help pinpoint whether the issue arises during initialization, data insertion, or querying.

  6. Version Compatibility: Check that you're using compatible versions of Milvus and the llama-index library. If functionalities or configurations have changed in different versions, it might affect your implementation.

By carefully following these steps and ensuring all components are correctly set up, you should be able to resolve the error and successfully use MilvusVectorStore with the llama-index library.

Details

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.

To continue the conversation, mention @dosu.

@RussellLuo
Copy link
Contributor

This problem was caused by #11566, which tried to address #11565. However, I think it may have made changes in the wrong place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants