Skip to content

Server crashes with ValueError: Out of range float values are not JSON compliant: inf #871

@roamergu

Description

@roamergu

Bug Description

OpenViking server crashes when processing certain requests that result in floating-point infinity (inf) values during vector similarity calculations or other numerical operations.

Error Log

2026-03-22 16:18:58,328 - openviking.server.app - WARNING - Unhandled exception: Out of range float values are not JSON compliant: inf
2026-03-22 16:18:58,331 - uvicorn.error - ERROR - Exception in ASGI application
...
ValueError: Out of range float values are not JSON compliant: inf

Root Cause Analysis

  1. During vector similarity computation or other numerical operations, the system produces inf (infinity) as a result
  2. This typically occurs due to division by zero or edge cases in similarity calculations
  3. When the server attempts to serialize the response to JSON, it fails because JSON standard does not support inf values
  4. The unhandled exception causes the server to crash

Environment

  • OpenViking version: 0.2.9
  • Python version: 3.13
  • Embedding model: BAAI/bge-m3 (via SiliconFlow API)
  • VLM: kimi-k2.5 (via Aliyun API)

Suggested Fix

Handle infinity values before JSON serialization:

  1. Check for inf and -inf values in numerical results
  2. Replace with appropriate sentinel values (e.g., null, max/min float, or a special indicator)
  3. Or use a custom JSON encoder that handles infinity values gracefully

Example fix pattern:

import math

def sanitize_for_json(obj):
    if isinstance(obj, float):
        if math.isinf(obj):
            return None  # or str(obj) for "inf"/"-inf"
    return obj

Impact

Server crash requires manual restart. This affects service reliability, especially for production deployments.

Workaround

Use a process manager (systemd/pm2) with auto-restart capability to recover from crashes automatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions