diff --git a/vllm_mlx/models/mllm.py b/vllm_mlx/models/mllm.py index 5a3551eb1..ec761c3f2 100644 --- a/vllm_mlx/models/mllm.py +++ b/vllm_mlx/models/mllm.py @@ -465,8 +465,10 @@ def save_base64_image(base64_string: str) -> str: """Save base64 image to temp file and return path. Caches identical images.""" import hashlib - # Hash the full base64 string to prevent collisions between images - # with identical headers (e.g. JPEG images sharing first 1000 chars) + # Hash the FULL base64 string — not just a prefix. + # Using only the first 1000 chars caused cache collisions between + # different images with identical JPEG headers (e.g. invoices from + # the same PDF renderer), returning a previous request's image. image_hash = hashlib.sha256(base64_string.encode()).hexdigest() # Return cached path if available and file still exists diff --git a/vllm_mlx/vision_embedding_cache.py b/vllm_mlx/vision_embedding_cache.py index 09749aaa9..106a729fa 100644 --- a/vllm_mlx/vision_embedding_cache.py +++ b/vllm_mlx/vision_embedding_cache.py @@ -106,9 +106,10 @@ def compute_image_hash(image_path: str) -> str: try: path = Path(image_path) if path.exists() and path.is_file(): - # Hash file content (first 64KB for speed) + # Hash full file content (not truncated — truncation can + # cause collisions for images with identical headers) with open(path, "rb") as f: - content = f.read(65536) + content = f.read() return hashlib.sha256(content).hexdigest()[:16] else: # Hash the string (URL or base64)