[MLsys2026 Best Paper]: https://arxiv.org/abs/2506.08276. RAG on Everything with LEANN. Enjoy 97% storage savings while running a fast, accurate, and 100% private RAG application on your personal device.
Python aifaissgpt-osslangchainllama-indexllmlocalstorageoffline-firstollamaprivacypythonragretrieval-augmented-generationvector-databasevector-searchvectors
fix: Windows MCP encoding crash and build abort on empty/corrupted PDFs (#391)
Wu-Yumindc85934f318c
diff --git a/packages/leann-core/src/leann/cli.py b/packages/leann-core/src/leann/cli.pyindex 7b6adf3..4cacdee 100644--- a/packages/leann-core/src/leann/cli.py+++ b/packages/leann-core/src/leann/cli.py@@ -175,6 +175,11 @@ def suppress_cpp_output(suppress: bool = True):def extract_pdf_text_with_pymupdf(file_path: str) -> str | None:"""Extract text from PDF using PyMuPDF for better quality."""try:+ if os.path.getsize(file_path) == 0:+ # Empty file: nothing to extract, skip instead of letting+ # fitz.EmptyFileError abort the whole build.+ return ""+import fitz # PyMuPDFdoc = fitz.open(file_path)@@ -186,11 +191,18 @@ def extract_pdf_text_with_pymupdf(file_path: str) -> str | None:except ImportError:# Fallback to default readerreturn None+ except Exception:+ # Skip corrupted PDFs instead of aborting the whole build+ return ""def extract_pdf_text_with_pdfplumber(file_path: str) -> str | None:"""Extract text from PDF using pdfplumber for better quality."""try:+ if os.path.getsize(file_path) == 0:+ # Empty file: nothing to extract, skip instead of aborting the build.+ return ""+import pdfplumbertext = ""@@ -201,6 +213,9 @@ def extract_pdf_text_with_pdfplumber(file_path: str) -> str | None:except ImportError:# Fallback to default readerreturn None+ except Exception:+ # Skip corrupted PDFs instead of aborting the whole build+ return ""class LeannCLI:diff --git a/packages/leann-core/src/leann/mcp.py b/packages/leann-core/src/leann/mcp.pyindex 458cf71..7713ec7 100755--- a/packages/leann-core/src/leann/mcp.py+++ b/packages/leann-core/src/leann/mcp.py@@ -21,9 +21,14 @@ def _leann_cmd() -> list[str]:def _run_leann(*args, timeout=120):"""Run a leann CLI command and return (returncode, stdout, stderr)."""result = subprocess.run(- ["leann", *args],+ [*_leann_cmd(), *args],capture_output=True,text=True,+ # The leann CLI prints UTF-8 (emoji, CJK, ...). Decode explicitly:+ # text=True alone falls back to the locale encoding (e.g. GBK on+ # Chinese Windows) and crashes the subprocess reader thread.+ encoding="utf-8",+ errors="replace",timeout=timeout,)return result.returncode, result.stdout, result.stderr