Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ generate-snippets = []
uuid = ["dep:uuid"]

[[example]]
name = "search"
name = "query"
required-features = ["serde"]

[[example]]
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ Add necessary dependencies:
cargo add qdrant-client anyhow tonic tokio serde-json --features tokio/rt-multi-thread
```

Add search example from [`examples/search.rs`](./examples/search.rs) to your `src/main.rs`:
Add query example from [`examples/query.rs`](./examples/query.rs) to your `src/main.rs`:

```rust
use qdrant_client::qdrant::{
Condition, CreateCollectionBuilder, Distance, Filter, PointStruct, ScalarQuantizationBuilder,
SearchParamsBuilder, SearchPointsBuilder, UpsertPointsBuilder, VectorParamsBuilder,
Condition, CreateCollectionBuilder, Distance, Filter, PointStruct, QueryPointsBuilder,
ScalarQuantizationBuilder, SearchParamsBuilder, UpsertPointsBuilder, VectorParamsBuilder,
};
use qdrant_client::{Payload, Qdrant, QdrantError};

Expand Down Expand Up @@ -127,16 +127,18 @@ async fn main() -> Result<(), QdrantError> {
.upsert_points(UpsertPointsBuilder::new(collection_name, points))
.await?;

let search_result = client
.search_points(
SearchPointsBuilder::new(collection_name, [11.; 10], 10)
let query_result = client
.query(
QueryPointsBuilder::new(collection_name)
.query(vec![11.0; 10])
.limit(10)
.filter(Filter::all([Condition::matches("bar", 12)]))
.with_payload(true)
.params(SearchParamsBuilder::default().exact(true)),
)
.await?;
dbg!(&search_result);
// search_result = [
dbg!(&query_result);
// query_result = [
// {
// "id": 0,
// "version": 0,
Expand All @@ -151,10 +153,10 @@ async fn main() -> Result<(), QdrantError> {
// }
// ]

let found_point = search_result.result.into_iter().next().unwrap();
let found_point = query_result.result.into_iter().next().unwrap();
let mut payload = found_point.payload;
let baz_payload = payload.remove("baz").unwrap().into_json();
println!("baz: {}", baz_payload);
println!("baz: {baz_payload}");
// baz: {"qux":"quux"}

Ok(())
Expand Down
18 changes: 10 additions & 8 deletions examples/search.rs → examples/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use qdrant_client::qdrant::{
Condition, CreateCollectionBuilder, Distance, Filter, PointStruct, ScalarQuantizationBuilder,
SearchParamsBuilder, SearchPointsBuilder, UpsertPointsBuilder, VectorParamsBuilder,
Condition, CreateCollectionBuilder, Distance, Filter, PointStruct, QueryPointsBuilder,
ScalarQuantizationBuilder, SearchParamsBuilder, UpsertPointsBuilder, VectorParamsBuilder,
};
use qdrant_client::{Payload, Qdrant, QdrantError};

Expand Down Expand Up @@ -51,16 +51,18 @@ async fn main() -> Result<(), QdrantError> {
.upsert_points(UpsertPointsBuilder::new(collection_name, points))
.await?;

let search_result = client
.search_points(
SearchPointsBuilder::new(collection_name, [11.; 10], 10)
let query_result = client
.query(
QueryPointsBuilder::new(collection_name)
.query(vec![1.0; 10])
.limit(10)
.filter(Filter::all([Condition::matches("bar", 12)]))
.with_payload(true)
.params(SearchParamsBuilder::default().exact(true)),
)
.await?;
dbg!(&search_result);
// search_result = [
dbg!(&query_result);
// query_result = [
// {
// "id": 0,
// "version": 0,
Expand All @@ -75,7 +77,7 @@ async fn main() -> Result<(), QdrantError> {
// }
// ]

let found_point = search_result.result.into_iter().next().unwrap();
let found_point = query_result.result.into_iter().next().unwrap();
let mut payload = found_point.payload;
let baz_payload = payload.remove("baz").unwrap().into_json();
println!("baz: {baz_payload}");
Expand Down
38 changes: 21 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,37 +86,41 @@
//!
//! Documentation: <https://qdrant.tech/documentation/concepts/points/#upload-points>
//!
//! # Search
//! # Query (search)
//!
//! Finally, we can retrieve points in various ways, the common one being a plain similarity
//! search:
//!
//! ```no_run
//!# use qdrant_client::{Qdrant, QdrantError};
//! use qdrant_client::qdrant::SearchPointsBuilder;
//! use qdrant_client::qdrant::QueryPointsBuilder;
//!
//!# async fn search(client: &Qdrant)
//!# async fn query(client: &Qdrant)
//!# -> Result<(), QdrantError> {
//! let search_request = SearchPointsBuilder::new(
//! "my_collection", // Collection name
//! vec![0.0_f32; 512], // Search vector
//! 4, // Search limit, number of results to return
//! ).with_payload(true);
//! let query_request = QueryPointsBuilder::new("my_collection") // Collection name
//! .query(vec![0.0_f32; 512]) // Query vector
//! .limit(4) // Search limit, number of results to return
//! .with_payload(true); // Include full payload in the result
//!
//! let response = client.search_points(search_request).await?;
//! let response = client.query(query_request).await?;
//!# Ok(())
//!# }
//! ```
//!
//! The parameter for [`SearchPointsBuilder::new()`](qdrant::SearchPointsBuilder::new) constructor
//! are pretty straightforward: name of the collection, the vector and how many top-k results to
//! return. The [`with_payload(true)`](qdrant::SearchPointsBuilder::with_payload) call tells qdrant
//! to also return the (full) payload data for each point. You can also add a
//! [`filter()`](qdrant::SearchPointsBuilder::filter) call to the
//! [`SearchPointsBuilder`](qdrant::SearchPointsBuilder) to filter the result. See the
//! [`Filter`](qdrant::Filter) documentation for details.
//! The parameter for [`QueryPointsBuilder::new()`](qdrant::QueryPointsBuilder::new) is pretty
//! straightforward: the name of the collection to query in. It is combined with other
//! [functions](qdrant::QueryPointsBuilder#implementations) to further specialize your query to
//! cover all query flavors.
//!
//! Documentation: <https://qdrant.tech/documentation/concepts/search/>
//! In this example [`query(...)`](qdrant::QueryPointsBuilder::query) is used to enable vector
//! similarity search on the given vector. [`limit(4)`](qdrant::QueryPointsBuilder::limit)
//! specifies we only want up to 4 top-k results. And
//! [`with_payload(true)`](qdrant::QueryPointsBuilder::with_payload) tells Qdrant to also return
//! the (full) payload data for each point. [`filter()`](qdrant::QueryPointsBuilder::filter) is
//! also commonly used to apply payload based filtering. See the [`Filter`](qdrant::Filter)
//! documentation for details.
//!
//! Documentation: <https://qdrant.tech/documentation/concepts/search/#query-api>

#![doc(html_logo_url = "https://qdrant.tech/favicon/android-chrome-192x192.png")]
#![doc(issue_tracker_base_url = "https://github.com/qdrant/rust-client/issues/")]
Expand Down
5 changes: 2 additions & 3 deletions src/qdrant_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ pub type QdrantBuilder = QdrantConfig;
/// - [Collection operations](Self#collection-operations) - manage collections, aliases and cluster configuration
/// - [Point operations](Self#point-operations) - manage points and vectors
/// - [Payload operations](Self#payload-operations) - manage point payloads
/// - [Search operations](Self#search-operations) - search and explore points
/// - [Query operations](Self#query-operations) - query points using universal search
/// - [Query operations](Self#query-operations) - query (search) points using universal search
/// - [Index operations](Self#index-operations) - manage field and payload indices
/// - [Snapshot operations](Self#snapshot-operations) - manage instance or collection snapshots
/// - [Shard key operations](Self#sharding-key-operations) - manage shard keys
Expand All @@ -82,7 +81,7 @@ pub type QdrantBuilder = QdrantConfig;
///
/// - [`create_collection`](Self::create_collection) - create a new collection
/// - [`upsert_points`](Self::upsert_points) - insert or update points
/// - [`search_points`](Self::search_points) - search points with similarity search
/// - [`query`](Self::query) - query points with similarity search
#[derive(Clone)]
pub struct Qdrant {
/// Client configuration
Expand Down
4 changes: 4 additions & 0 deletions src/qdrant_client/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use crate::qdrant_client::{Qdrant, QdrantResult};

/// # Search operations
///
/// <div class="warning">
/// For searching, please switch to the more fully featured <a href="#query-operations">Query API</a> instead. The search API will be removed in the future.
/// </div>
///
/// Search and explore points.
///
/// Documentation: <https://qdrant.tech/documentation/concepts/search/>
Expand Down