The Wayback Machine - https://web.archive.org/web/20221217211820/https://github.com/qdrant/rust-client
Skip to content

qdrant/rust-client

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Dec 6, 2022
Dec 6, 2022
Jul 5, 2022
Sep 12, 2022
Dec 6, 2022
Jun 24, 2022
fmt
Jul 24, 2022

rust-client

Rust client for Qdrant vector search engine.

Crates.io Apache 2.0 licensed

Installation

cargo add qdrant-client

Package is available in crates.io

Usage

Run Qdrant with enabled gRPC interface:

# With env variable
docker run -p 6333:6333 -p 6334:6334 \
    -e QDRANT__SERVICE__GRPC_PORT="6334" \
    qdrant/qdrant

Or by updating the configuration file:

service:
  grpc_port: 6334

More info about gRPC in documentation.

Making requests

use std::time::Duration;
use tonic::transport::Channel;
use qdrant_client::QdrantClient;
use qdrant_client::qdrant::ListCollectionsRequest;

#[tokio::main]
async fn main() {
    // Example of top level client
    // You may also use tonic-generated client from `src/qdrant.rs`
    let config = QdrantClientConfig::from_url("http://localhost:6334");
    let client = QdrantClient::new(Some(config)).await?;

    let collections_list = client.list_collections().await?;
    // ListCollectionsResponse { collections: [CollectionDescription { name: "test" }], time: 3.27e-6 }

    let collection_name = "test";
    client.delete_collection(collection_name).await?;

    client
        .create_collection(&CreateCollection {
            collection_name: collection_name.into(),
            vectors_config: Some(
                VectorsConfig {
                    config: Some(
                        Config::Params(
                            VectorParams {
                                size: 10,
                                distance: Distance::Cosine.into()
                            }
                        )
                    )
                }
            ),
        })
        .await?;

    let collection_info = client.collection_info(collection_name).await?;

    let payload: Payload = vec![
        ("foo", "Bar".into()),
        ("bar", 12.into()),
    ].into_iter().collect::<HashMap<_, Value>>().into();

    let points = vec![
        PointStruct::new(0, vec![12.; 10], payload)
    ];
    client.upsert_points_blocking(collection_name, points).await?;

    let search_result = client
        .search_points(&SearchPoints {
            collection_name: collection_name.into(),
            vector: vec![11.; 10],
            filter: None,
            limit: 10,
            with_vector: None,
            with_payload: None,
            params: None,
            score_threshold: None,
            offset: None,
        })
        .await?;
    // search_result = SearchResponse {
    //     result: [
    //         ScoredPoint {
    //         id: Some(
    //             PointId {
    //                 point_id_options: Some(Num(0)),
    //             },
    //         ),
    //         payload: {},
    //         score: 1.0000001,
    //         vector: [],
    //         version: 0,
    //     },
    //     ],
    //     time: 5.312e-5,
    // }
}