FFFF [Bug]: metafilter coerces NaN and Infinity strings into non-finite floats, breaking ES/OpenSearch JSON encoding · Issue #22698 · infiniflow/ragflow · GitHub
[go: up one dir, main page]

Skip to content

[Bug]: metafilter coerces NaN and Infinity strings into non-finite floats, breaking ES/OpenSearch JSON encoding #22698

Open

Description

@adityajai119

Self Checks

  • I have searched for existing issues, including closed ones.
  • I confirm that I am using English to submit this report.
  • Non-english title submitions will be closed directly.
  • Please do not modify this template :) and fill in all the required fields.

RAGFlow workspace code commit ID

da4a155

RAGFlow image version

N/A (local source checkout of main at da4a155)

Other environment information

  • OS: Windows 11 (amd64)
  • Go: 1.27.3 (CGO_ENABLED=0)

Actual behavior

In internal/engine/metafilter/meta_filter.go, both coerceScalar (used by = and ≠) and coerceRangeValue (used by >, <, ≥, ≤) call strconv.ParseFloat(s, 64) without checking whether the parsed float64 is finite (!math.IsNaN(parsed) && !math.IsInf(parsed, 0)).

In Go, strconv.ParseFloat accepts "NaN", "Inf", "+Inf", "-Inf", "Infinity", "+Infinity", and "-Infinity" case-insensitively and returns non-finite float64 values (NaN, +Inf, -Inf). As a result, filtering metadata on ordinary string values such as engine = "Infinity", department = "Inf", or author = "Nan" embeds a non-finite float64 directly into the generated Elasticsearch/OpenSearch query map:

  • BuildMetaFilterQuery produces {"term": {"meta_fields.engine": +Inf}} instead of a case-insensitive keyword match {"term": {"meta_fields.engine.keyword": {"value": "infinity", "case_insensitive": true}}}.
  • When internal/engine/elasticsearch/metadata.go or internal/engine/opensearch/metadata.go JSON-encodes that query via json.NewEncoder(&buf).Encode(requestBody), encoding/json fails with json: unsupported value: +Inf (or NaN / -Inf), causing FilterDocIdsByMetaPushdown to silently abort push-down.

Expected behavior

coerceScalar and coerceRangeValue should only coerce finite numeric values to float64. Non-finite strings like "NaN", "Inf", and "Infinity" should remain strings (lowercased in coerceScalar and matched against .keyword, preserved as strings in coerceRangeValue), producing valid JSON-serializable Elasticsearch/OpenSearch queries.

Steps to reproduce

  1. Call metafilter.BuildMetaFilterQuery([]map[string]interface{}{{"key": "engine", "op": "=", "value": "Infinity"}}, "and", []string{"kb-1"}) (or with "NaN", "Inf", "-Inf", "-Infinity", or with range operators >, <, ≥, ≤).
  2. Call json.Marshal on the returned query map.
  3. Observe json: unsupported value: +Inf (or NaN / -Inf).

Additional information

internal/engine/metafilter is shared by both Elasticsearch and OpenSearch metadata push-down (internal/engine/elasticsearch/metadata.go and internal/engine/opensearch/metadata.go). A fix is ready.

AI-assisted: drafted with an AI coding agent; the tests above were run locally.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0