Skip to content

MrBeeMovie/rust-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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,
    // }
}

About

Rust client for Qdrant vector search engine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 97.4%
  • Shell 2.6%