My PDF RAG has a BUG! #25192
Replies: 2 comments 1 reply
-
The error message "Process finished with exit code -1073741819 (0xC0000005)" indicates an access violation, which is often related to memory issues. This can occur due to various reasons such as incorrect handling of resources, invalid memory access, or issues with external libraries. Given the context of your PDF RAG implementation, here are a few steps to troubleshoot and potentially fix the issue:
Here is a modified version of your code with added logging for better debugging: import os
import logging
from langchain import hub
from langchain.schema import StrOutputParser
from langchain.schema.runnable import RunnablePassthrough
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores import Chroma
from langchain.document_loaders import PyPDFLoader
from langchain.llms import OpenAI
# Setup logging
logging.basicConfig(level=logging.DEBUG)
def RAG_new(path_or_link, query):
try:
system_prompt = (
"You are an assistant for question-answering tasks. "
"Use the following pieces of retrieved context to answer "
"the question. If you don't know the answer, say that you "
"don't know. Use three sentences maximum and keep the "
"answer concise."
"\n\n"
"{context}"
)
prompt = hub.ChatPromptTemplate.from_messages(
[
("system", system_prompt),
("human", "{input}"),
]
)
loader = PyPDFLoader(path_or_link)
docs = loader.load()
logging.info(f"Number of documents loaded: {len(docs)}")
text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
splits = text_splitter.split_documents(docs)
logging.info("Documents split successfully")
vectorstore = Chroma.from_documents(documents=splits, embedding=embeddings)
logging.info("Documents added to vector store successfully")
retriever = vectorstore.as_retriever()
logging.info("Retriever created successfully")
question_answer_chain = create_stuff_documents_chain(llm_4o, prompt)
logging.info("Question-answer chain created successfully")
rag_chain = create_retrieval_chain(retriever, question_answer_chain)
logging.info("RAG chain created successfully")
results = rag_chain.invoke({"input": query}).content
logging.info(f"Results: {results['context'][0].page_content}")
return results["context"][0].page_content
except Exception as e:
logging.error(f"An error occurred: {e}")
# Main function example
if __name__ == '__main__':
response = RAG_new(r"D:\dev\Chat_Bot\Web+AI.pdf", "What is the content?")
print(response) This code includes logging statements to help trace the execution flow and identify where the error might be occurring. If the issue persists, you may need to further isolate the problem by testing each component individually [1]. |
Beta Was this translation helpful? Give feedback.
-
USER_AGENT environment variable not set, consider setting it to identify your requests. Process finished with exit code -1073741819 (0xC0000005) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
It shows the bug! How should I fix it?
System Info
D:\ananconda\python.exe D:\dev\Chat_Bot\RAG.py
USER_AGENT environment variable not set, consider setting it to identify your requests.
8
1
Process finished with exit code -1073741819 (0xC0000005)
Beta Was this translation helpful? Give feedback.
All reactions