Hanan Shteingart
Hanan Shteingart

Reputation: 9078

ConversationalRetrievalChain with ConversationBufferMemory "TypeError: tuple indices must be integers or slices, not str"

When I run langchain's ConversationalRetrievalChain with ConversationBufferMemory I get an error:

"TypeError: tuple indices must be integers or slices, not str"

The problem is in: langchain/chains/conversational_retrieval/base.py:25) This line: human = "Human: " + human_s tries to concat a tuple and a string.

human_s is a tuple of this form: ('content', 'question user asked') Instead, I would expect human_s to be "question user asked".

This is the code I've used:

embedder = get_embedder()
logger.info("loading vector store from {}".format(vector_store_path))
vector_store = FAISS.load_local(vector_store_path, embeddings=embedder)
llm = get_llm()
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
qa_chain = ConversationalRetrievalChain.from_llm(
    retriever=vector_store.as_retriever(),
    llm=llm,
    memory=memory, verbose=True
)
while True:
    question = input("You:")
    result = qa_chain({'question': question})
    response = result['answer']
    print(response)

Upvotes: 0

Views: 171

Answers (1)

Hanan Shteingart
Hanan Shteingart

Reputation: 9078

It was a known bug in langchain https://github.com/langchain-ai/langchain/issues/3077 solved by updating to latest.

Upvotes: 0

Related Questions