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.

chore: remove unused type ignores

Aakash Suresh673401113a0f
diff --git a/apps/colqwen_rag.py b/apps/colqwen_rag.py
index cdc7f40..5878c48 100644
--- a/apps/colqwen_rag.py
+++ b/apps/colqwen_rag.py
@@ -12,7 +12,7 @@ import argparse
import os
import sys
from pathlib import Path
-from typing import Optional, cast
+from typing import Any, Optional, cast
# Add LEANN packages to path
_repo_root = Path(__file__).resolve().parents[1]
@@ -65,6 +65,9 @@ class ColQwenRAG:
ColQwen2,
ColQwen2Processor,
)
+ from colpali_engine.utils.torch_utils import ListDataset
+
+ self._list_dataset_cls: type[Any] = ListDataset
if model_type == "colqwen2":
self.model_name = "vidore/colqwen2-v1.0"
@@ -327,7 +330,7 @@ class ColQwenRAG:
if not images:
raise RuntimeError("No images provided for embedding.")
- dataset = ListDataset(images)
+ dataset = self._list_dataset_cls(images)
dataloader = DataLoader(dataset, batch_size=1, shuffle=False, collate_fn=lambda x: x)
embeddings = []
diff --git a/apps/multimodal/vision-based-pdf-multi-vector/leann_multi_vector.py b/apps/multimodal/vision-based-pdf-multi-vector/leann_multi_vector.py
index 9138261..b43f641 100644
--- a/apps/multimodal/vision-based-pdf-multi-vector/leann_multi_vector.py
+++ b/apps/multimodal/vision-based-pdf-multi-vector/leann_multi_vector.py
@@ -70,7 +70,7 @@ def _get_backend_leann_multi_vector() -> type:
if backend_path is None:
# Fallback to local implementation in this module
try:
- cls = LeannMultiVector # type: ignore[name-defined]
+ cls = LeannMultiVector
_BACKEND_LEANN_CLASS = cls
return cls
except Exception as e:
@@ -87,7 +87,7 @@ def _get_backend_leann_multi_vector() -> type:
raise ImportError(f"Failed to create spec for backend module at {backend_path}")
backend_module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = backend_module
- spec.loader.exec_module(backend_module) # type: ignore[assignment]
+ spec.loader.exec_module(backend_module)
if not hasattr(backend_module, "LeannMultiVector"):
raise ImportError(f"'LeannMultiVector' not found in backend module at {backend_path}")
@@ -954,7 +954,7 @@ class LeannMultiVector:
mapping: dict[int, list[int]] = {}
for idx, meta in enumerate(self._labels_meta):
try:
- doc_id = int(meta["doc_id"]) # type: ignore[index]
+ doc_id = int(meta["doc_id"])
except Exception:
continue
mapping.setdefault(doc_id, []).append(idx)
@@ -996,7 +996,7 @@ class LeannMultiVector:
except Exception:
continue
if 0 <= idx < len(self._labels_meta):
- doc_id = int(self._labels_meta[idx]["doc_id"]) # type: ignore[index]
+ doc_id = int(self._labels_meta[idx]["doc_id"])
else:
continue
score = float(distances[b][k])
@@ -1067,7 +1067,7 @@ class LeannMultiVector:
except Exception:
continue
if 0 <= idx < len(self._labels_meta):
- candidate_doc_ids.add(int(self._labels_meta[idx]["doc_id"])) # type: ignore[index]
+ candidate_doc_ids.add(int(self._labels_meta[idx]["doc_id"]))
# Exact scoring per doc (parallelized)
assert self._docid_to_indices is not None
diff --git a/packages/leann-core/src/leann/api.py b/packages/leann-core/src/leann/api.py
index 9b527f9..71904e9 100644
--- a/packages/leann-core/src/leann/api.py
+++ b/packages/leann-core/src/leann/api.py
@@ -797,7 +797,7 @@ class LeannBuilder:
f"Dimension mismatch during update: existing index uses {expected_dim}, got {embedding_dim}."
)
- from leann_backend_hnsw import faiss # type: ignore
+ from leann_backend_hnsw import faiss
embeddings = np.ascontiguousarray(embeddings, dtype=np.float32)
if distance_metric == "cosine":
diff --git a/packages/leann-core/src/leann/embedding_compute.py b/packages/leann-core/src/leann/embedding_compute.py
index e655917..d39e6b6 100644
--- a/packages/leann-core/src/leann/embedding_compute.py
+++ b/packages/leann-core/src/leann/embedding_compute.py
@@ -483,7 +483,7 @@ def compute_embeddings_sentence_transformers(
torch.set_num_threads(min(8, os.cpu_count() or 4))
try:
# PyTorch's ContextProp type is complex; cast for type checker
- torch.backends.mkldnn.enabled = True # type: ignore[assignment]
+ torch.backends.mkldnn.enabled = True
except AttributeError:
pass
@@ -626,7 +626,7 @@ def compute_embeddings_sentence_transformers(
# This path is reserved for an aggressively optimized FP pipeline
# (no quantization), mainly for experimentation.
try:
- from transformers import AutoModel, AutoTokenizer # type: ignore
+ from transformers import AutoModel, AutoTokenizer
except Exception as e:
raise ImportError(f"transformers is required for manual_tokenize=True: {e}")
@@ -652,7 +652,7 @@ def compute_embeddings_sentence_transformers(
# Optional compile on supported devices
if device in ["cuda", "mps"]:
try:
- hf_model = torch.compile( # type: ignore
+ hf_model = torch.compile(
hf_model, mode="reduce-overhead", dynamic=True
)
logger.info(
@@ -670,7 +670,7 @@ def compute_embeddings_sentence_transformers(
show_progress = is_build or len(texts) > 32
try:
if show_progress:
- from tqdm import tqdm # type: ignore
+ from tqdm import tqdm
batch_iter = tqdm(
range(0, len(texts), batch_size),
@@ -891,7 +891,7 @@ def compute_embeddings_mlx(chunks: list[str], model_name: str, batch_size: int =
# Tokenize all chunks in the batch
batch_token_ids = []
for chunk in batch_chunks:
- token_ids = tokenizer.encode(chunk) # type: ignore
+ token_ids = tokenizer.encode(chunk)
batch_token_ids.append(token_ids)
# Pad sequences to the same length for batch processing
diff --git a/packages/leann-core/src/leann/interactive_utils.py b/packages/leann-core/src/leann/interactive_utils.py
index ac803d2..44c5f43 100644
--- a/packages/leann-core/src/leann/interactive_utils.py
+++ b/packages/leann-core/src/leann/interactive_utils.py
@@ -12,9 +12,9 @@ from typing import Callable, Optional
# Try to import readline with fallback for Windows
HAS_READLINE = False
-readline = None # type: ignore[assignment]
+readline = None
try:
- import readline # type: ignore[no-redef]
+ import readline
HAS_READLINE = True
except ImportError:
diff --git a/packages/leann-core/src/leann/server.py b/packages/leann-core/src/leann/server.py
index e58bfe6..6a76209 100644
--- a/packages/leann-core/src/leann/server.py
+++ b/packages/leann-core/src/leann/server.py
@@ -25,8 +25,8 @@ from .cli import LeannCLI
def _ensure_fastapi():
"""Lazy import FastAPI and Pydantic, with a clear error if missing."""
try:
- from fastapi import FastAPI, HTTPException # type: ignore
- from pydantic import BaseModel # type: ignore
+ from fastapi import FastAPI, HTTPException
+ from pydantic import BaseModel
except ImportError as e: # pragma: no cover - dependency error path
raise RuntimeError(
"FastAPI and pydantic are required for the LEANN HTTP server.\n"
@@ -67,7 +67,7 @@ def _list_current_project_indexes() -> list[dict[str, Any]]:
current_path = Path.cwd()
indexes: list[dict[str, Any]] = []
- for idx in cli._discover_indexes_in_project(current_path): # type: ignore[attr-defined]
+ for idx in cli._discover_indexes_in_project(current_path):
# `idx` includes keys like: name, type (cli/app), status, size_mb
indexes.append(
{
@@ -139,7 +139,7 @@ def create_app():
try:
index_path = _resolve_index_path(index_name)
except FileNotFoundError as e:
- raise HTTPException(status_code=404, detail=str(e)) # type: ignore[misc]
+ raise HTTPException(status_code=404, detail=str(e))
searcher = LeannSearcher(index_path=index_path)
results = searcher.search(
@@ -177,7 +177,7 @@ def main() -> None:
leann serve
"""
try:
- import uvicorn # type: ignore
+ import uvicorn
except ImportError as e: # pragma: no cover - dependency error path
raise RuntimeError(
"uvicorn is required to run the LEANN HTTP server.\n"