php连接qdrant进行向量数据插入和相似查询代码

代码语言:php

所属分类:其他

代码描述:php连接qdrant进行向量数据插入和相似查询代码

代码标签: php 连接 qdrant 进行 向量 数据 插入 相似 查询 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<?php
// 创建集合
function createCollection() {
    $url = 'http://localhost:6333/collections/test';
    $data = array(
        "vectors" => array(
            "size" => 4,
            "distance" => "Dot"
        )
    );

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
}

// 确认集合被创建
function checkCollection() {
    $url = 'http://localhost:6333/collections/test';

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
}

// 添加数据点到集合
function addPoints() {
    $url = 'http://localhost:6333/collections/test/points?wait=true';
    $data = array(
      "points" => array(
        array("id" => 6, "vector" => [0.05, 0.11, 0.76, 0.74], "payload" => array("city" => "Berlin")),
 array("id" => 2, "vector" => [0.05, 0.61, 0.16, 0.74], "payload" => array("city" => "Beiing")),
 array("id" => 3, "vector" => [0.05, 0.61, 0.71, 0.74], "payload" => array("city" => "Shanghai")),
 array("id" => 4, "vector" => [0.15, 0.61, 0.76, 0.74], "payload" => array("city" => &.........完整代码请登录后点击上方下载按钮下载查看

网友评论0