Skip to content

Commit 0f6b68b

Browse files
committed
Update README
1 parent f0faaba commit 0f6b68b

File tree

1 file changed

+106
-86
lines changed

1 file changed

+106
-86
lines changed

README.md

Lines changed: 106 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -31,133 +31,153 @@ Java client library with handy utility methods and overloads for interfacing wit
3131
To install the library, add the following lines to your build config file.
3232

3333
#### Maven
34+
3435
```xml
3536
<dependency>
3637
<groupId>io.qdrant</groupId>
3738
<artifactId>client</artifactId>
38-
<version>1.0</version>
39+
<version>1.7-SNAPSHOT</version>
3940
</dependency>
4041
```
4142

4243
#### Scala SBT
44+
4345
```sbt
44-
libraryDependencies += "io.qdrant" % "client" % "1.0"
46+
libraryDependencies += "io.qdrant" % "client" % "1.7-SNAPSHOT"
4547
```
4648

4749
#### Gradle
50+
4851
```gradle
49-
implementation 'io.qdrant:client:1.0'
52+
implementation 'io.qdrant:client:1.7-SNAPSHOT'
5053
```
5154

5255
## 📖 Documentation
56+
5357
- [`QdrantClient` Reference](https://qdrant.github.io/java-client/io/qdrant/client/QdrantClient.html#constructor-detail)
54-
- [Utility Methods Reference](https://qdrant.github.io/java-client/io/qdrant/client/utils/package-summary.html)
5558

56-
## 🔌 Connecting to Qdrant
59+
## 🔌 Getting started
5760

58-
> [!NOTE]
59-
> The library uses Qdrant's GRPC interface. The default port being `6334`.
60-
>
61-
> Uses `TLS` if the URL protocol is `https`, plaintext otherwise.
61+
### Creating a client
6262

63-
#### Connecting to a local Qdrant instance
64-
```java
65-
import io.qdrant.client.QdrantClient;
63+
A client can be instantiated with
6664

67-
QdrantClient client = new QdrantClient("http://localhost:6334");
65+
```java
66+
QdrantClient client =
67+
new QdrantClient(QdrantGrpcClient.newBuilder("localhost").build());
6868
```
69+
which creates a client that will connect to Qdrant on https://localhost:6334.
6970

70-
#### Connecting to Qdrant cloud
71-
```java
72-
import io.qdrant.client.QdrantClient;
71+
Internally, the high level client uses a low level gRPC client to interact with
72+
Qdrant. Additional constructor overloads provide more control over how the gRPC
73+
client is configured. The following example configures a client to use TLS,
74+
validating the certificate using the root CA to verify the server's identity
75+
instead of the system's default, and also configures API key authentication:
7376

74-
QdrantClient client = new QdrantClient("https://xyz-eg.eu-central.aws.cloud.qdrant.io:6334", "<your-api-key>");
77+
```java
78+
ManagedChannel channel = Grpc.newChannelBuilder(
79+
"localhost:6334",
80+
TlsChannelCredentials.newBuilder()
81+
.trustManager(new File("ssl/ca.crt"))
82+
.build())
83+
.build();
84+
85+
QdrantClient client = new QdrantClient(
86+
QdrantGrpcClient.newBuilder(channel)
87+
.withApiKey("<apikey>")
88+
.build());
7589
```
7690

77-
## 🧪 Example Usage
78-
<details>
79-
<summary>Click to expand example</summary>
80-
91+
The client implements [`AutoCloseable`](https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html),
92+
though a client will typically be created once and used for the lifetime of the
93+
application. When a client is constructed by passing a `ManagedChannel`, the
94+
client does not shut down the channel on close by default. The client can be
95+
configured to shut down the channel on close with
8196

82-
#### You can connect to Qdrant by instantiating a [QdrantClient](https://qdrant.github.io/java-client/io/qdrant/client/QdrantClient.html) instance.
8397
```java
84-
import io.qdrant.client.QdrantClient;
98+
ManagedChannel channel = Grpc.newChannelBuilder(
99+
"localhost:6334",
100+
TlsChannelCredentials.create())
101+
.build();
102+
103+
QdrantClient client = new QdrantClient(
104+
QdrantGrpcClient.newBuilder(channel, true)
105+
.withApiKey("<apikey>")
106+
.build());
107+
```
85108

86-
QdrantClient client = new QdrantClient("http://localhost:6334");
109+
All client methods return `ListenableFuture<T>`.
87110

88-
System.out.println(client.listCollections());
89-
```
90-
*Output*:
91-
```
92-
collections {
93-
name: "Documents"
94-
}
95-
collections {
96-
name: "some_collection"
97-
}
98-
time: 7.04541E-4
99-
```
111+
### Working with collections
100112

101-
#### We can now perform operations on the DB. Like creating a collection, adding a point.
102-
The library offers handy utility methods for constructing GRPC structures.
113+
Once a client has been created, create a new collection
103114

104115
```java
105-
import java.util.Arrays;
106-
import java.util.HashMap;
107-
import java.util.List;
108-
import java.util.Map;
109-
110-
import io.qdrant.client.utils.*;
116+
client.createCollectionAsync("my_collection",
117+
VectorParams.newBuilder()
118+
.setDistance(Distance.Cosine)
119+
.setSize(4)
120+
.build())
121+
.get();
122+
```
111123

112-
String collectionName = "Documents";
124+
Insert vectors into a collection
113125

114-
client.recreateCollection(collectionName, 6, Distance.Cosine);
126+
```java
127+
// import static convenience methods
128+
import static io.qdrant.client.PointIdFactory.id;
129+
import static io.qdrant.client.ValueFactory.value;
130+
import static io.qdrant.client.VectorsFactory.vector;
131+
132+
Random random = new Random();
133+
List<PointStruct> points = IntStream.range(1, 101)
134+
.mapToObj(i -> PointStruct.newBuilder()
135+
.setId(id(i))
136+
.setVectors(vector(IntStream.range(1, 101)
137+
.mapToObj(v -> random.nextFloat())
138+
.collect(Collectors.toList())))
139+
.putAllPayload(ImmutableMap.of(
140+
"color", value("red"),
141+
"rand_number", value(i % 10))
142+
)
143+
.build()
144+
)
145+
.collect(Collectors.toList());
146+
147+
UpdateResult updateResult = client.upsertAsync("my_collection", points).get();
148+
```
115149

116-
Map<String, Object> map = new HashMap<>();
117-
map.put("name", "John Doe");
118-
map.put("age", 42);
119-
map.put("married", true);
150+
Search for similar vectors
120151

121-
PointStruct point =
122-
PointUtil.point(
123-
0,
124-
VectorUtil.toVector(0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f),
125-
PayloadUtil.toPayload(map));
126-
List<PointStruct> points = Arrays.asList(point);
127-
client.upsertPoints(collectionName, points, null);
152+
```java
153+
List<Float> queryVector = IntStream.range(1, 101)
154+
.mapToObj(v -> random.nextFloat())
155+
.collect(Collectors.toList());
156+
157+
List<ScoredPoint> points = client.searchAsync(SearchPoints.newBuilder()
158+
.setCollectionName("my_collection")
159+
.addAllVector(queryVector)
160+
.setLimit(5)
161+
.build()
162+
).get();
128163
```
129164

130-
#### Performing a search on the vectors with filtering
165+
Search for similar vectors with filtering condition
166+
131167
```java
132-
import io.qdrant.client.grpc.Points.Filter;
133-
import io.qdrant.client.grpc.Points.SearchPoints;
134-
import io.qdrant.client.grpc.Points.SearchResponse;
135-
136-
import io.qdrant.client.utils.*;
137-
138-
Filter filter = FilterUtil.must(FilterUtil.fieldCondition("age", FilterUtil.match(42)));
139-
140-
SearchPoints request = SearchPoints.newBuilder()
141-
.setCollectionName(collectionName)
142-
.addAllVector(Arrays.asList(0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f))
143-
.setFilter(filter)
144-
.setWithPayload(SelectorUtil.withPayload())
145-
.setLimit(10)
146-
.build();
147-
SearchResponse result = client.searchPoints(request);
148-
149-
ScoredPoint result = results.getResult(0);
150-
151-
System.out.println("Similarity: " + result.getScore());
152-
System.out.println("Payload: " + PayloadUtil.toMap(result.getPayload()));
153-
```
154-
*Output*:
168+
// import static convenience methods
169+
import static io.qdrant.client.ConditionFactory.range;
170+
171+
List<ScoredPoint> points = client.searchAsync(SearchPoints.newBuilder()
172+
.setCollectionName("my_collection")
173+
.addAllVector(queryVector)
174+
.setFilter(Filter.newBuilder()
175+
.addMust(range("rand_number", Range.newBuilder().setGte(3).build()))
176+
.build())
177+
.setLimit(5)
178+
.build()
179+
).get();
155180
```
156-
Similarity: 0.9999999
157-
Payload: {name=John Doe, married=true, age=42}
158-
```
159-
160-
</details>
161181

162182
## ⚖️ LICENSE
163183

0 commit comments

Comments
 (0)