Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions vllm_mlx/models/mllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions vllm_mlx/vision_embedding_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading