Getting no documents retrieved with retrieval chain #461
Replies: 5 comments 3 replies
-
Hi @Asma-droid, At first glance, this sounds like an error user code rather than an issue with LangServe. To determine whether that's the case, first try to run the chain from your notebook and don't use a server. from langchain.vectorstores import Chroma
from langchain.llms import HuggingFaceEndpoint
import os
from langchain.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough, RunnableParallel
from langchain.schema import StrOutputParser
from langchain.embeddings import HuggingFaceInferenceAPIEmbeddings
from langchain.chains import RetrievalQA
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.llms import LlamaCpp
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores import Chroma
from langchain.document_loaders import PyPDFDirectoryLoader
from langchain.llms import CTransformers
import pickle
#Step 06:Downlaod the Embeddings
embeddings = HuggingFaceEmbeddings(
model_name="thenlper/gte-large",
model_kwargs={"device": "cuda"},
encode_kwargs={"normalize_embeddings": True},
)
#Import Model
llm = LlamaCpp(
streaming = True,
model_path="/srv/nas_data/atrabelsi/Whisper-Analysis-Final/Meeting_summarization/summary/mistral-7b-instruct-v0.1.Q5_K_M.gguf",
temperature=0.01,
top_p=1,
verbose=True,
n_ctx=4096
)
chroma_index = Chroma(persist_directory='/srv/nas_data/atrabelsi/Whisper-Analysis-Final/RAG/LangServeDemo/langserve_index',
embedding_function=embeddings)
retriever = chroma_index.as_retriever(search_kwargs={"k": 1})
prompt_template = """\
Use the provided context to answer the user's question. If you don't know the answer, say you don't know.
Context:
{context}
Question:
{question}"""
rag_prompt = ChatPromptTemplate.from_template(prompt_template)
with open('./langserve_index_2/data.pkl', 'rb') as file:
# Call load method to deserialze
data = pickle.load(file)
def format_docs(data):
return "\n\n".join(doc.page_content for doc in data)
rag_chain_from_docs = (
RunnablePassthrough.assign(context=(lambda x: format_docs(x["context"])))
| rag_prompt
| llm
| StrOutputParser()
)
rag_chain_with_source = RunnableParallel(
{"context": retriever, "question": RunnablePassthrough()}
).assign(answer=rag_chain_from_docs) What do you get when you inovke this chain? rag_chain_with_source.invoke(...)`` |
Beta Was this translation helpful? Give feedback.
-
rag_chain_from_docs = (
RunnablePassthrough.assign(context=(lambda x: format_docs(x["context"])))
| rag_prompt
| llm
| StrOutputParser()
)
rag_chain_with_source = RunnableParallel(
{"context": retriever, "question": RunnablePassthrough()}
).assign(answer=rag_chain_from_docs) this approach leads us to another problem which is the answer generated with it should return based on the file information sorry i can not answer your question without mentioning sources or page numbers how can this be done? |
Beta Was this translation helpful? Give feedback.
-
is this issue solved? i am facing the same problem |
Beta Was this translation helpful? Give feedback.
-
hi ali, actually this problem happened to me because the vector store method, when it returns the chunks to my prompt/question sometimes it contains many chunks that dont represent or answer my question after improving the extraction and re ranking steps i get accurate answers and get nothing if the document doesnt have it take a look here for the vector store methods and with experiment/playing with parameters you can find the accurate one for your task also i recommend to you to train your own tokenizer model for feature extraction so it can be representative to the target domain good luck :) |
Beta Was this translation helpful? Give feedback.
-
this is the solution: #618 (comment) |
Beta Was this translation helpful? Give feedback.
-
hello,
I'am newest in langchain and langserver. I think that there is a problem when returning meta data. The API return only the answer and the question
hereis my server code
i have got empty context and empty documents
Beta Was this translation helpful? Give feedback.
All reactions