日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

快速開始

更新時(shí)間:

本文將介紹如何快速上手使用向量檢索服務(wù)DashVector。

前提條件

說明
  1. 需要使用您的api-key替換示例中的YOUR_API_KEY、您的Cluster Endpoint替換示例中的YOUR_CLUSTER_ENDPOINT,代碼才能正常運(yùn)行。

  2. Cluster Endpoint,可在控制臺“Cluster詳情”中查看。

Step1. 創(chuàng)建Client

使用HTTP API時(shí)可跳過本步驟。

import dashvector

client = dashvector.Client(
    api_key='YOUR_API_KEY',
    endpoint='YOUR_CLUSTER_ENDPOINT'
)
assert client
import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.common.DashVectorException;


DashVectorClient client = new DashVectorClient("YOUR_API_KEY", "YOUR_CLUSTER_ENDPOINT");

Step2. 創(chuàng)建Collection

創(chuàng)建一個(gè)名稱為quickstart,向量維度為4的collection。

client.create(name='quickstart', dimension=4)

collection = client.get('quickstart')
assert collection
import com.aliyun.dashvector.models.responses.Response;
import com.aliyun.dashvector.DashVectorCollection;


Response<Void> response = client.create("quickstart", 4);
System.out.println(response);
DashVectorCollection collection = client.get("quickstart");

assert collection.isSuccess();
curl -XPOST \
  -H 'dashvector-auth-token: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "quickstart", 
    "dimension": 4
  }' https://YOUR_CLUSTER_ENDPOINT/v1/collections
說明
  1. 在未指定距離度量參數(shù)時(shí),將使用默認(rèn)的Cosine距離度量方式。

  2. 在未指定向量數(shù)據(jù)類型時(shí),將使用默認(rèn)的Float數(shù)據(jù)類型。

Step3. 插入Doc

from dashvector import Doc

# 通過dashvector.Doc對象,插入單條數(shù)據(jù)
collection.insert(Doc(id='1', vector=[0.1, 0.2, 0.3, 0.4]))

# 通過dashvector.Doc對象,批量插入2條數(shù)據(jù)
collection.insert(
    [
        Doc(id='2', vector=[0.2, 0.3, 0.4, 0.5], fields={'age': 20, 'name': 'zhangsan'}),
        Doc(id='3', vector=[0.3, 0.4, 0.5, 0.6], fields={'anykey': 'anyvalue'})    
    ]
)
import com.aliyun.dashvector.models.Vector;
import com.aliyun.dashvector.models.Doc;
import com.aliyun.dashvector.models.requests.InsertDocRequest;
import com.aliyun.dashvector.models.responses.Response;

import java.util.Arrays;
import java.util.HashMap;


Doc doc1 = Doc.builder()
    .id("1")
    .vector(
        Vector.builder()
            .value(Arrays.asList(0.1f, 0.2f, 0.3f, 0.4f))
            .build()
    ).build();

Doc doc2 = Doc.builder()
    .id("2")
    .vector(
        Vector.builder()
            .value(Arrays.asList(0.2f, 0.3f, 0.4f, 0.5f))
            .build()
    ).fields(new HashMap<String, Object>(){{
        put("age", 20);
        put("name", "zhangsan");
    }}).build();

Doc doc3 = Doc.builder()
    .id("3")
    .field("anykey", "anyvalue")
    .vector(
        Vector.builder()
            .value(Arrays.asList(0.3f, 0.4f, 0.5f, 0.6f))
            .build()
    ).build();

InsertDocRequest request = InsertDocRequest.builder()
    .docs(Arrays.asList(doc1, doc2, doc3))
    .build();

Response<Void> response = collection.insert(request);
# 插入3條數(shù)據(jù)

curl -XPOST \
  -H 'dashvector-auth-token: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "docs": [
      {"id": "1", "vector": [0.1, 0.2, 0.3, 0.4]},
      {"id": "2", "vector": [0.2, 0.3, 0.4, 0.5], "fields": {"age": 20, "name": "zhangsan"}},
      {"id": "3", "vector": [0.3, 0.4, 0.5, 0.6], "fields": {"anykey": "anyvalue"}}
    ]
  }' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/docs

Step4. 相似性檢索

rets = collection.query([0.1, 0.2, 0.3, 0.4], topk=2)

print(rets)
import com.aliyun.dashvector.models.Vector;
import com.aliyun.dashvector.models.Doc;
import com.aliyun.dashvector.models.requests.QueryDocRequest;
import com.aliyun.dashvector.models.responses.Response;

import java.util.Arrays;
import java.util.List;


Vector vector = Vector.builder().value(Arrays.asList(0.1f, 0.2f, 0.3f, 0.4f)).build();
      	
QueryDocRequest request = QueryDocRequest.builder()
    .vector(vector)
    .topk(2)
    .build();

Response<List<Doc>> response = collection.query(request);
curl -XPOST \
  -H 'dashvector-auth-token: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "vector": [0.1, 0.2, 0.3, 0.4],
    "topk": 2
  }' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/query

Step5. 刪除Doc

# 刪除1條數(shù)據(jù)
collection.delete(ids=['1'])
import com.aliyun.dashvector.models.Doc;
import com.aliyun.dashvector.models.requests.DeleteDocRequest;
import com.aliyun.dashvector.models.responses.Response;


DeleteDocRequest request = DeleteDocRequest.builder()
    .id("1")
    .build();
      
Response<List<Doc>> response = collection.delete(request);
curl -XDELETE \
  -H 'dashvector-auth-token: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"ids": ["1"]}' \
  https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/docs

Step6. 查看Collection統(tǒng)計(jì)信息

stats = collection.stats()

print(stats)
import com.aliyun.dashvector.models.CollectionStats;
import com.aliyun.dashvector.models.responses.Response;


Response<CollectionStats> response = collection.stats();
curl -H 'dashvector-auth-token: YOUR_API_KEY' \
  https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/stats

Step7. 刪除Collection

client.delete('quickstart')
import com.aliyun.dashvector.models.responses.Response;


Response<Void> response = client.delete("quickstart");
curl -XDELETE -H 'dashvector-auth-token: YOUR_API_KEY' \
  https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart