Skip to content

Add support for retry-after header#95

Merged
tellet-q merged 7 commits intomasterfrom
retry-after-header
Mar 18, 2025
Merged

Add support for retry-after header#95
tellet-q merged 7 commits intomasterfrom
retry-after-header

Conversation

@tellet-q
Copy link
Contributor

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

Add support for following responses from Qdrant:

Rate limiter hit for REST API: qdrant/qdrant#5917
Rate limiter hit for gRPC: qdrant/qdrant#6072

  • Introduce ResourceExhaustedError for grpc client and QdrantClientResourceExhaustedError for rest client.
  • Bump undici version to 5.28.5 due to GHSA-c76h-2ccp-4975

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

import { QdrantClient, QdrantClientResourceExhaustedError } from "@qdrant/js-client-grpc";

const client = new QdrantClient({ host: "localhost", port: 6334, timeout: 1000, checkCompatibility: false });

try {
    console.log("start hit_rate_limit");

    for (let i = 0; i < 100; i++) {
        try {
            await client.api('points').query({
                collectionName: "benchmark",
                queryVector: [0.0, 0.0, 0.0, 0.0],
                limit: 4
            });
        } catch (error) {
            if (error instanceof QdrantClientResourceExhaustedError) {
                console.log(`hit_rate_limit! ${error}`);
                console.log(`retry after: ${error.retry_after} seconds`);
                break;
            }
            throw error;
        }
    }

    console.log("done hit_rate_limit");

} catch (err) {
    console.error('Could not do something:', err);
}
console.log('Done');

Example output:

start hit_rate_limit
hit_rate_limit! QdrantClientResourceExhaustedError: [resource_exhausted] Resource exhausted: Retry after specified duration
retry after: 1 seconds
done hit_rate_limit
Done

@tellet-q tellet-q changed the title WIP: Add support for retry-after header Add support for retry-after header Mar 10, 2025
retry-after may contain number of seconds or timestamp
Copy link
Member

@Anush008 Anush008 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🙏 One little suggestion.

@tellet-q tellet-q merged commit c5aa201 into master Mar 18, 2025
6 checks passed
@tellet-q tellet-q deleted the retry-after-header branch March 18, 2025 07:38
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.

2 participants