I'm work on a RAG system and when I want to a prompt from a user my code don't printing the Relevant and after that it's ending the my running section.
My Code:
from dotenv import load_dotenv
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.document_loaders import PyMuPDFLoader,TextLoader,PyPDFLoader
from langchain_community.vectorstores import Chroma
from langchain_openai import OpenAIEmbeddings
from langchain.schema import Document
load_dotenv()
files= [
"my pdf file path is here (You can call it just path if you want)"
]
docs= [PyPDFLoader(file).load() for file in files ]
docs_list = [item for sublist in docs for item in sublist]
#docs_list = [Document(page_content=item.page_content) for item in txt_docs]
text_splitter= RecursiveCharacterTextSplitter.from_tiktoken_encoder(
chunk_size= 250, chunk_overlap= 0
)
splits= text_splitter.split_documents(docs_list)
vectorestore= Chroma.from_documents(
documents=splits,
embedding=OpenAIEmbeddings(),
collection_name="rag-chroma",
persist_directory="./.chroma1.21"
)
retriever= Chroma(
collection_name="rag-chroma",
persist_directory="./.chroma1.21",
embedding_function=OpenAIEmbeddings(),
).as_retriever()
if __name__== "__main__":
print(docs_list)
This code making an embedding and makes chunks but when as a user, which is a question in the document, I asked, it's always ending code and gives me a message:
"This question don't relevant with document"
What should I do to solving this problem?