Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for retry-after header #95

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

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, ResourceExhaustedError } 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 ResourceExhaustedError) {
                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! ResourceExhaustedError: [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
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.

1 participant