docsearch = Pinecone.from_existing_index(index_name=“chatbot”, embedding=embeddings)
def question_answering(request):
retriever = docsearch.as_retriever(include_metadata=True, metadata_key = 'source',top_k=1)
qa_chain = RetrievalQA.from_chain_type(llm=llm,
chain_type="stuff",
retriever=retriever,
return_source_documents=True)
response = qa_chain(request['question'])
if response['source_documents']:
most_relevant_document = response['source_documents'][0].metadata['source']
response = {
“statusCode”: 200,
"body": {
"reference": response['source_documents'][0].metadata['source'],
"answer":response['result']
}
}
getting reference link , even content is not present in index.
Note:
we are created embeddings for 4 different documents and stored in pinecone, we are performing querying, when we ask a question for which the answer is not presented in any of 4 documents. In that case we should not get source instaed we should get empty.
ex: we are getting like this → metadata={‘page’: 0.0, ‘source’: ‘/home/sravani/YTP’}),