Appearance
Java:Maven 与连接
Maven 依赖
xml
<dependency>
<groupId>io.qdrant</groupId>
<artifactId>client</artifactId>
<version>1.17.0</version>
</dependency>版本号请与 Maven Central 对齐;若冲突,按官方说明引入 gRPC / Protobuf 传递依赖。
Gradle
gradle
implementation 'io.qdrant:client:1.17.0'创建客户端(本地 gRPC)
Java 客户端走 gRPC,默认连接本机 6334(与 Docker 映射一致)。
java
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
QdrantClient client =
new QdrantClient(QdrantGrpcClient.newBuilder("localhost").build());newBuilder("host") 可换为远程主机名;云环境注意 TLS 与 API Key(见官方 README)。
API Key + TLS 示例思路
使用 Grpc.newChannelBuilder 构建 ManagedChannel,再 QdrantGrpcClient.newBuilder(channel).withApiKey("...").build()。生产务必校验证书与主机名。
关闭客户端
QdrantClient 实现 AutoCloseable,长期运行的服务可在 JVM 退出时关闭;短脚本可用 try-with-resources。
java
try (QdrantClient client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost").build())) {
// 使用 client
}与 Python 同时调试
同一 Qdrant:Python 写 6333 REST,Java 读 6334 gRPC,数据相同。注意 防火墙 放行两端口。
下一节:集合与点操作。