Skip to content

Parse retry-after header#215

Merged
tellet-q merged 3 commits intodevfrom
retry-after-header
Mar 20, 2025
Merged

Parse retry-after header#215
tellet-q merged 3 commits intodevfrom
retry-after-header

Conversation

@tellet-q
Copy link
Contributor

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

Add support for following responses from Qdrant:

Rate limiter hit for gRPC: qdrant/qdrant#6072

  • Introduce QdrantError::ResourceExhaustedError for the client

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

use qdrant_client::{Qdrant, QdrantError};
use qdrant_client::qdrant::QueryPointsBuilder;

#[tokio::main]
async fn main() {
    let collection_name = "benchmark";

    let client = Qdrant::from_url("http://localhost:6334").build();

    match client {
        Ok(client) => {
            match client.collection_exists(collection_name).await {
                Ok(exists) => {
                    if exists {
                        println!("Collection '{}' exists!", collection_name);
                    } else {
                        println!("Collection '{}' does not exist.", collection_name);
                    }
                }
                Err(err) => {
                    eprintln!("Error checking collection existence: {:?}", err);
                }
            }

            match client.health_check().await {
                Ok(response) => {
                    println!("Qdrant is healthy: {:?}", response);
                }
                Err(err) => {
                    eprintln!("Qdrant is not healthy: {:?}", err);
                }
            }

            println!("start hit_rate_limit");
            for _ in 0..100 {
                let result = client.query(
                    QueryPointsBuilder::new("benchmark")
                        .query(vec![0.2, 0.1, 0.9, 0.7])
                ).await;

                match result {
                    Ok(_) => {},
                    Err(err) => {
                        match err {
                            QdrantError::ResourceExhaustedError { status: _, retry_after_seconds } => {
                                println!("Limit hit! Retry after: {:?} seconds", retry_after_seconds);
                                break;
                            },
                            _ => {
                                println!("Error: {:?}", err);
                                break;
                            }
                        }
                    }
                }
            }
            println!("done hit_rate_limit");
        }
        Err(err) => {
            eprintln!("Failed to create Qdrant client: {:?}", err);
        }
    }
}

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --all --all-features command?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@tellet-q tellet-q requested review from Anush008 and generall March 19, 2025 13:23
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 🙏

@tellet-q tellet-q merged commit 739cae0 into dev Mar 20, 2025
2 checks passed
@tellet-q tellet-q deleted the retry-after-header branch March 20, 2025 09:38
coszio pushed a commit that referenced this pull request Apr 22, 2025
* Parse retry-after header from server
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