Skip to content

Add support for retry-after header#69

Merged
tellet-q merged 14 commits intomasterfrom
retry-after-header
Mar 20, 2025
Merged

Add support for retry-after header#69
tellet-q merged 14 commits intomasterfrom
retry-after-header

Conversation

@tellet-q
Copy link
Contributor

@tellet-q tellet-q commented Mar 18, 2025

Add support for following responses from Qdrant:

Rate limiter hit for gRPC: qdrant/qdrant#6072

Usage example for strict mode ("read_rate_limit": 60, "write_rate_limit": 60):

package main

import (
	"context"
	"fmt"

	"github.com/qdrant/go-client/qdrant"
)

func hitWriteRateLimit(qClient *qdrant.Client) {
	fmt.Println("start hit_rate_limit")

	for i := 0; i < 500; i++ {
		_, err := qClient.Upsert(context.Background(), &qdrant.UpsertPoints{
			CollectionName: "benchmark",
			Points: []*qdrant.PointStruct{
				{
					Id:      qdrant.NewIDNum(uint64(i)),
					Vectors: qdrant.NewVectors(0.05, 0.61, 0.76, 0.74),
				},
			},
		})
		if err != nil {
			var resourceErr *qdrant.QdrantResourceExhaustedError
			if errors.As(err, &resourceErr) {
				fmt.Printf("hit_rate_limit! %s\nretry after: %d seconds\n", resourceErr.Error(), resourceErr.RetryAfterS)
				break
			}
			panic(err) // This runs only if the error is not QdrantResourceExhaustedError
		}
	}
	fmt.Println("done hit_rate_limit")
}

func collectionExists(qClient *qdrant.Client) {
	exists, err := qClient.CollectionExists(context.Background(), "benchmark")
	if err != nil {
		panic(err)
	}
	fmt.Println("Collection exists: ", exists)
}

func main() {
	client, err := qdrant.NewClient(&qdrant.Config{
		Host:                   "localhost",
		Port:                   6334,
		SkipCompatibilityCheck: false,
	})
	if err != nil {
		panic(err)
	}
	collectionExists(client)
	hitWriteRateLimit(client)
}

@tellet-q tellet-q requested a review from Robert-Stam March 18, 2025 14:51
@tellet-q tellet-q changed the title WIP: add grpc interceptor WIP: Add support for retry-after header Mar 19, 2025
@tellet-q tellet-q requested a review from Anush008 March 19, 2025 08:15
@tellet-q tellet-q changed the title WIP: Add support for retry-after header Add support for retry-after header Mar 19, 2025
@tellet-q tellet-q requested a review from Anush008 March 20, 2025 07:23
@tellet-q tellet-q merged commit 7866973 into master Mar 20, 2025
2 checks passed
@tellet-q tellet-q deleted the retry-after-header branch March 20, 2025 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants