langchain icon indicating copy to clipboard operation
langchain copied to clipboard

list index out of range error if similarity search gives 0 docs

Open sheikalthaf opened this issue 2 years ago • 7 comments

https://github.com/hwchase17/langchain/blob/276940fd9babf8aec570dd869cc84fbca1c766bf/langchain/vectorstores/milvus.py#L319

I'm using milvus where for my question I'm getting 0 documents and so index out of range error occurs

Error line: https://github.com/hwchase17/langchain/blob/276940fd9babf8aec570dd869cc84fbca1c766bf/langchain/chains/llm.py#L95

sheikalthaf avatar Mar 17 '23 11:03 sheikalthaf

19

Hi what's your input for llm and how do you build your chain, could you offer more information

rchanggogogo avatar Apr 15 '23 05:04 rchanggogogo

+1 getting this using the following:

from langchain.chains import RetrievalQA
from langchain.chat_models import ChatOpenAI


llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0)
chroma_retriever = db.as_retriever(k=3)

qa = RetrievalQA.from_chain_type(llm=llm, 
                                    chain_type="map_reduce", 
                                    retriever=chroma_retriever,

morganmcg1 avatar May 02 '23 15:05 morganmcg1

+1 have the same error

Code to reproduce:

def create_llm(agent):
    persist_directory = 'db'
    vector_db = Chroma(persist_directory=persist_directory, embedding_function=embedding)
    retriever = vector_db.as_retriever(search_type='similarity', search_kwards={'k': 4})
    embeddings_filter = EmbeddingsFilter(embeddings=embedding, similarity_threshold=0.76)
    compression_retriever = ContextualCompressionRetriever(base_compressor=embeddings_filter, base_retriever=retriever)
    qa_chain = RetrievalQAWithSourcesChain.from_llm(ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo"),
                                                    retriever=compression_retriever)
    return qa_chain


def chat(inp, history, agent):
    history = history or []
    log.debug("\n==== date/time: " + str(datetime.datetime.now()) + " ====")
    log.debug("inp: " + inp)
    history = history or []
    output = agent({"question": inp, "chat_history": history})
    answer = output["answer"]
    history.append((inp, answer))
    log.debug(history)
    return history, history

Error:

    if "stop" in input_list[0]:
IndexError: list index out of range

darkcofy avatar May 02 '23 15:05 darkcofy

+1 on this error. I don't seem to be getting the error when the chain_type = 'stuff'. It comes up for map_reduce, map_rerank and refine.

akash-ravikumar avatar May 10 '23 13:05 akash-ravikumar

+1 getting this using the following:

from langchain.chains import RetrievalQA
from langchain.chat_models import ChatOpenAI


llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0)
chroma_retriever = db.as_retriever(k=3)

qa = RetrievalQA.from_chain_type(llm=llm, 
                                    chain_type="map_reduce", 
                                    retriever=chroma_retriever,

Hello, is this problem solved?

Jason-YCX avatar May 22 '23 08:05 Jason-YCX

+1 on this error. I don't seem to be getting the error when the chain_type = 'stuff'. It comes up for map_reduce, map_rerank and refine.

Hello, is this problem solved?

Jason-YCX avatar May 22 '23 10:05 Jason-YCX

https://github.com/hwchase17/langchain/blob/276940fd9babf8aec570dd869cc84fbca1c766bf/langchain/vectorstores/milvus.py#L319

I'm using milvus where for my question I'm getting 0 documents and so index out of range error occurs

Error line:

https://github.com/hwchase17/langchain/blob/276940fd9babf8aec570dd869cc84fbca1c766bf/langchain/chains/llm.py#L95

Hello, is this problem solved?

Jason-YCX avatar May 23 '23 01:05 Jason-YCX