Skip to content

armgit / LEANN

Public Imported from GitHub
0

[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.

Fix ColQwen build crash when no images are extracted (#230)

Aakash Suresh60132374246d
diff --git a/apps/colqwen_rag.py b/apps/colqwen_rag.py
index a30058f..213b3dd 100644
--- a/apps/colqwen_rag.py
+++ b/apps/colqwen_rag.py
@@ -174,7 +174,16 @@ class ColQwenRAG:
continue
print(f"📄 Converted {len(all_images)} pages from {len(pdf_paths)} PDFs")
- print(f"All metadata: {all_metadata}")
+ if len(all_images) == 0:
+ raise RuntimeError(
+ "No PDF pages were converted to images, so there is nothing to embed.\n"
+ "Common causes:\n"
+ "- `poppler`/`pdftoppm` is missing (required by `pdf2image`)\n"
+ "- The input PDFs are encrypted/corrupt or have zero pages\n\n"
+ "Try:\n"
+ "- Install poppler (macOS: `brew install poppler`, Ubuntu: `apt-get install poppler-utils`)\n"
+ "- Re-run with a known-good PDF\n"
+ )
# Generate embeddings
print("🧠 Generating embeddings...")
@@ -274,6 +283,9 @@ class ColQwenRAG:
def _embed_images(self, images: list[Image.Image]) -> torch.Tensor:
"""Generate embeddings for a list of images."""
+ if not images:
+ raise RuntimeError("No images provided for embedding.")
+
dataset = ListDataset(images)
dataloader = DataLoader(dataset, batch_size=1, shuffle=False, collate_fn=lambda x: x)
@@ -285,6 +297,12 @@ class ColQwenRAG:
batch_embeddings = self.model(**batch_inputs)
embeddings.append(batch_embeddings.cpu())
+ if not embeddings:
+ raise RuntimeError(
+ "Image embedding produced no tensors (empty embedding list). "
+ "This usually indicates that no images were processed successfully."
+ )
+
return torch.cat(embeddings, dim=0)
def _embed_query(self, query: str) -> torch.Tensor: