Java连接Qdrant数据库

打印 上一主题 下一主题

主题 1732|帖子 1732|积分 5196

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
1.下载Qdrant
在虚拟机上利用Docker下载
链接:docker.io/langgenius/qdrant:v1.7.3 - 镜像下载 | docker.io (aityp.com)
  1. docker pull swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/langgenius/qdrant:v1.7.3
  2. docker tag  swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/langgenius/qdrant:v1.7.3  docker.io/langgenius/qdrant:v1.7.3
复制代码
2.运行Qdrant
  1. docker run -p 6333:6333 -p 6334:6334  swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/langgenius/qdrant:v1.7.3
复制代码
3.添加Maven依靠
  1. <dependency>
  2.     <groupId>io.qdrant</groupId>
  3.     <artifactId>client</artifactId>
  4.     <version>1.10.0</version>
  5. </dependency>
复制代码
4.Java操作Qdrant
官方文档:Local Quickstart - Qdrant
  1.     // 创建客户端链接
  2.     QdrantClient client = new QdrantClient(
  3.             QdrantGrpcClient.newBuilder("192.168.40.130", 6334, false).build());
  4.     // 创建collection
  5.     client.createCollectionAsync("my_collection",
  6.                     Collections.VectorParams.newBuilder()
  7.                             .setDistance(Collections.Distance.Cosine)
  8.                             .setSize(4)
  9.                             .build()).get();
  10.     // 插入向量
  11.     HashMap<String, JsonWithInt.Value> map1 = new HashMap<>();
  12.     map1.put("color", value("red"));
  13.     map1.put("rand_number", value(32));
  14.     HashMap<String, JsonWithInt.Value> map2 = new HashMap<>();
  15.     map2.put("color", value("blue"));
  16.     map2.put("rand_number", value(53));
  17.     map2.put("extra_field", value(true));
  18.     List<Points.PointStruct> points = new ArrayList<>();
  19.     points.add(Points.PointStruct.newBuilder()
  20.             .setId(id(1))
  21.             .setVectors(vectors(0.32f, 0.52f, 0.21f, 0.52f))
  22.             .putAllPayload(map1)
  23.             .build());
  24.     points.add(Points.PointStruct.newBuilder()
  25.             .setId(id(2))
  26.             .setVectors(vectors(0.42f, 0.52f, 0.67f, 0.632f))
  27.             .putAllPayload(map2)
  28.             .build());
  29.     Points.UpdateResult updateResult = client.upsertAsync("my_collection", points).get();
  30.     // 搜索相似结果
  31.     List<Points.ScoredPoint> points1 = client.searchAsync(
  32.             Points.SearchPoints.newBuilder()
  33.                     .setCollectionName("my_collection")
  34.                     .addAllVector(Arrays.asList(0.6235f, 0.123f, 0.532f, 0.123f))
  35.                     .setLimit(5)
  36.                     .build()).get();
  37.     System.out.println(points1);
  38.     // 搜索相似结果带过滤条件
  39.     List<Points.ScoredPoint> points2 = client.searchAsync(
  40.             Points.SearchPoints.newBuilder()
  41.                     .setCollectionName("my_collection")
  42.                     .addAllVector(Arrays.asList(0.6235f, 0.123f, 0.532f, 0.123f))
  43.                     .setFilter(Points.Filter.newBuilder()
  44.                             .addMust(range("rand_number", Points.Range.newBuilder().setGte(3).build()))
  45.                             .build())
  46.                     .setLimit(5)
  47.                     .build()).get();
  48.     System.out.println(points2);
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

郭卫东

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表