go-redis/redis · error

invalid score format

Error message

invalid score format

What it means

Raised in parseFTSearch (search_commands.go:2635-2638) when WITHSCORES was requested, the score element decoded as a string, but strconv.ParseFloat could not parse it into a float64. FT.SEARCH scores are textual floating-point; a non-numeric token here means the reply is malformed.

Source

Thrown at search_commands.go:2638

			return FTSearchResult{}, fmt.Errorf("invalid document ID format")
		}

		doc := Document{
			ID:     docID,
			Fields: make(map[string]string),
		}
		i++

		if noContent {
			results = append(results, doc)
			continue
		}

		if withScores && i < len(data) {
			if scoreStr, ok := data[i].(string); ok {
				score, err := strconv.ParseFloat(scoreStr, 64)
				if err != nil {
					return FTSearchResult{}, fmt.Errorf("invalid score format")
				}
				doc.Score = &score
				i++
			}
		}

		if withPayloads && i < len(data) {
			if payload, ok := data[i].(string); ok {
				doc.Payload = &payload
				i++
			}
		}

		if withSortKeys && i < len(data) {
			if sortKey, ok := data[i].(string); ok {
				doc.SortKey = &sortKey
				i++
			}

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Run the same query in redis-cli with WITHSCORES and inspect the score tokens.
  2. Verify WithScores is the only relevant flag and the schema actually scores documents.
  3. Upgrade go-redis and Redis Stack to matched, current versions.
  4. If you control the scorer, ensure it emits parseable floats.

Example fix

// before
opts := &redis.FTSearchOptions{WithScores: true}
res, err := client.FTSearchWithArgs(ctx, idx, q, opts).Result()
// after — confirm scores parse via raw inspection
raw, _ := client.FTSearchWithArgs(ctx, idx, q, opts).RawResult()
log.Printf("raw=%#v", raw)
Defensive patterns

Strategy: validation

Try / catch

res, err := client.FTSearchWithArgs(ctx, idx, q, &redis.FTSearchOptions{WithScores: true}).Result()
if err != nil && strings.Contains(err.Error(), "invalid score format") {
    raw, _ := client.FTSearchWithArgs(ctx, idx, q, &redis.FTSearchOptions{WithScores: true}).RawResult()
    log.Printf("score not parseable; raw=%#v", raw)
}

Prevention

When it happens

Trigger: Calling FTSearchWithArgs with WithScores:true against a reply where the score slot contains a non-numeric string (e.g. 'NaN', 'inf' in unexpected casing, or a sentinel like '__deleted__'), or where flag misalignment placed a field value where the score should be.

Common situations: Custom scorer returning unusual values, an upstream RESP proxy rewriting numbers, or version skew between the client parser and a newer Redis Stack release.

Related errors


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /data/errors/7684954bacd32e9a.json. Report an issue: GitHub.