I used ConversationalRetrievalChain to create a chain that outputs search-based answers.
The structure is to find the top 5 data by hybrid search and LLM generates the answer.
When a user asks for additional answers after the first search result, is it possible to search the 6th-10th ranked results from Pinecone index after the first 5 ranked results?
python code :
retriever = PineconeHybridSearchRetriever(
embeddings=embed, sparse_encoder=bm25, index=index, top_k= int(5), alpha= float(0.7))
llm = ChatOpenAI(model_name = “gpt-3.5-turbo-16k-0613”, temperature=0)
streaming_llm = OpenAI(model_name = “gpt-3.5-turbo-16k-0613”,streaming=True, callbacks=[StreamingStdOutCallbackHandler()], temperature=0)
general_user_template = “Question:{question}
”
messages = [
SystemMessagePromptTemplate.from_template(general_system_template,input_variables=[“context”, “question”]),
HumanMessagePromptTemplate.from_template(general_user_template)
]
qa_prompt = ChatPromptTemplate.from_messages( messages ,)
question_generator = LLMChain(llm=llm, prompt=CONDENSE_QUESTION_PROMPT)
doc_chain = load_qa_chain(streaming_llm, chain_type=“stuff”, prompt=qa_prompt,verbose=True)
qa = ConversationalRetrievalChain(
retriever= retriever,
combine_docs_chain=doc_chain, question_generator=question_generator,
return_source_documents=True, return_generated_question = True,#memory=memory
)