RetrievalQAWithSourcesChain

823 Views Asked by At

My code:

chain = RetrievalQAWithSourcesChain.from_llm(llm=llm, retriever=vectorIndex.as_retriever())
chain
query = "what is the price of Tiago iCNG?"

langchain.debug=True

input_data = {"question": query}
result = chain(input_data, return_only_outputs=True)

I get this error:

[chain/error] [1:chain:RetrievalQAWithSourcesChain > 3:chain:MapReduceDocumentsChain] [8.64s] Chain run errored with error:
"IndexError('list index out of range')"
[chain/error] [1:chain:RetrievalQAWithSourcesChain] [8.68s] Chain run errored with error:
"IndexError('list index out of range')"
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-27-154a1fc94a62> in <cell line: 7>()
      5 
      6 input_data = {"question": query}
----> 7 result = chain(input_data, return_only_outputs=True)

11 frames
/usr/local/lib/python3.10/dist-packages/langchain/schema/output_parser.py in parse_result(self, result, partial)
    224             Structured output.
    225         """
--> 226         return self.parse(result[0].text)
    227 
    228     @abstractmethod

IndexError: list index out of range`your text`

I want to call a llms api googlepalm and given the some url and convert the vectorembedding and store the faiss vectordatabase then use langchian and call the chain the given the new query.

1

There are 1 best solutions below

0
On

I'm assuming from your code you're trying to either return or print out your "results". If so one of the issues might be that you need to call the function invoke and then pass in the input data variable you have. So something like

chain = RetrievalQAWithSourcesChain.from_llm(llm=llm, retriever=vectorIndex.as_retriever())
chain
query = "what is the price of Tiago iCNG?"

langchain.debug=True

input_data = {"question": query}
result = chain.invoke(input_data)

Alternatively, you can simply the last line to something like

result = chain.invoke(query)