Problem
On Windows, PdfToEntries.extract_text cannot index any PDF because PyMuPDFLoader is passed the path of a still-open NamedTemporaryFile(delete=True), and Windows disallows a second open on that path.
Cite
src/khoj/processor/content/pdf/pdf_to_entries.py:100-105
with tempfile.NamedTemporaryFile(suffix=".pdf", delete=True) as tmpf:
tmpf.write(pdf_file)
tmpf.flush()
loader = PyMuPDFLoader(tmpf.name)
pdf_entries_per_file = loader.load()
Per Python docs: on Windows the name cannot be used to open the file a second time while the handle is still open.
Steps
- Windows 11,
pip install khoj (Python 3.10-3.12 per pyproject.toml).
- Upload any PDF via
/api/content?t=pdf.
Expected
PDF is indexed.
Actual
extract_text catches PermissionError: [WinError 32] The process cannot access the file because it is being used by another process and logs Unable to process file: <bytes>. This file will not be indexed. No entries created.
Environment
OS: Windows 11; Python 3.10-3.12; khoj 2.0.0-beta.28; pymupdf == 1.24.11, langchain-community == 0.3.31 (from pyproject.toml).
Suggested fix
Use delete=False + explicit os.unlink(tmpf.name) in a finally block, or (Python 3.12+) delete_on_close=False.
Thanks for maintaining khoj-ai/khoj!
Problem
On Windows,
PdfToEntries.extract_textcannot index any PDF becausePyMuPDFLoaderis passed the path of a still-openNamedTemporaryFile(delete=True), and Windows disallows a second open on that path.Cite
src/khoj/processor/content/pdf/pdf_to_entries.py:100-105Per Python docs: on Windows the name cannot be used to open the file a second time while the handle is still open.
Steps
pip install khoj(Python 3.10-3.12 perpyproject.toml)./api/content?t=pdf.Expected
PDF is indexed.
Actual
extract_textcatchesPermissionError: [WinError 32] The process cannot access the file because it is being used by another processand logsUnable to process file: <bytes>. This file will not be indexed.No entries created.Environment
OS: Windows 11; Python 3.10-3.12; khoj 2.0.0-beta.28;
pymupdf == 1.24.11,langchain-community == 0.3.31(frompyproject.toml).Suggested fix
Use
delete=False+ explicitos.unlink(tmpf.name)in afinallyblock, or (Python 3.12+)delete_on_close=False.Thanks for maintaining khoj-ai/khoj!