mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-01 08:58:31 +02:00
docs: Query API snippets with Java (#1103)
This commit is contained in:
@@ -112,32 +112,30 @@ client
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
import static io.qdrant.client.VectorFactory.vector;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.Filter;
|
||||
import io.qdrant.client.grpc.Points.RecommendPoints;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.RecommendInput;
|
||||
import io.qdrant.client.grpc.Points.RecommendStrategy;
|
||||
import io.qdrant.client.grpc.Points.Filter;
|
||||
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
import static io.qdrant.client.VectorInputFactory.vectorInput;
|
||||
import static io.qdrant.client.QueryFactory.recommend;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.recommendAsync(
|
||||
RecommendPoints.newBuilder()
|
||||
client.queryAsync(QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllPositive(List.of(id(100), id(200)))
|
||||
.addAllPositiveVectors(List.of(vector(100.0f, 231.0f)))
|
||||
.addAllNegative(List.of(id(718)))
|
||||
.addAllPositiveVectors(List.of(vector(0.2f, 0.3f, 0.4f, 0.5f)))
|
||||
.setQuery(recommend(RecommendInput.newBuilder()
|
||||
.addAllPositive(List.of(vectorInput(100), vectorInput(200), vectorInput(100.0f, 231.0f)))
|
||||
.addAllNegative(List.of(vectorInput(718), vectorInput(0.2f, 0.3f, 0.4f, 0.5f)))
|
||||
.setStrategy(RecommendStrategy.AverageVector)
|
||||
.build()))
|
||||
.setFilter(Filter.newBuilder().addMust(matchKeyword("city", "London")))
|
||||
.setLimit(3)
|
||||
.build())
|
||||
.get();
|
||||
.build()).get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
@@ -275,20 +273,21 @@ client
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.RecommendInput;
|
||||
|
||||
import io.qdrant.client.grpc.Points.RecommendPoints;
|
||||
import static io.qdrant.client.VectorInputFactory.vectorInput;
|
||||
import static io.qdrant.client.QueryFactory.recommend;
|
||||
|
||||
client
|
||||
.recommendAsync(
|
||||
RecommendPoints.newBuilder()
|
||||
client.queryAsync(QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllPositive(List.of(id(100), id(231)))
|
||||
.addAllNegative(List.of(id(718)))
|
||||
.setQuery(recommend(RecommendInput.newBuilder()
|
||||
.addAllPositive(List.of(vectorInput(100), vectorInput(231)))
|
||||
.addAllNegative(List.of(vectorInput(718)))
|
||||
.build()))
|
||||
.setUsing("image")
|
||||
.setLimit(10)
|
||||
.build())
|
||||
.get();
|
||||
.build()).get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
@@ -383,17 +382,19 @@ client
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
|
||||
import io.qdrant.client.grpc.Points.LookupLocation;
|
||||
import io.qdrant.client.grpc.Points.RecommendPoints;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.RecommendInput;
|
||||
|
||||
client
|
||||
.recommendAsync(
|
||||
RecommendPoints.newBuilder()
|
||||
import static io.qdrant.client.VectorInputFactory.vectorInput;
|
||||
import static io.qdrant.client.QueryFactory.recommend;
|
||||
|
||||
client.queryAsync(QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllPositive(List.of(id(100), id(231)))
|
||||
.addAllNegative(List.of(id(718)))
|
||||
.setQuery(recommend(RecommendInput.newBuilder()
|
||||
.addAllPositive(List.of(vectorInput(100), vectorInput(231)))
|
||||
.addAllNegative(List.of(vectorInput(718)))
|
||||
.build()))
|
||||
.setUsing("image")
|
||||
.setLimit(10)
|
||||
.setLookupFrom(
|
||||
@@ -401,8 +402,7 @@ client
|
||||
.setCollectionName("{external_collection_name}")
|
||||
.setVectorName("{external_vector_name}")
|
||||
.build())
|
||||
.build())
|
||||
.get();
|
||||
.build()).get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
@@ -578,35 +578,44 @@ client
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.Filter;
|
||||
import io.qdrant.client.grpc.Points.RecommendPoints;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.RecommendInput;
|
||||
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
import static io.qdrant.client.VectorInputFactory.vectorInput;
|
||||
import static io.qdrant.client.QueryFactory.recommend;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
Filter filter = Filter.newBuilder().addMust(matchKeyword("city", "London")).build();
|
||||
|
||||
List<RecommendPoints> recommendQueries =
|
||||
List.of(
|
||||
RecommendPoints.newBuilder()
|
||||
.addAllPositive(List.of(id(100), id(231)))
|
||||
.addAllNegative(List.of(id(718)))
|
||||
List<QueryPoints> recommendQueries = List.of(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setQuery(recommend(
|
||||
RecommendInput.newBuilder()
|
||||
.addAllPositive(List.of(vectorInput(100), vectorInput(231)))
|
||||
.addAllNegative(List.of(vectorInput(731)))
|
||||
.build()))
|
||||
.setFilter(filter)
|
||||
.setLimit(3)
|
||||
.build(),
|
||||
RecommendPoints.newBuilder()
|
||||
.addAllPositive(List.of(id(200), id(67)))
|
||||
.addAllNegative(List.of(id(300)))
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setQuery(recommend(
|
||||
RecommendInput.newBuilder()
|
||||
.addAllPositive(List.of(vectorInput(200), vectorInput(67)))
|
||||
.addAllNegative(List.of(vectorInput(300)))
|
||||
.build()))
|
||||
.setFilter(filter)
|
||||
.setLimit(3)
|
||||
.build());
|
||||
|
||||
client.recommendBatchAsync("{collection_name}", recommendQueries, null).get();
|
||||
client.queryBatchAsync("{collection_name}", recommendQueries).get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
@@ -799,42 +808,37 @@ client
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
import static io.qdrant.client.VectorFactory.vector;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.ContextExamplePair;
|
||||
import io.qdrant.client.grpc.Points.DiscoverPoints;
|
||||
import io.qdrant.client.grpc.Points.TargetVector;
|
||||
import io.qdrant.client.grpc.Points.VectorExample;
|
||||
import io.qdrant.client.grpc.Points.ContextInput;
|
||||
import io.qdrant.client.grpc.Points.ContextInputPair;
|
||||
import io.qdrant.client.grpc.Points.DiscoverInput;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
import static io.qdrant.client.VectorInputFactory.vectorInput;
|
||||
import static io.qdrant.client.QueryFactory.discover;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.discoverAsync(
|
||||
DiscoverPoints.newBuilder()
|
||||
client.queryAsync(QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setTarget(
|
||||
TargetVector.newBuilder()
|
||||
.setSingle(
|
||||
VectorExample.newBuilder()
|
||||
.setVector(vector(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.build()))
|
||||
.addAllContext(
|
||||
List.of(
|
||||
ContextExamplePair.newBuilder()
|
||||
.setPositive(VectorExample.newBuilder().setId(id(100)))
|
||||
.setNegative(VectorExample.newBuilder().setId(id(718)))
|
||||
.setQuery(discover(DiscoverInput.newBuilder()
|
||||
.setTarget(vectorInput(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setContext(ContextInput.newBuilder()
|
||||
.addAllPairs(List.of(
|
||||
ContextInputPair.newBuilder()
|
||||
.setPositive(vectorInput(100))
|
||||
.setNegative(vectorInput(718))
|
||||
.build(),
|
||||
ContextExamplePair.newBuilder()
|
||||
.setPositive(VectorExample.newBuilder().setId(id(200)))
|
||||
.setNegative(VectorExample.newBuilder().setId(id(300)))
|
||||
ContextInputPair.newBuilder()
|
||||
.setPositive(vectorInput(200))
|
||||
.setNegative(vectorInput(300))
|
||||
.build()))
|
||||
.build())
|
||||
.build()))
|
||||
.setLimit(10)
|
||||
.build())
|
||||
.get();
|
||||
.build()).get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
@@ -984,34 +988,33 @@ client
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.ContextExamplePair;
|
||||
import io.qdrant.client.grpc.Points.DiscoverPoints;
|
||||
import io.qdrant.client.grpc.Points.VectorExample;
|
||||
import io.qdrant.client.grpc.Points.ContextInput;
|
||||
import io.qdrant.client.grpc.Points.ContextInputPair;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
import static io.qdrant.client.VectorInputFactory.vectorInput;
|
||||
import static io.qdrant.client.QueryFactory.context;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.discoverAsync(
|
||||
DiscoverPoints.newBuilder()
|
||||
client.queryAsync(QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllContext(
|
||||
List.of(
|
||||
ContextExamplePair.newBuilder()
|
||||
.setPositive(VectorExample.newBuilder().setId(id(100)))
|
||||
.setNegative(VectorExample.newBuilder().setId(id(718)))
|
||||
.setQuery(context(ContextInput.newBuilder()
|
||||
.addAllPairs(List.of(
|
||||
ContextInputPair.newBuilder()
|
||||
.setPositive(vectorInput(100))
|
||||
.setNegative(vectorInput(718))
|
||||
.build(),
|
||||
ContextExamplePair.newBuilder()
|
||||
.setPositive(VectorExample.newBuilder().setId(id(200)))
|
||||
.setNegative(VectorExample.newBuilder().setId(id(300)))
|
||||
ContextInputPair.newBuilder()
|
||||
.setPositive(vectorInput(200))
|
||||
.setNegative(vectorInput(300))
|
||||
.build()))
|
||||
.build()))
|
||||
.setLimit(10)
|
||||
.build())
|
||||
.get();
|
||||
.build()).get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
|
||||
@@ -296,26 +296,24 @@ client
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.Filter;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.SearchParams;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setFilter(Filter.newBuilder().addMust(matchKeyword("city", "London")).build())
|
||||
.setParams(SearchParams.newBuilder().setExact(false).setHnswEf(128).build())
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setLimit(3)
|
||||
.build())
|
||||
.get();
|
||||
.build()).get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
@@ -425,20 +423,19 @@ import java.util.List;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setVectorName("image")
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setUsing("image")
|
||||
.setLimit(3)
|
||||
.build())
|
||||
.get();
|
||||
.build()).get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
@@ -539,19 +536,18 @@ import java.util.List;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
import io.qdrant.client.grpc.Points.SparseIndices;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setVectorName("text")
|
||||
.addAllVector(List.of(2.0f, 1.0f))
|
||||
.setSparseIndices(SparseIndices.newBuilder().addAllData(List.of(1, 7)).build())
|
||||
.setUsing("text")
|
||||
.setQuery(nearest(List.of(2.0f, 1.0f), List.of(1, 7)))
|
||||
.setLimit(3)
|
||||
.build())
|
||||
.get();
|
||||
@@ -630,23 +626,22 @@ client
|
||||
```
|
||||
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.WithPayloadSelectorFactory.enable;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.WithVectorsSelectorFactory;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
import static io.qdrant.client.WithPayloadSelectorFactory.enable;
|
||||
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setWithPayload(enable(true))
|
||||
.setWithVectors(WithVectorsSelectorFactory.enable(true))
|
||||
.setLimit(3)
|
||||
@@ -726,20 +721,20 @@ client
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.WithPayloadSelectorFactory.include;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
import static io.qdrant.client.WithPayloadSelectorFactory.include;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setWithPayload(include(List.of("city", "village", "town")))
|
||||
.setLimit(3)
|
||||
.build())
|
||||
@@ -828,20 +823,20 @@ client
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.WithPayloadSelectorFactory.exclude;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
import static io.qdrant.client.WithPayloadSelectorFactory.exclude;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setWithPayload(exclude(List.of("city")))
|
||||
.setLimit(3)
|
||||
.build())
|
||||
@@ -1005,30 +1000,32 @@ client
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.Filter;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
Filter filter = Filter.newBuilder().addMust(matchKeyword("city", "London")).build();
|
||||
List<SearchPoints> searches =
|
||||
List.of(
|
||||
SearchPoints.newBuilder()
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
|
||||
List<QueryPoints> searches = List.of(
|
||||
QueryPoints.newBuilder()
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setFilter(filter)
|
||||
.setLimit(3)
|
||||
.build(),
|
||||
SearchPoints.newBuilder()
|
||||
.addAllVector(List.of(0.5f, 0.3f, 0.2f, 0.3f))
|
||||
QueryPoints.newBuilder()
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setFilter(filter)
|
||||
.setLimit(3)
|
||||
.build());
|
||||
client.searchBatchAsync("{collection_name}", searches, null).get();
|
||||
|
||||
client.queryBatchAsync("{collection_name}", searches).get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
@@ -1148,21 +1145,21 @@ client
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.WithPayloadSelectorFactory.enable;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.WithVectorsSelectorFactory;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
import static io.qdrant.client.WithPayloadSelectorFactory.enable;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setWithPayload(enable(true))
|
||||
.setWithVectors(WithVectorsSelectorFactory.enable(true))
|
||||
.setLimit(10)
|
||||
@@ -1318,11 +1315,10 @@ import java.util.List;
|
||||
|
||||
import io.qdrant.client.grpc.Points.SearchPointGroups;
|
||||
|
||||
client
|
||||
.searchGroupsAsync(
|
||||
SearchPointGroups.newBuilder()
|
||||
client.queryGroupsAsync(
|
||||
QueryPointGroups.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllVector(List.of(1.1f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setGroupBy("document_id")
|
||||
.setLimit(4)
|
||||
.setGroupSize(2)
|
||||
@@ -1496,17 +1492,17 @@ client
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.WithPayloadSelectorFactory.include;
|
||||
import static io.qdrant.client.WithVectorsSelectorFactory.enable;
|
||||
|
||||
import io.qdrant.client.grpc.Points.SearchPointGroups;
|
||||
import io.qdrant.client.grpc.Points.QueryPointGroups;
|
||||
import io.qdrant.client.grpc.Points.WithLookup;
|
||||
|
||||
client
|
||||
.searchGroupsAsync(
|
||||
SearchPointGroups.newBuilder()
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
import static io.qdrant.client.WithVectorsSelectorFactory.enable;
|
||||
import static io.qdrant.client.WithPayloadSelectorFactory.include;
|
||||
|
||||
client.queryGroupsAsync(
|
||||
QueryPointGroups.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllVector(List.of(1.0f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setGroupBy("document_id")
|
||||
.setLimit(2)
|
||||
.setGroupSize(2)
|
||||
|
||||
@@ -377,20 +377,18 @@ import java.util.List;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
import io.qdrant.client.grpc.Points.SparseIndices;
|
||||
import io.qdrant.client.grpc.Points.Vectors;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setVectorName("text")
|
||||
.addAllVector(List.of(0.1f, 0.2f, 0.3f, 0.4f))
|
||||
.setSparseIndices(SparseIndices.newBuilder().addAllData(List.of(1, 3, 5, 7)).build())
|
||||
.setUsing("text")
|
||||
.setQuery(nearest(List.of(0.1f, 0.2f, 0.3f, 0.4f), List.of(1, 3, 5, 7)))
|
||||
.setLimit(3)
|
||||
.build())
|
||||
.get();
|
||||
|
||||
@@ -1130,28 +1130,26 @@ client
|
||||
```
|
||||
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.Filter;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.ReadConsistency;
|
||||
import io.qdrant.client.grpc.Points.ReadConsistencyType;
|
||||
import io.qdrant.client.grpc.Points.SearchParams;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setFilter(Filter.newBuilder().addMust(matchKeyword("city", "London")).build())
|
||||
.setQuery(nearest(.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setParams(SearchParams.newBuilder().setHnswEf(128).setExact(true).build())
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setLimit(3)
|
||||
.setReadConsistency(
|
||||
ReadConsistency.newBuilder().setType(ReadConsistencyType.Majority).build())
|
||||
|
||||
@@ -254,18 +254,20 @@ import java.util.List;
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.Filter;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setFilter(
|
||||
Filter.newBuilder().addMust(matchKeyword("group_id", "user_1")).build())
|
||||
.addAllVector(List.of(0.1f, 0.1f, 0.9f))
|
||||
.setQuery(nearest(0.1f, 0.1f, 0.9f))
|
||||
.setLimit(10)
|
||||
.build())
|
||||
.get();
|
||||
|
||||
@@ -219,21 +219,21 @@ client
|
||||
```
|
||||
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.QuantizationSearchParams;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.SearchParams;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setParams(
|
||||
SearchParams.newBuilder()
|
||||
.setQuantization(
|
||||
@@ -580,21 +580,20 @@ client
|
||||
```
|
||||
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.SearchParams;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setParams(SearchParams.newBuilder().setHnswEf(128).setExact(false).build())
|
||||
.setLimit(3)
|
||||
.build())
|
||||
|
||||
@@ -22,14 +22,12 @@ This can be particularly beneficial in large-scale applications where minimizing
|
||||
On the other hand, quantization introduces an approximation error, which can lead to a slight decrease in search quality.
|
||||
The level of this tradeoff depends on the quantization method and its parameters, as well as the characteristics of the data.
|
||||
|
||||
|
||||
## Scalar Quantization
|
||||
|
||||
*Available as of v1.1.0*
|
||||
|
||||
Scalar quantization, in the context of vector search engines, is a compression technique that compresses vectors by reducing the number of bits used to represent each vector component.
|
||||
|
||||
|
||||
For instance, Qdrant uses 32-bit floating numbers to represent the original vector components. Scalar quantization allows you to reduce the number of bits used to 8.
|
||||
In other words, Qdrant performs `float32 -> uint8` conversion for each vector component.
|
||||
Effectively, this means that the amount of memory required to store a vector is reduced by a factor of 4.
|
||||
@@ -45,7 +43,6 @@ In our experiments, we found that the error introduced by scalar quantization is
|
||||
However, this value depends on the data and the quantization parameters.
|
||||
Please refer to the [Quantization Tips](#quantization-tips) section for more information on how to optimize the quantization parameters for your use case.
|
||||
|
||||
|
||||
## Binary Quantization
|
||||
|
||||
*Available as of v1.5.0*
|
||||
@@ -76,7 +73,6 @@ The additional benefit of this method is that you can efficiently emulate Hammin
|
||||
|
||||
Specifically, if original vectors contain `{-1, 1}` as possible values, then the dot product of two vectors is equal to the Hamming distance by simply replacing `-1` with `0` and `1` with `1`.
|
||||
|
||||
|
||||
<!-- hidden section -->
|
||||
|
||||
<details>
|
||||
@@ -101,7 +97,6 @@ Specifically, if original vectors contain `{-1, 1}` as possible values, then the
|
||||
As you can see, both functions are equal up to a constant factor, which makes similarity search equivalent.
|
||||
Binary quantization makes it efficient to compare vectors using this representation.
|
||||
|
||||
|
||||
## Product Quantization
|
||||
|
||||
*Available as of v1.2.0*
|
||||
@@ -130,9 +125,9 @@ Here is a brief table of the pros and cons of each quantization method:
|
||||
|
||||
`*` - for compatible models
|
||||
|
||||
* **Binary Quantization** is the fastest method and the most memory-efficient, but it requires a centered distribution of vector components. It is recommended to use with tested models only.
|
||||
* **Scalar Quantization** is the most universal method, as it provides a good balance between accuracy, speed, and compression. It is recommended as default quantization if binary quantization is not applicable.
|
||||
* **Product Quantization** may provide a better compression ratio, but it has a significant loss of accuracy and is slower than scalar quantization. It is recommended if the memory footprint is the top priority and the search speed is not critical.
|
||||
- **Binary Quantization** is the fastest method and the most memory-efficient, but it requires a centered distribution of vector components. It is recommended to use with tested models only.
|
||||
- **Scalar Quantization** is the most universal method, as it provides a good balance between accuracy, speed, and compression. It is recommended as default quantization if binary quantization is not applicable.
|
||||
- **Product Quantization** may provide a better compression ratio, but it has a significant loss of accuracy and is slower than scalar quantization. It is recommended if the memory footprint is the top priority and the search speed is not critical.
|
||||
|
||||
## Setting up Quantization in Qdrant
|
||||
|
||||
@@ -646,22 +641,21 @@ client
|
||||
```
|
||||
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.QuantizationSearchParams;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.SearchParams;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setParams(
|
||||
SearchParams.newBuilder()
|
||||
.setQuantization(
|
||||
@@ -783,22 +777,21 @@ client
|
||||
```
|
||||
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.QuantizationSearchParams;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.SearchParams;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setParams(
|
||||
SearchParams.newBuilder()
|
||||
.setQuantization(
|
||||
@@ -833,7 +826,6 @@ By adjusting the quantile, you find an optimal value that will provide the best
|
||||
|
||||
- **Enable rescore**: Having the original vectors available, Qdrant can re-evaluate top-k search results using the original vectors. On large collections, this can improve the search quality, with just minor performance impact.
|
||||
|
||||
|
||||
#### Memory and speed tuning
|
||||
|
||||
In this section, we will discuss how to tune the memory and speed of the search process with quantization.
|
||||
@@ -1042,22 +1034,21 @@ client
|
||||
```
|
||||
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.QuantizationSearchParams;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.SearchParams;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setParams(
|
||||
SearchParams.newBuilder()
|
||||
.setQuantization(
|
||||
|
||||
@@ -332,20 +332,18 @@ dbg!(search_result);
|
||||
import java.util.List;
|
||||
|
||||
import io.qdrant.client.grpc.Points.ScoredPoint;
|
||||
import io.qdrant.client.grpc.Points.SearchPoints;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
import static io.qdrant.client.WithPayloadSelectorFactory.enable;
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
|
||||
List<ScoredPoint> searchResult =
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(QueryPoints.newBuilder()
|
||||
.setCollectionName("test_collection")
|
||||
.setLimit(3)
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setWithPayload(enable(true))
|
||||
.build())
|
||||
.get();
|
||||
.build()).get();
|
||||
|
||||
System.out.println(searchResult);
|
||||
```
|
||||
@@ -444,16 +442,13 @@ dbg!(search_result);
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
|
||||
List<ScoredPoint> searchResult =
|
||||
client
|
||||
.searchAsync(
|
||||
SearchPoints.newBuilder()
|
||||
client.queryAsync(QueryPoints.newBuilder()
|
||||
.setCollectionName("test_collection")
|
||||
.setLimit(3)
|
||||
.setFilter(Filter.newBuilder().addMust(matchKeyword("city", "London")))
|
||||
.addAllVector(List.of(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setWithPayload(enable(true))
|
||||
.build())
|
||||
.get();
|
||||
.build()).get();
|
||||
|
||||
System.out.println(searchResult);
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user