From 936784c78b79f25173005e913e349fabadc3d334 Mon Sep 17 00:00:00 2001 From: Arnaud Gourlay Date: Wed, 15 Jan 2025 15:42:40 +0100 Subject: [PATCH 1/5] Document HasVector condition --- .../documentation/concepts/filtering.md | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/qdrant-landing/content/documentation/concepts/filtering.md b/qdrant-landing/content/documentation/concepts/filtering.md index c5501341a..f12e6f529 100644 --- a/qdrant-landing/content/documentation/concepts/filtering.md +++ b/qdrant-landing/content/documentation/concepts/filtering.md @@ -2977,3 +2977,116 @@ Filtered points would be: { "id": 5, "city": "Moscow", "color": "green" } ] ``` + + +### Has vector + +*Available as of v1.13.0* + +This condition enables filtering by the presence of a given named vector on a point. + +For example, to search for points with the `image` vector: + +```http +POST /collections/{collection_name}/points/scroll +{ + "filter": { + "must": [ + { "has_vector": "image" } + ] + } + ... +} +``` + +```python +client.scroll( + collection_name="{collection_name}", + scroll_filter=models.Filter( + must=[ + models.HasVectorCondition(has_vector="image"), + ], + ), +) +``` + + +```typescript +client.scroll("{collection_name}", { + filter: { + must: [ + { + has_vector: "image", + }, + ], + }, +}); +``` + +```rust +use qdrant_client::qdrant::{Condition, Filter, ScrollPointsBuilder}; +use qdrant_client::Qdrant; + +let client = Qdrant::from_url("http://localhost:6334").build()?; + +client + .scroll( + ScrollPointsBuilder::new("{collection_name}") + .filter(Filter::must([Condition::has_vector("image")])), + ) + .await?; +``` + +```java +import java.util.List; + +import static io.qdrant.client.ConditionFactory.hasVector; +import static io.qdrant.client.PointIdFactory.id; + +import io.qdrant.client.grpc.Points.Filter; +import io.qdrant.client.grpc.Points.ScrollPoints; + +client + .scrollAsync( + ScrollPoints.newBuilder() + .setCollectionName("{collection_name}") + .setFilter( + Filter.newBuilder() + .addMust(hasVector("image")) + .build()) + .build()) + .get(); +``` + +```csharp +using Qdrant.Client; +using static Qdrant.Client.Grpc.Conditions; + +var client = new QdrantClient("localhost", 6334); + +await client.ScrollAsync(collectionName: "{collection_name}", filter: HasVector("image")); +``` + +```go +import ( + "context" + + "github.com/qdrant/go-client/qdrant" +) + +client, err := qdrant.NewClient(&qdrant.Config{ + Host: "localhost", + Port: 6334, +}) + +client.Scroll(context.Background(), &qdrant.ScrollPoints{ + CollectionName: "{collection_name}", + Filter: &qdrant.Filter{ + Must: []*qdrant.Condition{ + qdrant.NewHasVector( + "image", + ), + }, + }, +}) +``` From d548e2e8544904419d709ecd9602202c7bf47b8f Mon Sep 17 00:00:00 2001 From: Arnaud Gourlay Date: Wed, 15 Jan 2025 15:52:10 +0100 Subject: [PATCH 2/5] introduce example --- .../documentation/concepts/filtering.md | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/qdrant-landing/content/documentation/concepts/filtering.md b/qdrant-landing/content/documentation/concepts/filtering.md index f12e6f529..ec469d49b 100644 --- a/qdrant-landing/content/documentation/concepts/filtering.md +++ b/qdrant-landing/content/documentation/concepts/filtering.md @@ -2985,7 +2985,27 @@ Filtered points would be: This condition enables filtering by the presence of a given named vector on a point. -For example, to search for points with the `image` vector: +For example, if we have two named vector in our collection. + +```http +PUT /collections/{collection_name} +{ + "vectors": { + "image": { + "size": 4, + "distance": "Dot" + }, + "text": { + "size": 8, + "distance": "Cosine" + } + } +} +``` + +Some points in the collection might have both `image` and `text` vectors, some might have only one of them. + +This is how you can search for points which have the `image` vector defined: ```http POST /collections/{collection_name}/points/scroll From d772ae5f187414eee9a5ad4f6f4c13dfbca1c16d Mon Sep 17 00:00:00 2001 From: Arnaud Gourlay Date: Wed, 15 Jan 2025 15:58:24 +0100 Subject: [PATCH 3/5] add Python imports --- qdrant-landing/content/documentation/concepts/filtering.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qdrant-landing/content/documentation/concepts/filtering.md b/qdrant-landing/content/documentation/concepts/filtering.md index ec469d49b..8fc86d866 100644 --- a/qdrant-landing/content/documentation/concepts/filtering.md +++ b/qdrant-landing/content/documentation/concepts/filtering.md @@ -3020,6 +3020,10 @@ POST /collections/{collection_name}/points/scroll ``` ```python +from qdrant_client import QdrantClient, models + +client = QdrantClient(url="http://localhost:6333") + client.scroll( collection_name="{collection_name}", scroll_filter=models.Filter( From 63e111549abfa997e2a31570ed6e39b6a8782169 Mon Sep 17 00:00:00 2001 From: Arnaud Gourlay Date: Wed, 15 Jan 2025 17:00:46 +0100 Subject: [PATCH 4/5] more info about naming & sparse --- .../content/documentation/concepts/filtering.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/qdrant-landing/content/documentation/concepts/filtering.md b/qdrant-landing/content/documentation/concepts/filtering.md index 8fc86d866..3d6a95818 100644 --- a/qdrant-landing/content/documentation/concepts/filtering.md +++ b/qdrant-landing/content/documentation/concepts/filtering.md @@ -2999,13 +2999,19 @@ PUT /collections/{collection_name} "size": 8, "distance": "Cosine" } - } + }, + "sparse_vectors": { + "sparse-image": {}, + "sparse-text": {}, + }, } ``` -Some points in the collection might have both `image` and `text` vectors, some might have only one of them. +Some points in the collection might have all vectors, some might have only a subset of them. + + -This is how you can search for points which have the `image` vector defined: +This is how you can search for points which have the dense `image` vector defined: ```http POST /collections/{collection_name}/points/scroll From ef31b24763869978fb560014b66fedef4efb2bf7 Mon Sep 17 00:00:00 2001 From: Arnaud Gourlay Date: Wed, 15 Jan 2025 17:10:09 +0100 Subject: [PATCH 5/5] fix alignment --- qdrant-landing/content/documentation/concepts/filtering.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/qdrant-landing/content/documentation/concepts/filtering.md b/qdrant-landing/content/documentation/concepts/filtering.md index 3d6a95818..3c73b0489 100644 --- a/qdrant-landing/content/documentation/concepts/filtering.md +++ b/qdrant-landing/content/documentation/concepts/filtering.md @@ -3001,8 +3001,8 @@ PUT /collections/{collection_name} } }, "sparse_vectors": { - "sparse-image": {}, - "sparse-text": {}, + "sparse-image": {}, + "sparse-text": {}, }, } ``` @@ -3021,7 +3021,6 @@ POST /collections/{collection_name}/points/scroll { "has_vector": "image" } ] } - ... } ```