Implementation:Infiniflow Ragflow Float Utils
| Knowledge Sources | |
|---|---|
| Domains | Data_Processing, Utilities |
| Last Updated | 2026-02-12 06:00 GMT |
Overview
Concrete tool for safe numeric conversion and percentage normalization provided by the RAGFlow common library.
Description
The float_utils module provides get_float for safe string-to-float conversion (returns negative infinity on failure) and normalize_overlapped_percent for clamping overlap percentages to a valid 0-90 range, handling both decimal (0.0-1.0) and percentage (0-100) input formats.
Usage
Import these utilities when parsing numeric values from user input or configuration that may contain invalid strings, or when normalizing overlap percentage parameters for chunking operations.
Code Reference
Source Location
- Repository: Infiniflow_Ragflow
- File: common/float_utils.py
- Lines: 1-59
Signature
def get_float(v) -> float:
"""Convert value to float, returns -inf on failure."""
def normalize_overlapped_percent(overlapped_percent) -> int:
"""Normalize percentage to 0-90 range, auto-detecting decimal vs percentage."""
Import
from common.float_utils import get_float, normalize_overlapped_percent
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| v | any | Yes | Value to convert to float |
| overlapped_percent | float/int | Yes | Overlap percentage (0-1.0 or 0-100) |
Outputs
| Name | Type | Description |
|---|---|---|
| get_float() returns | float | Parsed float or -inf on failure |
| normalize_overlapped_percent() returns | int | Normalized percentage (0-90) |
Usage Examples
from common.float_utils import get_float, normalize_overlapped_percent
score = get_float("0.85") # 0.85
bad = get_float("not_a_num") # -inf
pct = normalize_overlapped_percent(0.15) # 15
pct2 = normalize_overlapped_percent(95) # 90 (clamped)