Closed marco-bertelli closed 3 months ago
🤖
Hey @marco-bertelli! 👋 I'm Dosu, your friendly neighborhood bot, here to lend a hand with bugs, answer questions, and help you contribute while we wait for a human maintainer to join us. I'm diving into your issue and will get back to you with a full answer soon. Hang tight! 🤖
i have found a solution for that and create a PR, if you think is a good solution merge it, thanks for the awesome job guys: https://github.com/run-llama/llama_index/pull/11094
🤖
Thank you for reporting this issue and for your contribution to the LlamaIndex project. It seems like the error you're encountering is due to the LLM model returning a single document when the LLMRerank class expects more. This discrepancy is causing an IndexError
in the default_parse_choice_select_answer_fn
function.
Your solution seems to address this issue by handling the case where the LLM model returns a single document. However, as an AI, I'm unable to review or merge pull requests. I recommend reaching out to the repository maintainers directly for them to review your solution.
Regarding your question about the expected behavior of the LLMRerank class when it encounters a question unrelated to the context, the LLMRerank class does not have a specific behavior for such questions. It simply reranks the nodes based on the scores returned by the LLM predictor. This behavior is independent of whether the question is related to the context or not.
As for the changes made to the LLMRerank class between version v0.10.9 and v0.10.10, I'm unable to provide that information as it's not available in the repository. You might want to check the release notes or commit history for those versions to get more details.
I hope this helps! If you have any more questions or need further clarification, feel free to ask.
I'm facing a issue while querying my pinecone vectordb after new version before it worked fine
class LLMRerankRetriever(BaseRetriever):
def __init__(
self,
vector_retriever: VectorIndexRetriever,
service_context: ServiceContext
):
self._vector_retriever = vector_retriever
self._service_context = service_context
super().__init__()
def _retrieve(self, query_bundle: QueryBundle):
retrieved_nodes = self._vector_retriever.retrieve(query_bundle)
reranker = LLMRerank(service_context=self._service_context,choice_batch_size=7,top_n=3)
retrieved_nodes = reranker.postprocess_nodes(retrieved_nodes, query_bundle)
return retrieved_nodes
vector_retriever = VectorIndexRetriever(index=index, similarity_top_k=21)
custom_retriever = LLMRerankRetriever(vector_retriever, service_context)
response_synthesizer = get_response_synthesizer(verbose=True)
custom_query_engine = RetrieverQueryEngine(
retriever=custom_retriever,
response_synthesizer=response_synthesizer
)
memory = ChatMemoryBuffer.from_defaults(token_limit=250)
new_engine=CondensePlusContextChatEngine.from_defaults(
retriever=custom_query_engine,memory=memory,
context_prompt=prompt)
I'm using a chatengine in combination with a RetrieverQueryEngine
Traceback (most recent call last):
File "d:\Sudar\Generative AI_Casy\chatbot_cli_vers\Chatbot_CLI_4.py", line 108, in
context_str, context_nodes = self._retrieve_context(condensed_question)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Sudar\Generative AI_Casy\myenv\Lib\site-packages\llama_index\core\chat_engine\condense_plus_context.py", line 168, in _retrieve_context
nodes = self._retriever.retrieve(message)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Sudar\Generative AI_Casy\myenv\Lib\site-packages\llama_index\core\query_engine\retriever_query_engine.py", line 142, in retrieve
nodes = self._retriever.retrieve(query_bundle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Sudar\Generative AI_Casy\myenv\Lib\site-packages\llama_index\core\base\base_retriever.py", line 229, in retrieve
nodes = self._retrieve(query_bundle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "d:\Sudar\Generative AI_Casy\chatbot_cli_vers\Chatbot_CLI_4.py", line 54, in _retrieve
retrieved_nodes = self._vector_retriever.retrieve(query_bundle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Sudar\Generative AI_Casy\myenv\Lib\site-packages\llama_index\core\base\base_retriever.py", line 229, in retrieve
nodes = self._retrieve(query_bundle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Sudar\Generative AI_Casy\myenv\Lib\site-packages\llama_index\core\indices\vector_store\retrievers\retriever.py", line 94, in _retrieve
return self._get_nodes_with_embeddings(query_bundle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Sudar\Generative AI_Casy\myenv\Lib\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 "D:\Sudar\Generative AI_Casy\myenv\Lib\site-packages\llama_index\vector_stores\pinecone\base.py", line 426, in query
response = self._pinecone_index.query(
^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Pinecone' object has no attribute 'query'
My pip versions
llama-index==0.10.11 llama-index-agent-openai==0.1.4 llama-index-cli==0.1.3 llama-index-core==0.10.11.post1 llama-index-embeddings-openai==0.1.5 llama-index-indices-managed-llama-cloud==0.1.2 llama-index-legacy==0.9.48 llama-index-llms-openai==0.1.5 llama-index-multi-modal-llms-openai==0.1.3 llama-index-program-openai==0.1.3 llama-index-question-gen-openai==0.1.2 llama-index-readers-file==0.1.4 llama-index-readers-llama-parse==0.1.2 llama-index-vector-stores-chroma==0.1.2 llama-index-vector-stores-pinecone==0.1.3 llama-parse==0.3.4 llamaindex-py-client==0.1.13 pinecone-client==3.0.3
Looking forward your support guyss!!!
Thanks in advance
Bug Description
If you will use LLMRerank class the DEFAULT_CHOICE_SELECT_PROMPT has a problem, the problem is that if the question is a general conversation thing like "great job!", the LLM model reply with something similar that:
['The question "ottimo" is not clear and does not seem to relate to any of the documents provided. Therefore', ' no documents are relevant.']
this will cause another error in this response parser that is:answer_num = int(line_tokens[0].split(":")[1].strip()) IndexError: list index out of range
. this because for example you choose top 3 docs but the LLM model will reply with only 1Version
0.10.9
Steps to Reproduce
instanciate a reranker:
reranker = LLMRerank( choice_batch_size=6, choice_select_prompt=CUSTOM_RERANK_TEMPLATE, top_n=2, service_context=service_context, )
after that use it anywhere and ask a question not related to the context. this will cause the error in the description: the problem is that if the question is a general conversation thing like "great job!", the LLM model reply with something similar that:
['The question "ottimo" is not clear and does not seem to relate to any of the documents provided. Therefore', ' no documents are relevant.']
this will cause another error in this response parser that is:answer_num = int(line_tokens[0].split(":")[1].strip()) IndexError: list index out of range
. this because for example you choose top 3 docs but the LLM model will reply with only 1Relevant Logs/Tracbacks