Quick Start
This tutorial guides you through CRUD tasks in a serverless cluster. You are expecting to learn the basic CRUD operations in Zilliz Cloud clusters.
Before you start
Throughout this guide, we will use Zilliz Cloud's SDKs and RESTful API. Before you begin, ensure that:
You have registered an account with Zilliz Cloud at https://cloud.zilliz.com/signup. For details, see Register with Zilliz Cloud.
You have subscribed to the Starter plan and created a serverless cluster in a project. For details, see Free Trials and Create Cluster.
You have installed the preferred SDKs. Currently, there are four SDKs available, and they are Python, Java, Go, and Node.js. For details, see Install SDKs.
You have downloaded the example dataset. For details, see Example Dataset.
Create a collection
Zilliz Cloud automatically creates a collection when you create a serverless cluster. It has dynamic schema enabled, with id and vector acting as predefined fields for the primary key and the vector field, respectively. The autoId attribute is enabled by default for the primary key.
If you want to create a new collection, follow these steps:
- Python
- NodeJS
- Java
- Bash
from pymilvus import MilvusClient
# Replace uri and API key with your own
client = MilvusClient(
uri=CLUSTER_ENDPOINT, # Cluster endpoint obtained from the console
token=TOKEN # API key or a colon-separated cluster username and password
)
# Create a collection
client.create_collection(
collection_name=COLLECTION_NAME,
dimension=768
)
const fs = require("fs")
const { MilvusClient } = require("@zilliz/milvus2-sdk-node")
const address = "YOUR_CLUSTER_ENDPOINT"
const token = "YOUR_CLUSTER_TOKEN"
const collectionName = "medium_articles_2020"
const data_file = `./medium_articles_2020_dpr.json`
// Include the following in an async function declaration
async function main () {
// Connect to the cluster
const client = new MilvusClient({address, token})
// Create a collection
let res = await client.createCollection({
collection_name: collectionName,
dimension: 768,
});
console.log(res)
// Output
//
// { error_code: 'Success', reason: '', code: 0 }
//
// <Insert the following code snippets here>
}
main()
import java.nio.file.Path;
import java.util.*;
import com.alibaba.fastjson.*;
import io.milvus.client.MilvusServiceClient;
import io.milvus.grpc.DescribeCollectionResponse;
import io.milvus.param.*;
import io.milvus.param.collection.*;
import io.milvus.param.highlevel.collection.*;
import io.milvus.param.highlevel.dml.*;
import io.milvus.param.highlevel.dml.response.*;
import io.milvus.response.DescCollResponseWrapper;
import io.milvus.response.QueryResultsWrapper;
import io.milvus.response.QueryResultsWrapper.RowRecord;
public class QuickStartDemo
{
public static void main( String[] args )
{
String clusterEndpoint = "YOUR_CLUSTER_ENDPOINT";
String token = "YOUR_CLUSTER_TOKEN";
String collectionName = "medium_articles";
String data_file = System.getProperty("user.dir") + "/medium_articles_2020_dpr.json";
// 1. Connect to Zilliz Cloud
ConnectParam connectParam = ConnectParam.newBuilder()
.withUri(clusterEndpoint)
.withToken(token)
.build();
MilvusServiceClient client = new MilvusServiceClient(connectParam);
System.out.println("Connected to Zilliz Cloud!");
// Output:
// Connected to Zilliz Cloud!
// 2. Create collection
CreateSimpleCollectionParam createCollectionParam = CreateSimpleCollectionParam.newBuilder()
.withCollectionName(collectionName)
.withDimension(768)
.build();
R<RpcStatus> createCollection = client.createCollection(createCollectionParam);
if (createCollection.getException() != null) {
System.err.println("Failed to create collection: " + createCollection.getException().getMessage());
return;
}
}
}
# Replace PUBLIC_ENDPOINT and TOKEN with your own
# token="username:password" or token="your-api-key"
curl --location --request POST "${PUBLIC_ENDPOINT}/v1/vector/collections/create" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Accept: */*" \
--data '{
"collectionName": "medium_articles_2020",
"dimension": 768
}'
# Output
# { "code": 200, "data": {} }
If you need full control of your collection, such as schema definition and manual enabling of dynamic schema, refer to Create Collection and Enable Dynamic Schema.
Each serverless cluster contains a maximum of two collections with basic settings. If you encounter an error while creating a collection, please check the number of collections on the Zilliz Cloud console.
View collections
To view information about a collection, you can make DescribeCollection API calls. The DescribeCollection operation returns the details of a specific collection.
- Python
- NodeJS
- Java
- Bash
res = client.describe_collection(
collection_name=COLLECTION_NAME
)
print(res)
# Output
#
# {
# "collection_name": "medium_articles_2020",
# "auto_id": false,
# "num_shards": 1,
# "description": "",
# "fields": [
# {
# "field_id": 100,
# "name": "id",
# "description": "",
# "type": 5,
# "params": {},
# "is_primary": true
# },
# {
# "field_id": 101,
# "name": "vector",
# "description": "",
# "type": 101,
# "params": {
# "dim": 768
# }
# }
# ],
# "aliases": [],
# "collection_id": 443943328732839733,
# "consistency_level": 2,
# "properties": [],
# "num_partitions": 1,
# "enable_dynamic_field": true
# }
async function main () {
// (Continued)
// Describe the created collection
res = await client.describeCollection({
collection_name: collectionName
});
console.log(res)
// Output
//
// {
// virtual_channel_names: [ 'by-dev-rootcoord-dml_0_445337000187266398v0' ],
// physical_channel_names: [ 'by-dev-rootcoord-dml_0' ],
// aliases: [],
// start_positions: [],
// properties: [],
// status: { error_code: 'Success', reason: '', code: 0 },
// schema: {
// fields: [ [Object], [Object] ],
// name: 'medium_articles_2020',
// description: '',
// autoID: false,
// enable_dynamic_field: true
// },
// collectionID: '445337000187266398',
// created_timestamp: '445337085300965381',
// created_utc_timestamp: '1698826161579',
// shards_num: 1,
// consistency_level: 'Bounded',
// collection_name: 'medium_articles_2020',
// db_name: 'default',
// num_partitions: '1'
// }
//
}
main()
public class QuickStartDemo
{
public static void main( String[] args )
{
// (Continued)
// 3. Describe collection
DescribeCollectionParam describeCollectionParam = DescribeCollectionParam.newBuilder()
.withCollectionName(collectionName)
.build();
R<DescribeCollectionResponse> collectionInfo = client.describeCollection(describeCollectionParam);
if (collectionInfo.getException() != null) {
System.err.println("Failed to describe collection: " + collectionInfo.getException().getMessage());
return;
}
DescCollResponseWrapper descCollResponseWrapper = new DescCollResponseWrapper(collectionInfo.getData());
System.out.println(descCollResponseWrapper);
// Output:
// Collection Description{name:'medium_articles', description:'', id:445337000188271120, shardNumber:1, createdUtcTimestamp:1698906291178, aliases:[], fields:[FieldType{name='id', type='Int64', elementType='None', primaryKey=true, partitionKey=false, autoID=false, params={}}, FieldType{name='vector', type='FloatVector', elementType='None', primaryKey=false, partitionKey=false, autoID=false, params={dim=768}}], isDynamicFieldEnabled:true}
}
}
# Replace PUBLIC_ENDPOINT and TOKEN with your own
# Replace TOKEN with your API key
curl --request GET \
--url "${PUBLIC_ENDPOINT}/v1/vector/collections/describe?collectionName=medium_articles_2020" \
--header "Authorization: Bearer ${TOKEN}" \
--header 'accept: application/json' \
--header 'content-type: application/json'
# Response
#
# {
# "code": 200,
# "data": {
# "collectionName": "medium_articles_2020",
# "shardsNum": 2,
# "description": "",
# "load": "loaded",
# "enableDynamicField": true,
# "fields": [
# {
# "name": "id",
# "type": "int64",
# "primaryKey": true,
# "autoId": true,
# "description": ""
# },
# {
# "name": "vector",
# "type": "floatVector(768)",
# "primaryKey": false,
# "autoId": false,
# "description": ""
# },
# {
# "name": "$meta",
# "type": "JSON",
# "primaryKey": false,
# "autoId": false,
# "description": "dynamic schema"
# }
# ],
# "indexes": [
# {
# "indexName": "vector_idx",
# "fieldName": "vector",
# "metricType": "L2"
# }
# ]
# }
# }
Insert data
In this example, we have prepared a dataset containing over 5,000 articles from Medium.com published from January through August in 2020. You can download the prepared dataset from here. To know more about the dataset, read the introduction page on Kaggle.
Here are some examples of inserting one or multiple entities from the dataset into the collection. You can view the inserted entities on the Zilliz Cloud console.
Insert a single entity
- Python
- NodeJS
- Java
- Bash
# Insert a single entity
res = client.insert(
collection_name=COLLECTION_NAME,
data={
'id': 0,
'title': 'The Reported Mortality Rate of Coronavirus Is Not Important',
'link': '<https://medium.com/swlh/the-reported-mortality-rate-of-coronavirus-is-not-important-369989c8d912>',
'reading_time': 13,
'publication': 'The Startup',
'claps': 1100,
'responses': 18,
'vector': [0.041732933, 0.013779674, -0.027564144, -0.013061441, 0.009748648, 0.00082446384, -0.00071647146, 0.048612226, -0.04836573, -0.04567751, 0.018008126, 0.0063936645, -0.011913628, 0.030776596, -0.018274948, 0.019929802, 0.020547243, 0.032735646, -0.031652678, -0.033816382, -0.051087562, -0.033748355, 0.0039493158, 0.009246126, -0.060236514, -0.017136049, 0.028754413, -0.008433934, 0.011168004, -0.012391256, -0.011225835, 0.031775184, 0.002929508, -0.007448661, -0.005337719, -0.010999258, -0.01515909, -0.005130484, 0.0060212007, 0.0034560722, -0.022935811, -0.04970116, -0.0155887455, 0.06627353, -0.006052789, -0.051570725, -0.109865054, 0.033205193, 0.00041118253, 0.0029823708, 0.036160238, -0.011256539, 0.00023560718, 0.058322437, 0.022275906, 0.015206677, -0.02884609, 0.0016338055, 0.0049200393, 0.014388571, -0.0049061654, -0.04664761, -0.027454877, 0.017526226, -0.005100602, 0.018090058, 0.02700998, 0.04031944, -0.0097965, -0.03674761, -0.0043163053, -0.023320708, 0.012654851, -0.014262311, -0.008081833, -0.018334744, 0.0014025003, -0.003053399, -0.002636383, -0.022398386, -0.004725274, 0.00036367847, -0.012368711, 0.0014739085, 0.03450414, 0.009684024, 0.017912658, 0.06594397, 0.021381201, 0.029343689, -0.0069561847, 0.026152428, 0.04635037, 0.014746184, -0.002119602, 0.034359712, -0.013705124, 0.010691518, 0.04060854, 0.013679299, -0.018990282, 0.035340093, 0.007353945, -0.035990074, 0.013126987, -0.032933377, -0.001756877, -0.0049658176, -0.03380879, -0.07024137, -0.0130426735, 0.010533265, -0.023091802, -0.004645729, -0.03344451, 0.04759929, 0.025985204, -0.040710885, -0.016681142, -0.024664842, -0.025170377, 0.08839205, -0.023733815, 0.019494494, 0.0055427826, 0.045460507, 0.07066554, 0.022181382, 0.018302314, 0.026806992, -0.006066003, 0.046525814, -0.04066389, 0.019001767, 0.021242762, -0.020784091, -0.031635042, 0.04573943, 0.02515421, -0.050663553, -0.05183343, -0.046468202, -0.07910535, 0.017036669, 0.021445233, 0.04277428, -0.020235524, -0.055314954, 0.00904601, -0.01104365, 0.03069203, -0.00821997, -0.035594665, 0.024322856, -0.0068963314, 0.009003657, 0.00398102, -0.008596356, 0.014772055, 0.02740991, 0.025503553, 0.0038213644, -0.0047855405, -0.034888722, 0.030553816, -0.008325959, 0.030010607, 0.023729775, 0.016138833, -0.022967983, -0.08616877, -0.02460819, -0.008210168, -0.06444098, 0.018750126, -0.03335763, 0.022024624, 0.032374356, 0.023870794, 0.021288997, -0.026617877, 0.020435361, -0.003692393, -0.024113296, 0.044870164, -0.030451361, 0.013022849, 0.002278627, -0.027616743, -0.012087787, -0.033232547, -0.022974484, 0.02801226, -0.029057292, 0.060317725, -0.02312559, 0.015558754, 0.073630534, 0.02490823, -0.0140531305, -0.043771528, 0.040756326, 0.01667925, -0.0046050115, -0.08938058, 0.10560781, 0.015044094, 0.003613817, 0.013523503, -0.011039813, 0.06396795, 0.013428416, -0.025031878, -0.014972648, -0.015970055, 0.037022553, -0.013759925, 0.013363354, 0.0039748577, -0.0040822625, 0.018209668, -0.057496265, 0.034993384, 0.07075411, 0.023498386, 0.085871644, 0.028646072, 0.007590898, 0.07037031, -0.05005178, 0.010477505, -0.014106617, 0.013402172, 0.007472563, -0.03131418, 0.020552127, -0.031878896, -0.04170217, -0.03153583, 0.03458349, 0.03366634, 0.021306382, -0.037176874, 0.029069472, 0.014662372, 0.0024123765, -0.025403008, -0.0372993, -0.049923114, -0.014209514, -0.015524425, 0.036377322, 0.04259327, -0.029715618, 0.02657093, -0.0062432447, -0.0024253451, -0.021287171, 0.010478781, -0.029322306, -0.021203341, 0.047209084, 0.025337176, 0.018471811, -0.008709492, -0.047414266, -0.06227469, -0.05713435, 0.02141101, 0.024481304, 0.07176469, 0.0211379, -0.049316987, -0.124073654, 0.0049275495, -0.02461509, -0.02738388, 0.04825289, -0.05069646, 0.012640115, -0.0061352802, 0.034599125, 0.02799496, -0.01511028, -0.046418104, 0.011309801, 0.016673129, -0.033531003, -0.049203333, -0.027218347, -0.03528408, 0.008881575, 0.010736325, 0.034232814, 0.012807507, -0.0100207105, 0.0067757815, 0.009538357, 0.026212366, -0.036120333, -0.019764563, 0.006527411, -0.016437015, -0.009759148, -0.042246807, 0.012492151, 0.0066206953, 0.010672299, -0.44499892, -0.036189068, -0.015703931, -0.031111298, -0.020329623, 0.0047888453, 0.090396516, -0.041484866, 0.033830352, -0.0033847596, 0.06065415, 0.030880837, 0.05558494, 0.022805553, 0.009607596, 0.006682602, 0.036806617, 0.02406229, 0.034229457, -0.0105605405, 0.034754273, 0.02436426, -0.03849325, 0.021132406, -0.01251386, 0.022090863, -0.029137045, 0.0064384523, -0.03175176, -0.0070441505, 0.016025176, -0.023172623, 0.00076795724, -0.024106828, -0.045440633, -0.0074440194, 0.00035374766, 0.024374487, 0.0058897804, -0.012461025, -0.029086761, 0.0029477053, -0.022914894, -0.032369837, 0.020743662, 0.024116345, 0.0020526652, 0.0008596536, -0.000583463, 0.061080184, 0.020812698, -0.0235381, 0.08112197, 0.05689626, -0.003070104, -0.010714772, -0.004864459, 0.027089117, -0.030910335, 0.0017404438, -0.014978656, 0.0127020255, 0.01878998, -0.051732827, -0.0037475713, 0.013033434, -0.023682894, -0.03219574, 0.03736345, 0.0058930484, -0.054040316, 0.047637977, 0.012636436, -0.05820182, 0.013828813, -0.057893142, -0.012405234, 0.030266648, -0.0029184038, -0.021839319, -0.045179468, -0.013123978, -0.021320488, 0.0015718226, 0.020244086, -0.014414709, 0.009535103, -0.004497577, -0.02577227, -0.0085017495, 0.029090486, 0.009356506, 0.0055838437, 0.021151636, 0.039531752, 0.07814674, 0.043186333, -0.0077368533, 0.028967595, 0.025058193, 0.05432941, -0.04383656, -0.027070394, -0.080263995, -0.03616516, -0.026129462, -0.0033627374, 0.035040155, 0.015231506, -0.06372076, 0.046391208, 0.0049725454, 0.003783345, -0.057800908, 0.061461, -0.017880175, 0.022820404, 0.048944063, 0.04725843, -0.013392871, 0.05023065, 0.0069421427, -0.019561166, 0.012953843, 0.06227977, -0.02114757, -0.003334329, 0.023241237, -0.061053444, -0.023145229, 0.016086273, 0.0774039, 0.008069459, -0.0013532874, -0.016790181, -0.027246375, -0.03254919, 0.033754334, 0.00037142826, -0.02387325, 0.0057056695, 0.0084914565, -0.051856343, 0.029254, 0.005583839, 0.011591886, -0.033027634, -0.004170374, 0.018334484, -0.0030969654, 0.0024489106, 0.0030196267, 0.023012564, 0.020529047, 0.00010772953, 0.0017700809, 0.029260442, -0.018829526, -0.024797931, -0.039499596, 0.008108761, -0.013099816, -0.11726566, -0.005652353, -0.008117937, -0.012961832, 0.0152542135, -0.06429504, 0.0184562, 0.058997117, -0.027178442, -0.019294549, -0.01587592, 0.0048053437, 0.043830805, 0.011232237, -0.026841154, -0.0007282251, -0.00862919, -0.008405325, 0.019370917, -0.008112641, -0.014931766, 0.065622255, 0.0149185015, 0.013089685, -0.0028022556, -0.028629888, -0.048105706, 0.009296162, 0.010251239, 0.030800395, 0.028263845, -0.011021621, -0.034127586, 0.014709971, -0.0075270324, 0.010737263, 0.020517904, -0.012932179, 0.007153817, 0.03736311, -0.03391106, 0.03028614, 0.012531187, -0.046059456, -0.0043963846, 0.028799629, -0.06663413, -0.009447025, -0.019833198, -0.036111858, -0.01901045, 0.040701825, 0.0060573653, 0.027482377, -0.019782187, -0.020186251, 0.028398912, 0.027108852, 0.026535714, -0.000995191, -0.020599326, -0.005658084, -0.017271476, 0.026300041, -0.006992451, -0.08593853, 0.03675959, 0.0029454317, -0.040927384, -0.035480253, 0.016498009, -0.03406521, -0.026182177, -0.0007024827, 0.019500641, 0.0047998386, -0.02416359, 0.0019833131, 0.0033488963, 0.037788488, -0.009154958, -0.043469638, -0.024896, -0.017234193, 0.044996973, -0.06303135, -0.051730774, 0.04041444, 0.0075959326, -0.03901764, -0.019851806, -0.008242245, 0.06107143, 0.030118924, -0.016167669, -0.028161867, -0.0025679746, -0.021713274, 0.025275888, -0.012819265, -0.036431268, 0.017991759, 0.040626206, -0.0036572467, -0.0005935883, -0.0037468506, 0.034460746, -0.0182785, -0.00431203, -0.044755403, 0.016463224, 0.041199315, -0.0093387, 0.03919184, -0.01151653, -0.016965209, 0.006347649, 0.021104146, 0.060276803, -0.026659148, 0.026461488, -0.032700688, 0.0012274865, -0.024675943, -0.003006079, -0.009607032, 0.010597691, 0.0043017124, -0.01908524, 0.006748306, -0.03049305, -0.017481703, 0.036747415, 0.036634356, 0.0007106319, 0.045647435, -0.020883067, -0.0593661, -0.03929885, 0.042825453, 0.016104022, -0.03222858, 0.031112716, 0.020407677, -0.013276762, 0.03657825, -0.033871554, 0.004176301, 0.009538976, -0.009995692, 0.0042660628, 0.050545394, -0.018142857, 0.005219403, 0.0006711967, -0.014264284, 0.031044828, -0.01827481, 0.012488852, 0.031393733, 0.050390214, -0.014484084, -0.054758117, 0.055042055, -0.005506624, -0.0066648237, 0.010891078, 0.012446279, 0.061687976, 0.018091502, 0.0026527622, 0.0321537, -0.02469515, 0.01772019, 0.006846163, -0.07471038, -0.024433741, 0.02483875, 0.0497063, 0.0043456135, 0.056550737, 0.035752796, -0.02430349, 0.036570627, -0.027576203, -0.012418993, 0.023442797, -0.03433812, 0.01953399, -0.028003592, -0.021168072, 0.019414881, -0.014712576, -0.0003938545, 0.021453558, -0.023197332, -0.004455581, -0.08799191, 0.0010808896, 0.009281116, -0.0051161298, 0.031497046, 0.034916095, -0.023042161, 0.030799815, 0.017298799, 0.0015253434, 0.013728047, 0.0035838438, 0.016767647, -0.022243451, 0.013371096, 0.053564783, -0.008776885, -0.013133307, 0.015577713, -0.027008705, 0.009490815, -0.04103532, -0.012426461, -0.0050485474, -0.04323231, -0.013291623, -0.01660157, -0.055480026, 0.017622838, 0.017476618, -0.009798125, 0.038226977, -0.03127579, 0.019329516, 0.033461004, -0.0039813113, -0.039526325, 0.03884973, -0.011381027, -0.023257744, 0.03033401, 0.0029607012, -0.0006490531, -0.0347344, 0.029701462, -0.04153701, 0.028073426, -0.025427297, 0.009756264, -0.048082624, 0.021743972, 0.057197016, 0.024082556, -0.013968224, 0.044379756, -0.029081704, 0.003487999, 0.042621125, -0.04339743, -0.027005397, -0.02944044, -0.024172144, -0.07388652, 0.05952364, 0.02561452, -0.010255158, -0.015288555, 0.045012463, 0.012403602, -0.021197597, 0.025847573, -0.016983166, 0.03021369, -0.02920852, 0.035140667, -0.010627725, -0.020431923, 0.03191218, 0.0046844087, 0.056356475, -0.00012615003, -0.0052536936, -0.058609407, 0.009710908, 0.00041168949, -0.22300485, -0.0077232462, 0.0029359192, -0.028645728, -0.021156758, 0.029606635, -0.026473567, -0.0019432966, 0.023867624, 0.021946864, -0.00082128344, 0.01897284, -0.017976845, -0.015677344, -0.0026336901, 0.030096486]
}
)
print(res)
# Output
#
# [0]
async function main () {
// (continued)
// Insert a record
res = await client.insert({
collection_name: collectionName,
data: [{
'id': 0,
'title': 'The Reported Mortality Rate of Coronavirus Is Not Important',
'link': '<https://medium.com/swlh/the-reported-mortality-rate-of-coronavirus-is-not-important-369989c8d912>',
'reading_time': 13,
'publication': 'The Startup',
'claps': 1100,
'responses': 18,
'vector': [0.041732933, 0.013779674, -0.027564144, -0.013061441, 0.009748648, 0.00082446384, -0.00071647146, 0.048612226, -0.04836573, -0.04567751, 0.018008126, 0.0063936645, -0.011913628, 0.030776596, -0.018274948, 0.019929802, 0.020547243, 0.032735646, -0.031652678, -0.033816382, -0.051087562, -0.033748355, 0.0039493158, 0.009246126, -0.060236514, -0.017136049, 0.028754413, -0.008433934, 0.011168004, -0.012391256, -0.011225835, 0.031775184, 0.002929508, -0.007448661, -0.005337719, -0.010999258, -0.01515909, -0.005130484, 0.0060212007, 0.0034560722, -0.022935811, -0.04970116, -0.0155887455, 0.06627353, -0.006052789, -0.051570725, -0.109865054, 0.033205193, 0.00041118253, 0.0029823708, 0.036160238, -0.011256539, 0.00023560718, 0.058322437, 0.022275906, 0.015206677, -0.02884609, 0.0016338055, 0.0049200393, 0.014388571, -0.0049061654, -0.04664761, -0.027454877, 0.017526226, -0.005100602, 0.018090058, 0.02700998, 0.04031944, -0.0097965, -0.03674761, -0.0043163053, -0.023320708, 0.012654851, -0.014262311, -0.008081833, -0.018334744, 0.0014025003, -0.003053399, -0.002636383, -0.022398386, -0.004725274, 0.00036367847, -0.012368711, 0.0014739085, 0.03450414, 0.009684024, 0.017912658, 0.06594397, 0.021381201, 0.029343689, -0.0069561847, 0.026152428, 0.04635037, 0.014746184, -0.002119602, 0.034359712, -0.013705124, 0.010691518, 0.04060854, 0.013679299, -0.018990282, 0.035340093, 0.007353945, -0.035990074, 0.013126987, -0.032933377, -0.001756877, -0.0049658176, -0.03380879, -0.07024137, -0.0130426735, 0.010533265, -0.023091802, -0.004645729, -0.03344451, 0.04759929, 0.025985204, -0.040710885, -0.016681142, -0.024664842, -0.025170377, 0.08839205, -0.023733815, 0.019494494, 0.0055427826, 0.045460507, 0.07066554, 0.022181382, 0.018302314, 0.026806992, -0.006066003, 0.046525814, -0.04066389, 0.019001767, 0.021242762, -0.020784091, -0.031635042, 0.04573943, 0.02515421, -0.050663553, -0.05183343, -0.046468202, -0.07910535, 0.017036669, 0.021445233, 0.04277428, -0.020235524, -0.055314954, 0.00904601, -0.01104365, 0.03069203, -0.00821997, -0.035594665, 0.024322856, -0.0068963314, 0.009003657, 0.00398102, -0.008596356, 0.014772055, 0.02740991, 0.025503553, 0.0038213644, -0.0047855405, -0.034888722, 0.030553816, -0.008325959, 0.030010607, 0.023729775, 0.016138833, -0.022967983, -0.08616877, -0.02460819, -0.008210168, -0.06444098, 0.018750126, -0.03335763, 0.022024624, 0.032374356, 0.023870794, 0.021288997, -0.026617877, 0.020435361, -0.003692393, -0.024113296, 0.044870164, -0.030451361, 0.013022849, 0.002278627, -0.027616743, -0.012087787, -0.033232547, -0.022974484, 0.02801226, -0.029057292, 0.060317725, -0.02312559, 0.015558754, 0.073630534, 0.02490823, -0.0140531305, -0.043771528, 0.040756326, 0.01667925, -0.0046050115, -0.08938058, 0.10560781, 0.015044094, 0.003613817, 0.013523503, -0.011039813, 0.06396795, 0.013428416, -0.025031878, -0.014972648, -0.015970055, 0.037022553, -0.013759925, 0.013363354, 0.0039748577, -0.0040822625, 0.018209668, -0.057496265, 0.034993384, 0.07075411, 0.023498386, 0.085871644, 0.028646072, 0.007590898, 0.07037031, -0.05005178, 0.010477505, -0.014106617, 0.013402172, 0.007472563, -0.03131418, 0.020552127, -0.031878896, -0.04170217, -0.03153583, 0.03458349, 0.03366634, 0.021306382, -0.037176874, 0.029069472, 0.014662372, 0.0024123765, -0.025403008, -0.0372993, -0.049923114, -0.014209514, -0.015524425, 0.036377322, 0.04259327, -0.029715618, 0.02657093, -0.0062432447, -0.0024253451, -0.021287171, 0.010478781, -0.029322306, -0.021203341, 0.047209084, 0.025337176, 0.018471811, -0.008709492, -0.047414266, -0.06227469, -0.05713435, 0.02141101, 0.024481304, 0.07176469, 0.0211379, -0.049316987, -0.124073654, 0.0049275495, -0.02461509, -0.02738388, 0.04825289, -0.05069646, 0.012640115, -0.0061352802, 0.034599125, 0.02799496, -0.01511028, -0.046418104, 0.011309801, 0.016673129, -0.033531003, -0.049203333, -0.027218347, -0.03528408, 0.008881575, 0.010736325, 0.034232814, 0.012807507, -0.0100207105, 0.0067757815, 0.009538357, 0.026212366, -0.036120333, -0.019764563, 0.006527411, -0.016437015, -0.009759148, -0.042246807, 0.012492151, 0.0066206953, 0.010672299, -0.44499892, -0.036189068, -0.015703931, -0.031111298, -0.020329623, 0.0047888453, 0.090396516, -0.041484866, 0.033830352, -0.0033847596, 0.06065415, 0.030880837, 0.05558494, 0.022805553, 0.009607596, 0.006682602, 0.036806617, 0.02406229, 0.034229457, -0.0105605405, 0.034754273, 0.02436426, -0.03849325, 0.021132406, -0.01251386, 0.022090863, -0.029137045, 0.0064384523, -0.03175176, -0.0070441505, 0.016025176, -0.023172623, 0.00076795724, -0.024106828, -0.045440633, -0.0074440194, 0.00035374766, 0.024374487, 0.0058897804, -0.012461025, -0.029086761, 0.0029477053, -0.022914894, -0.032369837, 0.020743662, 0.024116345, 0.0020526652, 0.0008596536, -0.000583463, 0.061080184, 0.020812698, -0.0235381, 0.08112197, 0.05689626, -0.003070104, -0.010714772, -0.004864459, 0.027089117, -0.030910335, 0.0017404438, -0.014978656, 0.0127020255, 0.01878998, -0.051732827, -0.0037475713, 0.013033434, -0.023682894, -0.03219574, 0.03736345, 0.0058930484, -0.054040316, 0.047637977, 0.012636436, -0.05820182, 0.013828813, -0.057893142, -0.012405234, 0.030266648, -0.0029184038, -0.021839319, -0.045179468, -0.013123978, -0.021320488, 0.0015718226, 0.020244086, -0.014414709, 0.009535103, -0.004497577, -0.02577227, -0.0085017495, 0.029090486, 0.009356506, 0.0055838437, 0.021151636, 0.039531752, 0.07814674, 0.043186333, -0.0077368533, 0.028967595, 0.025058193, 0.05432941, -0.04383656, -0.027070394, -0.080263995, -0.03616516, -0.026129462, -0.0033627374, 0.035040155, 0.015231506, -0.06372076, 0.046391208, 0.0049725454, 0.003783345, -0.057800908, 0.061461, -0.017880175, 0.022820404, 0.048944063, 0.04725843, -0.013392871, 0.05023065, 0.0069421427, -0.019561166, 0.012953843, 0.06227977, -0.02114757, -0.003334329, 0.023241237, -0.061053444, -0.023145229, 0.016086273, 0.0774039, 0.008069459, -0.0013532874, -0.016790181, -0.027246375, -0.03254919, 0.033754334, 0.00037142826, -0.02387325, 0.0057056695, 0.0084914565, -0.051856343, 0.029254, 0.005583839, 0.011591886, -0.033027634, -0.004170374, 0.018334484, -0.0030969654, 0.0024489106, 0.0030196267, 0.023012564, 0.020529047, 0.00010772953, 0.0017700809, 0.029260442, -0.018829526, -0.024797931, -0.039499596, 0.008108761, -0.013099816, -0.11726566, -0.005652353, -0.008117937, -0.012961832, 0.0152542135, -0.06429504, 0.0184562, 0.058997117, -0.027178442, -0.019294549, -0.01587592, 0.0048053437, 0.043830805, 0.011232237, -0.026841154, -0.0007282251, -0.00862919, -0.008405325, 0.019370917, -0.008112641, -0.014931766, 0.065622255, 0.0149185015, 0.013089685, -0.0028022556, -0.028629888, -0.048105706, 0.009296162, 0.010251239, 0.030800395, 0.028263845, -0.011021621, -0.034127586, 0.014709971, -0.0075270324, 0.010737263, 0.020517904, -0.012932179, 0.007153817, 0.03736311, -0.03391106, 0.03028614, 0.012531187, -0.046059456, -0.0043963846, 0.028799629, -0.06663413, -0.009447025, -0.019833198, -0.036111858, -0.01901045, 0.040701825, 0.0060573653, 0.027482377, -0.019782187, -0.020186251, 0.028398912, 0.027108852, 0.026535714, -0.000995191, -0.020599326, -0.005658084, -0.017271476, 0.026300041, -0.006992451, -0.08593853, 0.03675959, 0.0029454317, -0.040927384, -0.035480253, 0.016498009, -0.03406521, -0.026182177, -0.0007024827, 0.019500641, 0.0047998386, -0.02416359, 0.0019833131, 0.0033488963, 0.037788488, -0.009154958, -0.043469638, -0.024896, -0.017234193, 0.044996973, -0.06303135, -0.051730774, 0.04041444, 0.0075959326, -0.03901764, -0.019851806, -0.008242245, 0.06107143, 0.030118924, -0.016167669, -0.028161867, -0.0025679746, -0.021713274, 0.025275888, -0.012819265, -0.036431268, 0.017991759, 0.040626206, -0.0036572467, -0.0005935883, -0.0037468506, 0.034460746, -0.0182785, -0.00431203, -0.044755403, 0.016463224, 0.041199315, -0.0093387, 0.03919184, -0.01151653, -0.016965209, 0.006347649, 0.021104146, 0.060276803, -0.026659148, 0.026461488, -0.032700688, 0.0012274865, -0.024675943, -0.003006079, -0.009607032, 0.010597691, 0.0043017124, -0.01908524, 0.006748306, -0.03049305, -0.017481703, 0.036747415, 0.036634356, 0.0007106319, 0.045647435, -0.020883067, -0.0593661, -0.03929885, 0.042825453, 0.016104022, -0.03222858, 0.031112716, 0.020407677, -0.013276762, 0.03657825, -0.033871554, 0.004176301, 0.009538976, -0.009995692, 0.0042660628, 0.050545394, -0.018142857, 0.005219403, 0.0006711967, -0.014264284, 0.031044828, -0.01827481, 0.012488852, 0.031393733, 0.050390214, -0.014484084, -0.054758117, 0.055042055, -0.005506624, -0.0066648237, 0.010891078, 0.012446279, 0.061687976, 0.018091502, 0.0026527622, 0.0321537, -0.02469515, 0.01772019, 0.006846163, -0.07471038, -0.024433741, 0.02483875, 0.0497063, 0.0043456135, 0.056550737, 0.035752796, -0.02430349, 0.036570627, -0.027576203, -0.012418993, 0.023442797, -0.03433812, 0.01953399, -0.028003592, -0.021168072, 0.019414881, -0.014712576, -0.0003938545, 0.021453558, -0.023197332, -0.004455581, -0.08799191, 0.0010808896, 0.009281116, -0.0051161298, 0.031497046, 0.034916095, -0.023042161, 0.030799815, 0.017298799, 0.0015253434, 0.013728047, 0.0035838438, 0.016767647, -0.022243451, 0.013371096, 0.053564783, -0.008776885, -0.013133307, 0.015577713, -0.027008705, 0.009490815, -0.04103532, -0.012426461, -0.0050485474, -0.04323231, -0.013291623, -0.01660157, -0.055480026, 0.017622838, 0.017476618, -0.009798125, 0.038226977, -0.03127579, 0.019329516, 0.033461004, -0.0039813113, -0.039526325, 0.03884973, -0.011381027, -0.023257744, 0.03033401, 0.0029607012, -0.0006490531, -0.0347344, 0.029701462, -0.04153701, 0.028073426, -0.025427297, 0.009756264, -0.048082624, 0.021743972, 0.057197016, 0.024082556, -0.013968224, 0.044379756, -0.029081704, 0.003487999, 0.042621125, -0.04339743, -0.027005397, -0.02944044, -0.024172144, -0.07388652, 0.05952364, 0.02561452, -0.010255158, -0.015288555, 0.045012463, 0.012403602, -0.021197597, 0.025847573, -0.016983166, 0.03021369, -0.02920852, 0.035140667, -0.010627725, -0.020431923, 0.03191218, 0.0046844087, 0.056356475, -0.00012615003, -0.0052536936, -0.058609407, 0.009710908, 0.00041168949, -0.22300485, -0.0077232462, 0.0029359192, -0.028645728, -0.021156758, 0.029606635, -0.026473567, -0.0019432966, 0.023867624, 0.021946864, -0.00082128344, 0.01897284, -0.017976845, -0.015677344, -0.0026336901, 0.030096486]
}]
});
console.log(res)
// Output
//
// {
// succ_index: [ 0 ],
// err_index: [],
// status: { error_code: 'Success', reason: '', code: 0 },
// IDs: { int_id: { data: [Array] }, id_field: 'int_id' },
// acknowledged: false,
// insert_cnt: '1',
// delete_cnt: '0',
// upsert_cnt: '0',
// timestamp: '445337086401708038'
// }
//
}public class QuickStartDemo
{
public static void main( String[] args )
{
// (Continued)
// 4. Insert entities
String content;
Path file = Path.of(data_file);
try {
content = Files.readString(file);
} catch (Exception e) {
System.err.println("Failed to read file: " + e.getMessage());
return;
}
System.out.println("Successfully read file");
// Output:
// Successfully read file
// Load dataset
JSONObject dataset = JSON.parseObject(content);
// Change the counts argument to limit the rows.
List<JSONObject> rows = getRows(dataset.getJSONArray("rows"), 1);
// Pretty print the first row
System.out.println(rows.get(0));
// Output:
// {"id":0,"link":"https://medium.com/swlh/the-reported-mortality-rate-of-coronavirus-is-not-important-369989c8d912","publication":"The Startup","reading_time":13,"claps":1100,"responses":18,"title":"The Reported Mortality Rate of Coronavirus Is Not Important","vector":[0.041732933,0.013779674,-0.027564144,-0.013061441,0.009748648,8.2446384E-4,-7.1647146E-4,0.048612226,-0.04836573,-0.04567751,0.018008126,0.0063936645,-0.011913628,0.030776596,-0.018274948,0.019929802,0.020547243,0.032735646,-0.031652678,-0.033816382,-0.051087562,-0.033748355,0.0039493158,0.009246126,-0.060236514,-0.017136049,0.028754413,-0.008433934,0.011168004,-0.012391256,-0.011225835,0.031775184,0.002929508,-0.007448661,-0.005337719,-0.010999258,-0.01515909,-0.005130484,0.0060212007,0.0034560722,-0.022935811,-0.04970116,-0.0155887455,0.06627353,-0.006052789,-0.051570725,-0.109865054,0.033205193,4.1118253E-4,0.0029823708,0.036160238,-0.011256539,2.3560718E-4,0.058322437,0.022275906,0.015206677,-0.02884609,0.0016338055,0.0049200393,0.014388571,-0.0049061654,-0.04664761,-0.027454877,0.017526226,-0.005100602,0.018090058,0.02700998,0.04031944,-0.0097965,-0.03674761,-0.0043163053,-0.023320708,0.012654851,-0.014262311,-0.008081833,-0.018334744,0.0014025003,-0.003053399,-0.002636383,-0.022398386,-0.004725274,3.6367847E-4,-0.012368711,0.0014739085,0.03450414,0.009684024,0.017912658,0.06594397,0.021381201,0.029343689,-0.0069561847,0.026152428,0.04635037,0.014746184,-0.002119602,0.034359712,-0.013705124,0.010691518,0.04060854,0.013679299,-0.018990282,0.035340093,0.007353945,-0.035990074,0.013126987,-0.032933377,-0.001756877,-0.0049658176,-0.03380879,-0.07024137,-0.0130426735,0.010533265,-0.023091802,-0.004645729,-0.03344451,0.04759929,0.025985204,-0.040710885,-0.016681142,-0.024664842,-0.025170377,0.08839205,-0.023733815,0.019494494,0.0055427826,0.045460507,0.07066554,0.022181382,0.018302314,0.026806992,-0.006066003,0.046525814,-0.04066389,0.019001767,0.021242762,-0.020784091,-0.031635042,0.04573943,0.02515421,-0.050663553,-0.05183343,-0.046468202,-0.07910535,0.017036669,0.021445233,0.04277428,-0.020235524,-0.055314954,0.00904601,-0.01104365,0.03069203,-0.00821997,-0.035594665,0.024322856,-0.0068963314,0.009003657,0.00398102,-0.008596356,0.014772055,0.02740991,0.025503553,0.0038213644,-0.0047855405,-0.034888722,0.030553816,-0.008325959,0.030010607,0.023729775,0.016138833,-0.022967983,-0.08616877,-0.02460819,-0.008210168,-0.06444098,0.018750126,-0.03335763,0.022024624,0.032374356,0.023870794,0.021288997,-0.026617877,0.020435361,-0.003692393,-0.024113296,0.044870164,-0.030451361,0.013022849,0.002278627,-0.027616743,-0.012087787,-0.033232547,-0.022974484,0.02801226,-0.029057292,0.060317725,-0.02312559,0.015558754,0.073630534,0.02490823,-0.0140531305,-0.043771528,0.040756326,0.01667925,-0.0046050115,-0.08938058,0.10560781,0.015044094,0.003613817,0.013523503,-0.011039813,0.06396795,0.013428416,-0.025031878,-0.014972648,-0.015970055,0.037022553,-0.013759925,0.013363354,0.0039748577,-0.0040822625,0.018209668,-0.057496265,0.034993384,0.07075411,0.023498386,0.085871644,0.028646072,0.007590898,0.07037031,-0.05005178,0.010477505,-0.014106617,0.013402172,0.007472563,-0.03131418,0.020552127,-0.031878896,-0.04170217,-0.03153583,0.03458349,0.03366634,0.021306382,-0.037176874,0.029069472,0.014662372,0.0024123765,-0.025403008,-0.0372993,-0.049923114,-0.014209514,-0.015524425,0.036377322,0.04259327,-0.029715618,0.02657093,-0.0062432447,-0.0024253451,-0.021287171,0.010478781,-0.029322306,-0.021203341,0.047209084,0.025337176,0.018471811,-0.008709492,-0.047414266,-0.06227469,-0.05713435,0.02141101,0.024481304,0.07176469,0.0211379,-0.049316987,-0.124073654,0.0049275495,-0.02461509,-0.02738388,0.04825289,-0.05069646,0.012640115,-0.0061352802,0.034599125,0.02799496,-0.01511028,-0.046418104,0.011309801,0.016673129,-0.033531003,-0.049203333,-0.027218347,-0.03528408,0.008881575,0.010736325,0.034232814,0.012807507,-0.0100207105,0.0067757815,0.009538357,0.026212366,-0.036120333,-0.019764563,0.006527411,-0.016437015,-0.009759148,-0.042246807,0.012492151,0.0066206953,0.010672299,-0.44499892,-0.036189068,-0.015703931,-0.031111298,-0.020329623,0.0047888453,0.090396516,-0.041484866,0.033830352,-0.0033847596,0.06065415,0.030880837,0.05558494,0.022805553,0.009607596,0.006682602,0.036806617,0.02406229,0.034229457,-0.0105605405,0.034754273,0.02436426,-0.03849325,0.021132406,-0.01251386,0.022090863,-0.029137045,0.0064384523,-0.03175176,-0.0070441505,0.016025176,-0.023172623,7.6795724E-4,-0.024106828,-0.045440633,-0.0074440194,3.5374766E-4,0.024374487,0.0058897804,-0.012461025,-0.029086761,0.0029477053,-0.022914894,-0.032369837,0.020743662,0.024116345,0.0020526652,8.596536E-4,-5.83463E-4,0.061080184,0.020812698,-0.0235381,0.08112197,0.05689626,-0.003070104,-0.010714772,-0.004864459,0.027089117,-0.030910335,0.0017404438,-0.014978656,0.0127020255,0.01878998,-0.051732827,-0.0037475713,0.013033434,-0.023682894,-0.03219574,0.03736345,0.0058930484,-0.054040316,0.047637977,0.012636436,-0.05820182,0.013828813,-0.057893142,-0.012405234,0.030266648,-0.0029184038,-0.021839319,-0.045179468,-0.013123978,-0.021320488,0.0015718226,0.020244086,-0.014414709,0.009535103,-0.004497577,-0.02577227,-0.0085017495,0.029090486,0.009356506,0.0055838437,0.021151636,0.039531752,0.07814674,0.043186333,-0.0077368533,0.028967595,0.025058193,0.05432941,-0.04383656,-0.027070394,-0.080263995,-0.03616516,-0.026129462,-0.0033627374,0.035040155,0.015231506,-0.06372076,0.046391208,0.0049725454,0.003783345,-0.057800908,0.061461,-0.017880175,0.022820404,0.048944063,0.04725843,-0.013392871,0.05023065,0.0069421427,-0.019561166,0.012953843,0.06227977,-0.02114757,-0.003334329,0.023241237,-0.061053444,-0.023145229,0.016086273,0.0774039,0.008069459,-0.0013532874,-0.016790181,-0.027246375,-0.03254919,0.033754334,3.7142826E-4,-0.02387325,0.0057056695,0.0084914565,-0.051856343,0.029254,0.005583839,0.011591886,-0.033027634,-0.004170374,0.018334484,-0.0030969654,0.0024489106,0.0030196267,0.023012564,0.020529047,1.0772953E-4,0.0017700809,0.029260442,-0.018829526,-0.024797931,-0.039499596,0.008108761,-0.013099816,-0.11726566,-0.005652353,-0.008117937,-0.012961832,0.0152542135,-0.06429504,0.0184562,0.058997117,-0.027178442,-0.019294549,-0.01587592,0.0048053437,0.043830805,0.011232237,-0.026841154,-7.282251E-4,-0.00862919,-0.008405325,0.019370917,-0.008112641,-0.014931766,0.065622255,0.0149185015,0.013089685,-0.0028022556,-0.028629888,-0.048105706,0.009296162,0.010251239,0.030800395,0.028263845,-0.011021621,-0.034127586,0.014709971,-0.0075270324,0.010737263,0.020517904,-0.012932179,0.007153817,0.03736311,-0.03391106,0.03028614,0.012531187,-0.046059456,-0.0043963846,0.028799629,-0.06663413,-0.009447025,-0.019833198,-0.036111858,-0.01901045,0.040701825,0.0060573653,0.027482377,-0.019782187,-0.020186251,0.028398912,0.027108852,0.026535714,-9.95191E-4,-0.020599326,-0.005658084,-0.017271476,0.026300041,-0.006992451,-0.08593853,0.03675959,0.0029454317,-0.040927384,-0.035480253,0.016498009,-0.03406521,-0.026182177,-7.024827E-4,0.019500641,0.0047998386,-0.02416359,0.0019833131,0.0033488963,0.037788488,-0.009154958,-0.043469638,-0.024896,-0.017234193,0.044996973,-0.06303135,-0.051730774,0.04041444,0.0075959326,-0.03901764,-0.019851806,-0.008242245,0.06107143,0.030118924,-0.016167669,-0.028161867,-0.0025679746,-0.021713274,0.025275888,-0.012819265,-0.036431268,0.017991759,0.040626206,-0.0036572467,-5.935883E-4,-0.0037468506,0.034460746,-0.0182785,-0.00431203,-0.044755403,0.016463224,0.041199315,-0.0093387,0.03919184,-0.01151653,-0.016965209,0.006347649,0.021104146,0.060276803,-0.026659148,0.026461488,-0.032700688,0.0012274865,-0.024675943,-0.003006079,-0.009607032,0.010597691,0.0043017124,-0.01908524,0.006748306,-0.03049305,-0.017481703,0.036747415,0.036634356,7.106319E-4,0.045647435,-0.020883067,-0.0593661,-0.03929885,0.042825453,0.016104022,-0.03222858,0.031112716,0.020407677,-0.013276762,0.03657825,-0.033871554,0.004176301,0.009538976,-0.009995692,0.0042660628,0.050545394,-0.018142857,0.005219403,6.711967E-4,-0.014264284,0.031044828,-0.01827481,0.012488852,0.031393733,0.050390214,-0.014484084,-0.054758117,0.055042055,-0.005506624,-0.0066648237,0.010891078,0.012446279,0.061687976,0.018091502,0.0026527622,0.0321537,-0.02469515,0.01772019,0.006846163,-0.07471038,-0.024433741,0.02483875,0.0497063,0.0043456135,0.056550737,0.035752796,-0.02430349,0.036570627,-0.027576203,-0.012418993,0.023442797,-0.03433812,0.01953399,-0.028003592,-0.021168072,0.019414881,-0.014712576,-3.938545E-4,0.021453558,-0.023197332,-0.004455581,-0.08799191,0.0010808896,0.009281116,-0.0051161298,0.031497046,0.034916095,-0.023042161,0.030799815,0.017298799,0.0015253434,0.013728047,0.0035838438,0.016767647,-0.022243451,0.013371096,0.053564783,-0.008776885,-0.013133307,0.015577713,-0.027008705,0.009490815,-0.04103532,-0.012426461,-0.0050485474,-0.04323231,-0.013291623,-0.01660157,-0.055480026,0.017622838,0.017476618,-0.009798125,0.038226977,-0.03127579,0.019329516,0.033461004,-0.0039813113,-0.039526325,0.03884973,-0.011381027,-0.023257744,0.03033401,0.0029607012,-6.490531E-4,-0.0347344,0.029701462,-0.04153701,0.028073426,-0.025427297,0.009756264,-0.048082624,0.021743972,0.057197016,0.024082556,-0.013968224,0.044379756,-0.029081704,0.003487999,0.042621125,-0.04339743,-0.027005397,-0.02944044,-0.024172144,-0.07388652,0.05952364,0.02561452,-0.010255158,-0.015288555,0.045012463,0.012403602,-0.021197597,0.025847573,-0.016983166,0.03021369,-0.02920852,0.035140667,-0.010627725,-0.020431923,0.03191218,0.0046844087,0.056356475,-1.2615003E-4,-0.0052536936,-0.058609407,0.009710908,4.1168949E-4,-0.22300485,-0.0077232462,0.0029359192,-0.028645728,-0.021156758,0.029606635,-0.026473567,-0.0019432966,0.023867624,0.021946864,-8.2128344E-4,0.01897284,-0.017976845,-0.015677344,-0.0026336901,0.030096486]}
InsertRowsParam insertRowsParam = InsertRowsParam.newBuilder()
.withCollectionName(collectionName)
.withRows(rows)
.build();
R<InsertResponse> res = client.insert(insertRowsParam);
if (res.getException() != null) {
System.err.println("Failed to insert: " + res.getException().getMessage());
return;
}
System.out.println("Successfully inserted " + res.getData().getInsertCount() + " records");
// Output:
// Successfully inserted 1 records
}
public static List<JSONObject> getRows(JSONArray dataset, int counts) {
List<JSONObject> rows = new ArrayList<JSONObject>();
for (int i = 0; i < counts; i++) {
JSONObject json_row = new JSONObject(1, true);
JSONObject original_row = dataset.getJSONObject(i);
Long id = original_row.getLong("id");
String title = original_row.getString("title");
String link = original_row.getString("link");
String publication = original_row.getString("publication");
Long reading_time = original_row.getLong("reading_time");
Long claps = original_row.getLong("claps");
Long responses = original_row.getLong("responses");
List<Float> vectors = original_row.getJSONArray("title_vector").toJavaList(Float.class);
json_row.put("id", id);
json_row.put("link", link);
json_row.put("publication", publication);
json_row.put("reading_time", reading_time);
json_row.put("claps", claps);
json_row.put("responses", responses);
json_row.put("title", title);
json_row.put("vector", vectors);
rows.add(json_row);
}
return rows;
}
}# Read the first record from the dataset
data="$(cat path/to/medium_articles_2020_dpr.json \
| jq '.rows' \
| jq '.[0]' \
| jq -c '. + {"vector": .title_vector} | del(.title_vector) | del(.id)' )"
echo $data
# Insert a single entity
# Replace uri and API key with your own
curl --request POST \
--url "${PUBLIC_ENDPOINT}/v1/vector/insert" \
--header "Authorization: Bearer ${TOKEN}" \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data "{
\"collectionName\": \"medium_articles_2020\",
\"data\": ${data}
}"
# Output:
#
# {
# "code": 200,
# "data": {
# "insertCount": 1,
# "insertIds": [
# "442147653350115745"
# ]
# }
# }Insert multiple entities
- Python
- NodeJS
- Java
- Bash
# Read the first 200 records
with open(DATASET_PATH) as f:
data = json.load(f)
data = data["rows"][:200]
for x in data:
x["vector"] = x.pop("title_vector")
# Insert multiple entities
res = client.insert(
collection_name=COLLECTION_NAME,
data=data
)
print(res)
# Output
#
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, "(180 more items hidden)"]async function main() {
// (Continued)
// Read a few records from the dataset
const data = JSON.parse(fs.readFileSync(data_file, 'utf8'));
const client_data = data.rows.map((row) => {
row.vector = row.title_vector;
delete row.title_vector;
return row;
});
console.log(client_data[0]);
// Output
//
// [
// {
// id: 0,
// title: 'The Reported Mortality Rate of Coronavirus Is Not Important',
// link: 'https://medium.com/swlh/the-reported-mortality-rate-of-coronavirus-is-not-important-369989c8d912',
// reading_time: 13,
// publication: 'The Startup',
// claps: 1100,
// responses: 18,
// vector: [
// 0.041732933, 0.013779674, -0.027564144, -0.013061441,
// 0.009748648, 0.00082446384, -0.00071647146, 0.048612226,
// -0.04836573, -0.04567751, 0.018008126, 0.0063936645,
// -0.011913628, 0.030776596, -0.018274948, 0.019929802,
// 0.020547243, 0.032735646, -0.031652678, -0.033816382,
// -0.051087562, -0.033748355, 0.0039493158, 0.009246126,
// -0.060236514, -0.017136049, 0.028754413, -0.008433934,
// 0.011168004, -0.012391256, -0.011225835, 0.031775184,
// 0.002929508, -0.007448661, -0.005337719, -0.010999258,
// -0.01515909, -0.005130484, 0.0060212007, 0.0034560722,
// -0.022935811, -0.04970116, -0.0155887455, 0.06627353,
// -0.006052789, -0.051570725, -0.109865054, 0.033205193,
// 0.00041118253, 0.0029823708, 0.036160238, -0.011256539,
// 0.00023560718, 0.058322437, 0.022275906, 0.015206677,
// -0.02884609, 0.0016338055, 0.0049200393, 0.014388571,
// -0.0049061654, -0.04664761, -0.027454877, 0.017526226,
// -0.005100602, 0.018090058, 0.02700998, 0.04031944,
// -0.0097965, -0.03674761, -0.0043163053, -0.023320708,
// 0.012654851, -0.014262311, -0.008081833, -0.018334744,
// 0.0014025003, -0.003053399, -0.002636383, -0.022398386,
// -0.004725274, 0.00036367847, -0.012368711, 0.0014739085,
// 0.03450414, 0.009684024, 0.017912658, 0.06594397,
// 0.021381201, 0.029343689, -0.0069561847, 0.026152428,
// 0.04635037, 0.014746184, -0.002119602, 0.034359712,
// -0.013705124, 0.010691518, 0.04060854, 0.013679299,
// ... 668 more items
// ]
// }
// ]
//
res = await client.insert({
collection_name: collectionName,
data: client_data
})
console.log(res);
// Output
//
// {
// succ_index: [
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
// 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
// 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
// 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
// 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
// 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
// 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
// 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
// 96, 97, 98, 99,
// ... 5879 more items
// ],
// err_index: [],
// status: { error_code: 'Success', reason: '', code: 0 },
// IDs: { int_id: { data: [Array] }, id_field: 'int_id' },
// acknowledged: false,
// insert_cnt: '5979',
// delete_cnt: '0',
// upsert_cnt: '0',
// timestamp: '445337091304325121'
// }
//
}public class QuickStartDemo
{
public static void main( String[] args )
{
// (Continued)
// 4. Insert entities
String content;
Path file = Path.of(data_file);
try {
content = Files.readString(file);
} catch (Exception e) {
System.err.println("Failed to read file: " + e.getMessage());
return;
}
System.out.println("Successfully read file");
// Output:
// Successfully read file
// Load dataset
JSONObject dataset = JSON.parseObject(content);
// Change the counts argument to limit the rows.
List<JSONObject> rows = getRows(dataset.getJSONArray("rows"), 5979);
// Pretty print the first row
System.out.println(rows.get(0));
// Output:
// {"id":0,"link":"https://medium.com/swlh/the-reported-mortality-rate-of-coronavirus-is-not-important-369989c8d912","publication":"The Startup","reading_time":13,"claps":1100,"responses":18,"title":"The Reported Mortality Rate of Coronavirus Is Not Important","vector":[0.041732933,0.013779674,-0.027564144,-0.013061441,0.009748648,8.2446384E-4,-7.1647146E-4,0.048612226,-0.04836573,-0.04567751,0.018008126,0.0063936645,-0.011913628,0.030776596,-0.018274948,0.019929802,0.020547243,0.032735646,-0.031652678,-0.033816382,-0.051087562,-0.033748355,0.0039493158,0.009246126,-0.060236514,-0.017136049,0.028754413,-0.008433934,0.011168004,-0.012391256,-0.011225835,0.031775184,0.002929508,-0.007448661,-0.005337719,-0.010999258,-0.01515909,-0.005130484,0.0060212007,0.0034560722,-0.022935811,-0.04970116,-0.0155887455,0.06627353,-0.006052789,-0.051570725,-0.109865054,0.033205193,4.1118253E-4,0.0029823708,0.036160238,-0.011256539,2.3560718E-4,0.058322437,0.022275906,0.015206677,-0.02884609,0.0016338055,0.0049200393,0.014388571,-0.0049061654,-0.04664761,-0.027454877,0.017526226,-0.005100602,0.018090058,0.02700998,0.04031944,-0.0097965,-0.03674761,-0.0043163053,-0.023320708,0.012654851,-0.014262311,-0.008081833,-0.018334744,0.0014025003,-0.003053399,-0.002636383,-0.022398386,-0.004725274,3.6367847E-4,-0.012368711,0.0014739085,0.03450414,0.009684024,0.017912658,0.06594397,0.021381201,0.029343689,-0.0069561847,0.026152428,0.04635037,0.014746184,-0.002119602,0.034359712,-0.013705124,0.010691518,0.04060854,0.013679299,-0.018990282,0.035340093,0.007353945,-0.035990074,0.013126987,-0.032933377,-0.001756877,-0.0049658176,-0.03380879,-0.07024137,-0.0130426735,0.010533265,-0.023091802,-0.004645729,-0.03344451,0.04759929,0.025985204,-0.040710885,-0.016681142,-0.024664842,-0.025170377,0.08839205,-0.023733815,0.019494494,0.0055427826,0.045460507,0.07066554,0.022181382,0.018302314,0.026806992,-0.006066003,0.046525814,-0.04066389,0.019001767,0.021242762,-0.020784091,-0.031635042,0.04573943,0.02515421,-0.050663553,-0.05183343,-0.046468202,-0.07910535,0.017036669,0.021445233,0.04277428,-0.020235524,-0.055314954,0.00904601,-0.01104365,0.03069203,-0.00821997,-0.035594665,0.024322856,-0.0068963314,0.009003657,0.00398102,-0.008596356,0.014772055,0.02740991,0.025503553,0.0038213644,-0.0047855405,-0.034888722,0.030553816,-0.008325959,0.030010607,0.023729775,0.016138833,-0.022967983,-0.08616877,-0.02460819,-0.008210168,-0.06444098,0.018750126,-0.03335763,0.022024624,0.032374356,0.023870794,0.021288997,-0.026617877,0.020435361,-0.003692393,-0.024113296,0.044870164,-0.030451361,0.013022849,0.002278627,-0.027616743,-0.012087787,-0.033232547,-0.022974484,0.02801226,-0.029057292,0.060317725,-0.02312559,0.015558754,0.073630534,0.02490823,-0.0140531305,-0.043771528,0.040756326,0.01667925,-0.0046050115,-0.08938058,0.10560781,0.015044094,0.003613817,0.013523503,-0.011039813,0.06396795,0.013428416,-0.025031878,-0.014972648,-0.015970055,0.037022553,-0.013759925,0.013363354,0.0039748577,-0.0040822625,0.018209668,-0.057496265,0.034993384,0.07075411,0.023498386,0.085871644,0.028646072,0.007590898,0.07037031,-0.05005178,0.010477505,-0.014106617,0.013402172,0.007472563,-0.03131418,0.020552127,-0.031878896,-0.04170217,-0.03153583,0.03458349,0.03366634,0.021306382,-0.037176874,0.029069472,0.014662372,0.0024123765,-0.025403008,-0.0372993,-0.049923114,-0.014209514,-0.015524425,0.036377322,0.04259327,-0.029715618,0.02657093,-0.0062432447,-0.0024253451,-0.021287171,0.010478781,-0.029322306,-0.021203341,0.047209084,0.025337176,0.018471811,-0.008709492,-0.047414266,-0.06227469,-0.05713435,0.02141101,0.024481304,0.07176469,0.0211379,-0.049316987,-0.124073654,0.0049275495,-0.02461509,-0.02738388,0.04825289,-0.05069646,0.012640115,-0.0061352802,0.034599125,0.02799496,-0.01511028,-0.046418104,0.011309801,0.016673129,-0.033531003,-0.049203333,-0.027218347,-0.03528408,0.008881575,0.010736325,0.034232814,0.012807507,-0.0100207105,0.0067757815,0.009538357,0.026212366,-0.036120333,-0.019764563,0.006527411,-0.016437015,-0.009759148,-0.042246807,0.012492151,0.0066206953,0.010672299,-0.44499892,-0.036189068,-0.015703931,-0.031111298,-0.020329623,0.0047888453,0.090396516,-0.041484866,0.033830352,-0.0033847596,0.06065415,0.030880837,0.05558494,0.022805553,0.009607596,0.006682602,0.036806617,0.02406229,0.034229457,-0.0105605405,0.034754273,0.02436426,-0.03849325,0.021132406,-0.01251386,0.022090863,-0.029137045,0.0064384523,-0.03175176,-0.0070441505,0.016025176,-0.023172623,7.6795724E-4,-0.024106828,-0.045440633,-0.0074440194,3.5374766E-4,0.024374487,0.0058897804,-0.012461025,-0.029086761,0.0029477053,-0.022914894,-0.032369837,0.020743662,0.024116345,0.0020526652,8.596536E-4,-5.83463E-4,0.061080184,0.020812698,-0.0235381,0.08112197,0.05689626,-0.003070104,-0.010714772,-0.004864459,0.027089117,-0.030910335,0.0017404438,-0.014978656,0.0127020255,0.01878998,-0.051732827,-0.0037475713,0.013033434,-0.023682894,-0.03219574,0.03736345,0.0058930484,-0.054040316,0.047637977,0.012636436,-0.05820182,0.013828813,-0.057893142,-0.012405234,0.030266648,-0.0029184038,-0.021839319,-0.045179468,-0.013123978,-0.021320488,0.0015718226,0.020244086,-0.014414709,0.009535103,-0.004497577,-0.02577227,-0.0085017495,0.029090486,0.009356506,0.0055838437,0.021151636,0.039531752,0.07814674,0.043186333,-0.0077368533,0.028967595,0.025058193,0.05432941,-0.04383656,-0.027070394,-0.080263995,-0.03616516,-0.026129462,-0.0033627374,0.035040155,0.015231506,-0.06372076,0.046391208,0.0049725454,0.003783345,-0.057800908,0.061461,-0.017880175,0.022820404,0.048944063,0.04725843,-0.013392871,0.05023065,0.0069421427,-0.019561166,0.012953843,0.06227977,-0.02114757,-0.003334329,0.023241237,-0.061053444,-0.023145229,0.016086273,0.0774039,0.008069459,-0.0013532874,-0.016790181,-0.027246375,-0.03254919,0.033754334,3.7142826E-4,-0.02387325,0.0057056695,0.0084914565,-0.051856343,0.029254,0.005583839,0.011591886,-0.033027634,-0.004170374,0.018334484,-0.0030969654,0.0024489106,0.0030196267,0.023012564,0.020529047,1.0772953E-4,0.0017700809,0.029260442,-0.018829526,-0.024797931,-0.039499596,0.008108761,-0.013099816,-0.11726566,-0.005652353,-0.008117937,-0.012961832,0.0152542135,-0.06429504,0.0184562,0.058997117,-0.027178442,-0.019294549,-0.01587592,0.0048053437,0.043830805,0.011232237,-0.026841154,-7.282251E-4,-0.00862919,-0.008405325,0.019370917,-0.008112641,-0.014931766,0.065622255,0.0149185015,0.013089685,-0.0028022556,-0.028629888,-0.048105706,0.009296162,0.010251239,0.030800395,0.028263845,-0.011021621,-0.034127586,0.014709971,-0.0075270324,0.010737263,0.020517904,-0.012932179,0.007153817,0.03736311,-0.03391106,0.03028614,0.012531187,-0.046059456,-0.0043963846,0.028799629,-0.06663413,-0.009447025,-0.019833198,-0.036111858,-0.01901045,0.040701825,0.0060573653,0.027482377,-0.019782187,-0.020186251,0.028398912,0.027108852,0.026535714,-9.95191E-4,-0.020599326,-0.005658084,-0.017271476,0.026300041,-0.006992451,-0.08593853,0.03675959,0.0029454317,-0.040927384,-0.035480253,0.016498009,-0.03406521,-0.026182177,-7.024827E-4,0.019500641,0.0047998386,-0.02416359,0.0019833131,0.0033488963,0.037788488,-0.009154958,-0.043469638,-0.024896,-0.017234193,0.044996973,-0.06303135,-0.051730774,0.04041444,0.0075959326,-0.03901764,-0.019851806,-0.008242245,0.06107143,0.030118924,-0.016167669,-0.028161867,-0.0025679746,-0.021713274,0.025275888,-0.012819265,-0.036431268,0.017991759,0.040626206,-0.0036572467,-5.935883E-4,-0.0037468506,0.034460746,-0.0182785,-0.00431203,-0.044755403,0.016463224,0.041199315,-0.0093387,0.03919184,-0.01151653,-0.016965209,0.006347649,0.021104146,0.060276803,-0.026659148,0.026461488,-0.032700688,0.0012274865,-0.024675943,-0.003006079,-0.009607032,0.010597691,0.0043017124,-0.01908524,0.006748306,-0.03049305,-0.017481703,0.036747415,0.036634356,7.106319E-4,0.045647435,-0.020883067,-0.0593661,-0.03929885,0.042825453,0.016104022,-0.03222858,0.031112716,0.020407677,-0.013276762,0.03657825,-0.033871554,0.004176301,0.009538976,-0.009995692,0.0042660628,0.050545394,-0.018142857,0.005219403,6.711967E-4,-0.014264284,0.031044828,-0.01827481,0.012488852,0.031393733,0.050390214,-0.014484084,-0.054758117,0.055042055,-0.005506624,-0.0066648237,0.010891078,0.012446279,0.061687976,0.018091502,0.0026527622,0.0321537,-0.02469515,0.01772019,0.006846163,-0.07471038,-0.024433741,0.02483875,0.0497063,0.0043456135,0.056550737,0.035752796,-0.02430349,0.036570627,-0.027576203,-0.012418993,0.023442797,-0.03433812,0.01953399,-0.028003592,-0.021168072,0.019414881,-0.014712576,-3.938545E-4,0.021453558,-0.023197332,-0.004455581,-0.08799191,0.0010808896,0.009281116,-0.0051161298,0.031497046,0.034916095,-0.023042161,0.030799815,0.017298799,0.0015253434,0.013728047,0.0035838438,0.016767647,-0.022243451,0.013371096,0.053564783,-0.008776885,-0.013133307,0.015577713,-0.027008705,0.009490815,-0.04103532,-0.012426461,-0.0050485474,-0.04323231,-0.013291623,-0.01660157,-0.055480026,0.017622838,0.017476618,-0.009798125,0.038226977,-0.03127579,0.019329516,0.033461004,-0.0039813113,-0.039526325,0.03884973,-0.011381027,-0.023257744,0.03033401,0.0029607012,-6.490531E-4,-0.0347344,0.029701462,-0.04153701,0.028073426,-0.025427297,0.009756264,-0.048082624,0.021743972,0.057197016,0.024082556,-0.013968224,0.044379756,-0.029081704,0.003487999,0.042621125,-0.04339743,-0.027005397,-0.02944044,-0.024172144,-0.07388652,0.05952364,0.02561452,-0.010255158,-0.015288555,0.045012463,0.012403602,-0.021197597,0.025847573,-0.016983166,0.03021369,-0.02920852,0.035140667,-0.010627725,-0.020431923,0.03191218,0.0046844087,0.056356475,-1.2615003E-4,-0.0052536936,-0.058609407,0.009710908,4.1168949E-4,-0.22300485,-0.0077232462,0.0029359192,-0.028645728,-0.021156758,0.029606635,-0.026473567,-0.0019432966,0.023867624,0.021946864,-8.2128344E-4,0.01897284,-0.017976845,-0.015677344,-0.0026336901,0.030096486]}
InsertRowsParam insertRowsParam = InsertRowsParam.newBuilder()
.withCollectionName(collectionName)
.withRows(rows)
.build();
R<InsertResponse> res = client.insert(insertRowsParam);
if (res.getException() != null) {
System.err.println("Failed to insert: " + res.getException().getMessage());
return;
}
System.out.println("Successfully inserted " + res.getData().getInsertCount() + " records");
// Output:
// Successfully inserted 5979 records
}
public static List<JSONObject> getRows(JSONArray dataset, int counts) {
List<JSONObject> rows = new ArrayList<JSONObject>();
for (int i = 0; i < counts; i++) {
JSONObject json_row = new JSONObject(1, true);
JSONObject original_row = dataset.getJSONObject(i);
Long id = original_row.getLong("id");
String title = original_row.getString("title");
String link = original_row.getString("link");
String publication = original_row.getString("publication");
Long reading_time = original_row.getLong("reading_time");
Long claps = original_row.getLong("claps");
Long responses = original_row.getLong("responses");
List<Float> vectors = original_row.getJSONArray("title_vector").toJavaList(Float.class);
json_row.put("id", id);
json_row.put("link", link);
json_row.put("publication", publication);
json_row.put("reading_time", reading_time);
json_row.put("claps", claps);
json_row.put("responses", responses);
json_row.put("title", title);
json_row.put("vector", vectors);
rows.add(json_row);
}
return rows;
}
}# read the first 200 records from the dataset
data="$(cat path/to/medium_articles_2020_dpr.json \
| jq '.rows' \
| jq '.[1:200]' \
| jq -r '.[] | . + {"vector": .title_vector} | del(.title_vector) | del(.id)' \
| jq -s -c '.')"
echo $data
# Insert multiple entities
# Replace uri and API key with your own
curl --request POST \
--url "${PUBLIC_ENDPOINT}/v1/vector/insert" \
--header "Authorization: Bearer ${TOKEN}" \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data "{
\"collectionName\": \"medium_articles_2020\",
\"data\": ${data}
}"
# Response
#
# {
# "code": 200,
# "data": {
# "insertCount": 200,
# "insertIds": [
# "442147653350115755",
# "442147653350115756",
# ...
# ]
# }
# }
Search, query, and get operations
The search, query, and get API operations are three different operations for data retrieving:
A search operation performs an approximate nearest neighbor (ANN) search.
A query operation matches entities based on specific conditions.
A get operation fetches specific entities by their IDs.
Perform an ANN search
In the dataset, the vector field contains vector embeddings of each article’s title. This example illustrates how to conduct an ANN search among these vectors (finding the closest titles with a query vector data
).
- Python
- NodeJS
- Java
- Bash
# Conduct an ANN search
res = client.search(
collection_name=COLLECTION_NAME,
data=[data["rows"][0]["title_vector"]],
output_fields=["title"]
)
print(res)
# Output
#
# [
# [
# {
# "id": 0,
# "distance": 1.0,
# "entity": {
# "title": "The Reported Mortality Rate of Coronavirus Is Not Important"
# }
# },
# {
# "id": 70,
# "distance": 0.7525784969329834,
# "entity": {
# "title": "How bad will the Coronavirus Outbreak get? \u2014 Predicting the outbreak figures"
# }
# },
# {
# "id": 160,
# "distance": 0.7132074236869812,
# "entity": {
# "title": "The Funeral Industry is a Killer"
# }
# },
# {
# "id": 111,
# "distance": 0.6888885498046875,
# "entity": {
# "title": "The role of AI in web-based ADA and WCAG compliance"
# }
# },
# {
# "id": 196,
# "distance": 0.6882869601249695,
# "entity": {
# "title": "The Question We Should Be Asking About the Cost of Youth Sports"
# }
# },
# {
# "id": 51,
# "distance": 0.6719912886619568,
# "entity": {
# "title": "What if Facebook had to pay you for the profit they are making?"
# }
# },
# {
# "id": 178,
# "distance": 0.6699185371398926,
# "entity": {
# "title": "Is The Environmental Damage Due To Cruise Ships Irreversible?"
# }
# },
# {
# "id": 47,
# "distance": 0.6680259704589844,
# "entity": {
# "title": "What Happens When the Google Cookie Crumbles?"
# }
# },
# {
# "id": 135,
# "distance": 0.6597772836685181,
# "entity": {
# "title": "How to Manage Risk as a Product Manager"
# }
# }
# ]
# ]
async function main () {
// (Continued)
// Conduct an ANN search
res = await client.search({
collection_name: collectionName,
vector: client_data[0].vector,
output_fields: ['title', 'link'],
limit: 5,
})
console.log(res)
// Output
//
// {
// status: { error_code: 'Success', reason: '', code: 0 },
// results: [
// {
// score: 1,
// id: '0',
// title: 'The Reported Mortality Rate of Coronavirus Is Not Important',
// link: 'https://medium.com/swlh/the-reported-mortality-rate-of-coronavirus-is-not-important-369989c8d912'
// },
// {
// score: 0.8500008583068848,
// id: '3177',
// title: 'Following the Spread of Coronavirus',
// link: 'https://towardsdatascience.com/following-the-spread-of-coronavirus-23626940c125'
// },
// {
// score: 0.8194807767868042,
// id: '5607',
// title: 'The Hidden Side Effect of the Coronavirus',
// link: 'https://medium.com/swlh/the-hidden-side-effect-of-the-coronavirus-b6a7a5ee9586'
// },
// {
// score: 0.8116300106048584,
// id: '5641',
// title: 'Why The Coronavirus Mortality Rate is Misleading',
// link: 'https://towardsdatascience.com/why-the-coronavirus-mortality-rate-is-misleading-cc63f571b6a6'
// }
// ]
// }
//
// Conduct an ANN search with filters
res = await client.search({
collection_name: collectionName,
vector: client_data[0].vector,
output_fields: ["title", "claps", "publication"],
filter: 'claps > 100 and publication in ["The Startup", "Towards Data Science"]',
limit: 5,
})
console.log(res)
// Output
//
// {
// status: { error_code: 'Success', reason: '', code: 0 },
// results: [
// {
// score: 1,
// id: '0',
// claps: 1100,
// publication: 'The Startup',
// title: 'The Reported Mortality Rate of Coronavirus Is Not Important'
// },
// {
// score: 0.8500008583068848,
// id: '3177',
// claps: 215,
// publication: 'Towards Data Science',
// title: 'Following the Spread of Coronavirus'
// },
// {
// score: 0.8116300106048584,
// id: '5641',
// claps: 2900,
// publication: 'Towards Data Science',
// title: 'Why The Coronavirus Mortality Rate is Misleading'
// },
// {
// score: 0.7555683851242065,
// id: '4275',
// claps: 255,
// publication: 'The Startup',
// title: 'How Can AI Help Fight Coronavirus?'
// }
// ]
// }
//
}
public class QuickStartDemo
{
public static void main( String[] args )
{
// (Continued)
// 5. search
List<List<Float>> queryVectors = new ArrayList<>();
List<Float> queryVector1 = rows.get(0).getJSONArray("vector").toJavaList(Float.class);
queryVectors.add(queryVector1);
List<String> outputFields = new ArrayList<>();
outputFields.add("title");
SearchSimpleParam searchSimpleParam = SearchSimpleParam.newBuilder()
.withCollectionName(collectionName)
.withVectors(queryVectors)
.withOutputFields(outputFields)
.withOffset(0L)
.withLimit(3L)
.build();
R<SearchResponse> searchRes = client.search(searchSimpleParam);
if (searchRes.getException() != null) {
System.err.println("Failed to search: " + searchRes.getException().getMessage());
return;
}
List<RowRecord> searchResults = new ArrayList<>();
for (QueryResultsWrapper.RowRecord rowRecord: searchRes.getData().getRowRecords(0)) {
searchResults.add(rowRecord);
}
System.out.println(searchResults);
// Output:
// [[distance:0.0, id:0, title:The Reported Mortality Rate of Coronavirus Is Not Important], [distance:0.29999834, id:3177, title:Following the Spread of Coronavirus], [distance:0.36103833, id:5607, title:The Hidden Side Effect of the Coronavirus]]
// 6. search with filters
outputFields.add("claps");
outputFields.add("publication");
SearchSimpleParam searchSimpleParamWithFilter = SearchSimpleParam.newBuilder()
.withCollectionName(collectionName)
.withVectors(queryVectors)
.withOutputFields(outputFields)
.withFilter("claps > 100 and publication in ['The Startup', 'Towards Data Science']")
.withOffset(0L)
.withLimit(3L)
.build();
R<SearchResponse> searchResWithFilter = client.search(searchSimpleParamWithFilter);
if (searchResWithFilter.getException() != null) {
System.err.println("Failed to search: " + searchResWithFilter.getException().getMessage());
return;
}
List<RowRecord> searchWithFilterResults = new ArrayList<>();
for (QueryResultsWrapper.RowRecord rowRecord: searchResWithFilter.getData().getRowRecords(0)) {
searchWithFilterResults.add(rowRecord);
}
System.out.println(searchWithFilterResults);
// Output:
// [[distance:0.0, publication:The Startup, id:0, title:The Reported Mortality Rate of Coronavirus Is Not Important, claps:1100], [distance:0.29999834, publication:Towards Data Science, id:3177, title:Following the Spread of Coronavirus, claps:215], [distance:0.37674016, publication:Towards Data Science, id:5641, title:Why The Coronavirus Mortality Rate is Misleading, claps:2900]]
}
}
# read the first vector from the dataset
vector="$(cat path/to/medium_articles_2020_dpr.json \
| jq '.rows[0].title_vector' )"
echo $vector
# Replace uri and API key with your own
curl --request POST \
--url "${PUBLIC_ENDPOINT}/v1/vector/search" \
--header "Authorization: Bearer ${TOKEN}" \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data "{
\"collectionName\": \"medium_articles_2020\",
\"limit\": 3,
\"vector\": $vector
}"
# Response
#
# {
# "code": 200,
# "data": [
# {
# "distance": 0,
# "id": 442147653350115900
# },
# {
# "distance": 0.494843,
# "id": 442147653350116000
# },
# {
# "distance": 0.65601754,
# "id": 442147653350116000
# }
# ]
# }
You can also conduct an ANN search in a limited scope by applying a filter condition.
- Python
- NodeJS
- Java
- Bash
# Conduct an ANN search with filters
res = client.search(
collection_name=COLLECTION_NAME,
data=[data["rows"][0]["title_vector"]],
filter='claps > 100 and publication in ["The Startup", "Towards Data Science"]',
output_fields=["title", "claps", "publication"]
)
print(res)
# Output
#
# [
# [
# {
# "id": 0,
# "distance": 1.0,
# "entity": {
# "title": "The Reported Mortality Rate of Coronavirus Is Not Important",
# "publication": "The Startup",
# "claps": 1100
# }
# },
# {
# "id": 70,
# "distance": 0.7525784969329834,
# "entity": {
# "title": "How bad will the Coronavirus Outbreak get? \u2014 Predicting the outbreak figures",
# "publication": "Towards Data Science",
# "claps": 1100
# }
# },
# {
# "id": 160,
# "distance": 0.7132074236869812,
# "entity": {
# "title": "The Funeral Industry is a Killer",
# "publication": "The Startup",
# "claps": 407
# }
# },
# {
# "id": 111,
# "distance": 0.6888885498046875,
# "entity": {
# "title": "The role of AI in web-based ADA and WCAG compliance",
# "publication": "Towards Data Science",
# "claps": 935
# }
# },
# {
# "id": 47,
# "distance": 0.6680259704589844,
# "entity": {
# "title": "What Happens When the Google Cookie Crumbles?",
# "publication": "The Startup",
# "claps": 203
# }
# },
# {
# "id": 135,
# "distance": 0.6597772836685181,
# "entity": {
# "title": "How to Manage Risk as a Product Manager",
# "publication": "The Startup",
# "claps": 120
# }
# },
# {
# "id": 174,
# "distance": 0.6502071619033813,
# "entity": {
# "title": "I Thought Suicide was Selfish Until I Wanted to Die",
# "publication": "The Startup",
# "claps": 319
# }
# },
# {
# "id": 7,
# "distance": 0.6361640095710754,
# "entity": {
# "title": "Building Comprehensible Customer Churn Prediction Models",
# "publication": "The Startup",
# "claps": 261
# }
# },
# {
# "id": 181,
# "distance": 0.6355971693992615,
# "entity": {
# "title": "It\u2019s OK to Admit You\u2019re Writing For Money",
# "publication": "The Startup",
# "claps": 626
# }
# }
# ]
# ]
async function main () {
// (Continued)
// Conduct an ANN search with filters
res = await client.search({
collection_name: collectionName,
vector: client_data[0].vector,
output_fields: ["title", "claps", "publication"],
filter: 'claps > 100 and publication in ["The Startup", "Towards Data Science"]',
limit: 5,
})
console.log(res)
// Output
//
// {
// status: { error_code: 'Success', reason: '', code: 0 },
// results: [
// {
// score: 1,
// id: '0',
// claps: 1100,
// publication: 'The Startup',
// title: 'The Reported Mortality Rate of Coronavirus Is Not Important'
// },
// {
// score: 0.8500008583068848,
// id: '3177',
// claps: 215,
// publication: 'Towards Data Science',
// title: 'Following the Spread of Coronavirus'
// },
// {
// score: 0.8116300106048584,
// id: '5641',
// claps: 2900,
// publication: 'Towards Data Science',
// title: 'Why The Coronavirus Mortality Rate is Misleading'
// },
// {
// score: 0.7555683851242065,
// id: '4275',
// claps: 255,
// publication: 'The Startup',
// title: 'How Can AI Help Fight Coronavirus?'
// }
// ]
// }
//
}
public class QuickStartDemo
{
public static void main( String[] args )
{
// (Continued)
// 6. search with filters
outputFields.add("claps");
outputFields.add("publication");
SearchSimpleParam searchSimpleParamWithFilter = SearchSimpleParam.newBuilder()
.withCollectionName(collectionName)
.withVectors(queryVectors)
.withOutputFields(outputFields)
.withFilter("claps > 100 and publication in ['The Startup', 'Towards Data Science']")
.withOffset(0L)
.withLimit(3L)
.build();
R<SearchResponse> searchResWithFilter = client.search(searchSimpleParamWithFilter);
if (searchResWithFilter.getException() != null) {
System.err.println("Failed to search: " + searchResWithFilter.getException().getMessage());
return;
}
List<RowRecord> searchWithFilterResults = new ArrayList<>();
for (QueryResultsWrapper.RowRecord rowRecord: searchResWithFilter.getData().getRowRecords(0)) {
searchWithFilterResults.add(rowRecord);
}
System.out.println(searchWithFilterResults);
// Output:
// [[distance:0.0, publication:The Startup, id:0, title:The Reported Mortality Rate of Coronavirus Is Not Important, claps:1100], [distance:0.29999834, publication:Towards Data Science, id:3177, title:Following the Spread of Coronavirus, claps:215], [distance:0.37674016, publication:Towards Data Science, id:5641, title:Why The Coronavirus Mortality Rate is Misleading, claps:2900]]
}
}
# read the first vector from the dataset
vector="$(cat path/to/medium_articles_2020_dpr.json \
| jq '.rows[0].title_vector' )"
echo $vector
# Replace uri and API key with your own
curl --request POST \
--url "${PUBLIC_ENDPOINT}/v1/vector/search" \
--header "Authorization: Bearer ${API_KEY}" \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data "{
\"collectionName\": \"medium_articles_2020\",
\"limit\": 3,
\"vector\": $vector,
\"filter\": \"claps > 5\",
\"outputFields\": [\"title\", \"claps\"]
}"
# Output
#
# {
# "code": 200,
# "data": [
# {
# "claps": 1100,
# "distance": 0,
# "title": "The Reported Mortality Rate of Coronavirus Is Not Important"
# },
# {
# "claps": 1100,
# "distance": 0.494843,
# "title": "How bad will the Coronavirus Outbreak get? — Predicting the outbreak figures"
# },
# {
# "claps": 54,
# "distance": 0.65601754,
# "title": "What if Facebook had to pay you for the profit they are making?"
# }
# ]
# }
Perform a query
All fields, except for the vector field, are scalar fields. You can define a filter condition against scalar fields to fetch the necessary entities.
Here is an example of a query.
- Python
- NodeJS
- Java
- Bash
# Perform a query
res = client.query(
collection_name=COLLECTION_NAME,
filter="claps > 100 and publication in ['The Startup', 'Towards Data Science']",
limit=3,
outputField=["title", "claps", "publication"]
)
print(res[0])
# Output
#
# [
# {
# "id": 0,
# "title": "The Reported Mortality Rate of Coronavirus Is Not Important",
# "link": "<https://medium.com/swlh/the-reported-mortality-rate-of-coronavirus-is-not-important-369989c8d912>",
# "reading_time": 13,
# "publication": "The Startup",
# "claps": 1100,
# "responses": 18,
# "vector": [
# 0.041732933,
# 0.013779674,
# -0.027564144,
# -0.013061441,
# 0.009748648,
# 0.00082446384,
# -0.00071647146,
# 0.048612226,
# -0.04836573,
# -0.04567751,
# 0.018008126,
# 0.0063936645,
# -0.011913628,
# 0.030776596,
# -0.018274948,
# 0.019929802,
# 0.020547243,
# 0.032735646,
# -0.031652678,
# -0.033816382,
# "(748 more items hidden)"
# ]
# }
# ]
async function main () {
// (Continued)
// Perform a query
res = await client.query({
collection_name: collectionName,
filter: 'claps > 100 and publication in ["The Startup", "Towards Data Science"]',
output_fields: ["title", "claps", "publication"],
limit: 5,
})
console.log(res)
// Output
//
// {
// status: { error_code: 'Success', reason: '', code: 0 },
// data: [
// { '$meta': [Object], id: '0' },
// { '$meta': [Object], id: '1' },
// { '$meta': [Object], id: '2' },
// { '$meta': [Object], id: '3' }
// ]
// }
//
}
public class QuickStartDemo
{
public static void main( String[] args )
{
// (Continued)
QuerySimpleParam querySimpleParam = QuerySimpleParam.newBuilder()
.withCollectionName(collectionName)
.withFilter("claps > 100 and publication in ['The Startup', 'Towards Data Science']")
.withOutputFields(outputFields)
.withOffset(0L)
.withLimit(3L)
.build();
R<QueryResponse> queryRes = client.query(querySimpleParam);
if (queryRes.getException() != null) {
System.err.println("Failed to query: " + queryRes.getException().getMessage());
return;
}
List<RowRecord> queryResults = new ArrayList<>();
for (QueryResultsWrapper.RowRecord rowRecord: queryRes.getData().getRowRecords()) {
queryResults.add(rowRecord);
}
System.out.println(queryResults);
// Output:
// [[publication:The Startup, id:0, title:The Reported Mortality Rate of Coronavirus Is Not Important, claps:1100], [publication:The Startup, id:1, title:Dashboards in Python: 3 Advanced Examples for Dash Beginners and Everyone Else, claps:726], [publication:The Startup, id:2, title:How Can We Best Switch in Python?, claps:500]]
}
}
# Replace uri and API key with your own
curl --request POST \
--url "${PUBLIC_ENDPOINT}/v1/vector/query" \
--header "Authorization: Bearer ${TOKEN}" \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data "{
\"collectionName\": \"medium_articles_2020\",
\"limit\": 3,
\"filter\": \"claps > 100 and publication in ['The Startup', 'Towards Data Science']\",
\"outputFields\": [\"title\", \"claps\", \"publication\"]
}"
# Output
#
# {
# "code": 200,
# "data": [
# {
# "claps": 1100,
# "id": 442147653350117440,
# "publication": "The Startup",
# "title": "The Reported Mortality Rate of Coronavirus Is Not Important"
# },
# {
# "claps": 726,
# "id": 442147653350117440,
# "publication": "The Startup",
# "title": "Dashboards in Python: 3 Advanced Examples for Dash Beginners and Everyone Else"
# },
# {
# "claps": 500,
# "id": 442147653350117440,
# "publication": "The Startup",
# "title": "How Can We Best Switch in Python?"
# }
# ]
# }
Get entities by IDs
In some cases, you may want to get specific entities based on their IDs. This is where the get operation comes into play.
Here are some examples of getting entities by IDs.
Get a single entity by its ID
- Python
- NodeJS
- Java
- Bash
# Retrieve a single entity by ID
res = client.get(
collection_name=COLLECTION_NAME,
ids=1
)
print(res)
# Output
#
# [
# {
# "id": 1,
# "title": "Dashboards in Python: 3 Advanced Examples for Dash Beginners and Everyone Else",
# "link": "https://medium.com/swlh/dashboards-in-python-3-advanced-examples-for-dash-beginners-and-everyone-else-b1daf4e2ec0a",
# "reading_time": 14,
# "publication": "The Startup",
# "claps": 726,
# "responses": 3,
# "vector": [
# 0.0039737443,
# 0.003020432,
# -0.0006188639,
# 0.03913546,
# -0.00089768134,
# 0.021238148,
# 0.014454661,
# 0.025742851,
# 0.0022063442,
# -0.051130578,
# -0.0010897011,
# 0.038453076,
# 0.011593861,
# -0.046852026,
# 0.0064208573,
# 0.010120634,
# -0.023668954,
# 0.041229635,
# 0.008146385,
# -0.023367394,
# "(748 more items hidden)"
# ]
# }
# ]async function main () {
// (Continued)
// Get an entity by id
res = await client.get({
collection_name: collectionName,
ids: [0],
output_fields: ['id', 'title']
});
console.log(res)
// Output
//
// {
// status: { error_code: 'Success', reason: '', code: 0 },
// data: [ { id: '0', '$meta': [Object] } ]
// }
//
}public class QuickStartDemo
{
public static void main( String[] args )
{
// (Continued)
List<String> ids = Lists.newArrayList("1");
// List<String> ids = Lists.newArrayList("1", "2", "3");
GetIdsParam getParam = GetIdsParam.newBuilder()
.withCollectionName(collectionName)
.withPrimaryIds(ids)
.withOutputFields(Lists.newArrayList("*"))
.build();
R<GetResponse> getRes = client.get(getParam);
if (getRes.getException() != null) {
System.err.println("Failed to get: " + getRes.getException().getMessage());
return;
}
List<RowRecord> getResults = new ArrayList<>();
for (QueryResultsWrapper.RowRecord rowRecord: getRes.getData().getRowRecords()) {
getResults.add(rowRecord);
}
System.out.println(getResults);
// Output:
// [[reading_time:14, publication:The Startup, link:https://medium.com/swlh/dashboards-in-python-3-advanced-examples-for-dash-beginners-and-everyone-else-b1daf4e2ec0a, responses:3, vector:[0.0039737443, 0.003020432, -6.188639E-4, 0.03913546, -8.9768134E-4, 0.021238148, 0.014454661, 0.025742851, 0.0022063442, -0.051130578, -0.0010897011, 0.038453076, 0.011593861, -0.046852026, 0.0064208573, 0.010120634, -0.023668954, 0.041229635, 0.008146385, -0.023367394, -0.029139837, -0.023222756, -0.016318452, -0.076287195, 0.035851076, 0.044926822, 0.0037161126, 0.024241403, -0.024827085, -0.012770665, 0.0018561907, 0.047921725, -0.030281143, -0.031129083, -0.038785066, -0.048101038, 0.008587025, -0.0036647166, -0.013043694, -0.044786748, 0.0015023423, -0.02393749, 0.027479807, 0.03407725, -0.011031249, -0.016997544, -0.11140522, -0.0012403706, -0.0116099715, 0.010803051, -0.042221617, 0.071550176, 0.029078195, 0.02936992, -0.016870253, 0.024187507, -0.0064322287, -0.0018420032, -0.010838795, 0.005448679, 0.042049922, 0.015199081, -0.00612731, 0.04651738, -4.543191E-4, 0.0018536948, -0.021741537, 0.042303678, -0.016282137, 0.031659417, 0.03347323, -0.05687932, -0.04784338, 0.047716856, -0.04012971, -0.024161791, -0.015605036, 0.01364975, 0.023177518, 0.01887649, 0.040253926, 0.021470893, 0.09768697, -0.032784328, 0.03222924, 0.03559948, -0.0028161134, 0.03687029, -0.013814558, -0.009652667, 0.021593641, -0.05943368, 0.026042875, 0.028282177, 0.007687183, 0.020226369, -0.0016281981, -0.008526736, 0.025751492, -0.003104332, -0.0061201006, 0.02595484, -0.021449475, -0.014293144, -0.029449001, 0.0020593074, -0.034804724, -0.022180008, -0.006285631, 0.013707787, -0.037423145, -0.009107584, -0.009432007, 0.010610414, -0.056727782, 0.0233536, -0.0060632285, 0.055170756, 0.015278058, -0.0074357074, 0.038479842, 0.07088861, 0.06036749, 0.015448346, 0.024050185, 0.015041763, 0.022847643, 0.018183885, 0.047313735, 0.026332416, -0.002408156, 0.04366259, 0.0057872427, -0.02127312, -0.020023786, -0.02634593, 0.028322363, 0.020426102, 0.026535949, 0.031108813, -0.03800821, -0.016794013, -0.0022405083, -0.028002623, 0.013555326, -0.020880137, -0.040561143, -0.024379047, -0.058721762, 0.009864129, -0.0060728258, 0.019879017, -0.027474888, 0.004868736, -0.01618118, 0.07627549, -0.009566949, -0.0362882, -0.0013981637, 3.6380984E-4, 0.025276562, 0.061608184, -0.048915602, -0.043986745, -0.0055106534, -0.03694729, 0.0018953384, 0.0063064545, 0.010227479, -0.0068412647, -0.011093203, -0.0093250135, -0.019277632, 0.026233265, 0.009567129, 0.008851426, 0.01565083, 0.02383659, 0.058387164, 0.007578936, -0.039052304, -0.020484922, 0.041768145, -0.038177934, 0.032690376, -0.0088214185, 0.040147487, 0.015718441, -0.026545178, -0.023138655, -0.055501554, -0.06176257, 0.01347796, -0.043426935, 0.09015595, -0.05628449, -0.03414897, 0.077925004, 0.039848283, 0.004569112, -0.021932716, -0.008975595, 0.032322578, 0.0011694044, -0.008094395, 0.013524566, -0.010504273, -0.008891303, -0.047701288, -0.003401436, -0.006817342, -0.0131783355, 0.013252014, -0.02291292, 0.005158376, -0.005217175, -0.009027178, 0.01674159, 0.0062977904, -0.0021274886, 0.1001569, -0.010145763, 0.00398632, 0.016642937, -0.04561657, -0.00593123, 0.068103015, 0.022859594, 0.055262484, -0.07711217, -0.013573, 0.00793467, -0.00206392, -0.055678505, -0.0027695482, -0.008978216, 0.023205645, 0.010584002, 0.036940057, 0.0055925045, -0.03128972, 0.008169264, 0.002143065, 0.0054644635, 0.007751248, -0.049370192, -0.017171964, 0.012460248, -0.039616507, -0.008905116, -0.029277697, 0.0316178, 0.007783805, -0.046197712, -0.02389374, 0.03949501, 0.012882567, -0.050312858, -0.0025155935, 0.05531826, -0.0060943947, 0.040836193, -0.0057800347, 0.0639973, 0.009591699, -0.05218372, -0.03645041, -0.05206777, 0.053644467, 0.071591765, 0.008294372, 0.0028174156, 0.0048404625, 0.013453085, 0.022866488, -0.06087804, 0.023474297, 0.027761765, -0.040729735, -0.009113696, 0.020109607, 0.010756393, 0.066961266, -0.03530044, -0.0013631586, -0.034647003, 0.03281657, -0.055955954, -0.043759737, -0.014830927, -0.0012740378, 0.053068876, 0.0041171, -0.009249764, 0.04119711, -0.0022221678, 0.008220726, 0.011716879, 0.04751782, -0.021161754, -0.0034890848, 0.017168297, 0.018082855, -0.054346565, 0.01130623, -0.014759945, -0.020925378, -0.011718521, -0.5058962, -0.016079627, -0.05195381, -0.065540574, -0.024114326, 0.0045832954, 0.05303542, -0.040304415, -0.001513657, 0.019103762, 0.008554532, 0.053032935, -0.00915671, -0.009092158, -0.009177251, 0.028371146, 0.028055405, -0.008145964, 0.011927662, 0.027140373, -0.04623, -0.026633251, -1.9752477E-4, 0.045192443, 0.02449006, 0.013997616, -0.06873905, 0.027910134, 0.003347047, 0.0013439717, 0.034202795, -0.015585498, -0.055015743, 1.6024683E-4, -0.015891591, -0.021741774, 0.025558911, 0.011084363, 0.014056266, -0.018982887, 0.0016998561, 0.048058353, 0.007829392, 0.0018672302, 0.041273497, -0.039120134, 3.624535E-4, -0.0011298673, -0.006326307, 0.032140832, -0.037109844, -4.1404666E-4, -0.0084530655, 0.0077904286, 0.012144728, -0.03869803, 0.047453202, 0.04121898, -0.032067478, 0.022875102, 0.07410041, -0.024542922, -0.036993448, -0.039777547, 0.0094557, -0.025156112, -0.035101883, -0.048749104, -0.0045563756, -0.006167684, -0.048193872, 0.0017396678, 0.019029584, -0.061944872, 0.050563816, -0.021848006, 0.008817201, 0.010323988, 0.020705162, 0.018577144, -0.048376583, -0.041189134, -0.0047300197, -0.00836772, -0.0052992413, -0.035920832, -0.029942693, 0.028925791, 0.030509083, 0.00738733, 0.124217756, -0.04977689, 0.023752924, 0.027065763, 0.057005685, 0.03732509, 0.069008276, -0.022444589, 0.0035944746, -0.041807327, 0.028195074, -0.011788701, -0.0034672262, -0.014074685, -0.009594197, 0.0018883395, -0.024706602, 0.015436245, 0.054175258, -0.03945695, -0.029252004, -0.006543419, -0.064558335, 0.00635337, 0.014417143, 0.013945442, -0.009091861, 5.249867E-4, 0.010337455, -0.009454559, -0.035721924, -0.022774082, -0.031336624, 0.0416093, -0.038794383, -0.008280955, 0.033273164, 0.013371025, -0.0129316645, -0.012368203, 0.022565264, -0.0012145197, 0.01841233, -0.002506566, 0.02414115, -0.047187645, -0.0046407585, 0.032652196, 0.053410284, -0.0365266, -0.0063986774, 0.023949109, 0.010821287, 0.013743939, 0.04780526, 0.008855356, -0.028712442, 0.010830425, -0.0039607813, 0.022576412, -0.009031381, -0.04623192, 0.0140510835, 0.009459673, -0.0033195931, 0.02447672, 0.025940116, 0.015182389, -0.03030254, -0.042433836, 0.043204527, -0.009033531, -0.09083154, -3.1694994E-4, 0.030156016, -0.030984623, -0.031595454, 0.002228252, -0.003698093, -0.006667667, 0.023925511, -0.045642223, -0.0054936595, -0.020487037, -0.011321221, -0.008023139, -0.0022487226, 0.016701572, -0.004573161, -0.0076336027, -0.007048531, -0.03015078, 0.03309948, 0.028124114, 0.014135684, 0.009500284, -0.0033359944, 0.017857917, 0.034960285, 0.005099243, 0.021408139, -0.0065242476, 0.03559723, 0.002711937, -0.028567772, -0.044500142, 0.025019938, 0.020869007, -0.023909464, -0.06710058, -0.04702157, -0.012781483, -0.03416069, 0.009026116, 0.016877936, -0.015858926, 0.0432861, 0.029753765, -0.016831696, -0.04155155, -0.056399744, -0.0632834, -0.030745849, -0.023681961, -0.02031578, -0.006460313, 0.009156013, -0.03944369, -0.05559119, 0.011855634, 0.0043062386, -0.026944742, -0.05057878, -0.033390008, 0.0012567446, 0.00859911, 0.031703074, -0.024424741, 0.011032831, -0.03794956, -0.0058376114, 0.050361525, 0.02664676, 0.035737876, 9.327007E-5, -0.0036208995, -0.07552407, 0.008858675, 0.06525408, -0.03309569, -0.019470563, 0.029411364, -0.023945473, -0.02741788, 0.025530888, -0.004085135, -0.023078475, -0.05026493, -0.047704235, 0.0063968995, 0.05705471, -0.039139755, -0.016409663, -0.050894372, 0.0229268, 0.024625905, -0.020794865, -0.018509613, -0.0286961, 0.02955773, -0.012118265, 0.007289678, -0.017907536, -9.589148E-5, -0.014387568, 0.01077215, -0.0057492387, -0.070152126, 0.011277187, -0.06932382, 0.0064085126, -0.002137664, 0.020172758, 0.018431762, 0.02997658, -0.035457257, -0.027747527, 0.023011072, 0.0044074785, 0.022357704, -0.011456843, -0.014637661, 0.028279554, -0.018716238, 0.03532025, 0.003035383, 0.028103184, -0.026085945, -0.012884989, 0.024874324, 0.0021957066, 0.038837254, -0.013919544, 0.021001196, -0.006413539, 0.03233318, 0.054959916, 0.002057221, -0.008223584, 0.02089053, 0.031112751, 0.06568271, 0.07437756, -0.032314405, 0.0063390816, 0.021723315, 0.009370877, -0.019755581, -0.009407542, 0.008717818, -0.012684821, -0.015996328, 0.019934947, 0.05044348, -0.03040645, -0.0076975147, 0.013472682, -0.04469578, 0.059487574, 0.0077290037, -0.0062347664, 0.017982362, 0.047718633, -0.029480672, -0.049545363, 0.019446652, -0.012957434, 0.021308606, 0.0034625032, 0.016427478, 0.062390056, 0.074961245, -0.0017664412, -0.0374053, 0.006156502, -0.023779914, 0.022087418, -0.0018362328, 0.036417086, -0.031101517, 0.03615886, 0.0011009142, -0.009626947, 0.0020367356, -0.024929306, 0.05029518, 0.01021691, 0.02706921, -0.055606462, 0.050653223, -0.020299971, 0.022907283, -0.0078015765, 0.0013674265, -0.016805433, -0.005469926, -0.010843944, 0.024753453, 0.0036051865, 0.021984477, 0.019608894, 0.056622125, 0.0168941, 5.6558E-5, -0.037705585, 0.010488043, 0.055042468, -0.012437194, 0.017340036, 0.008242167, -0.032131612, 0.046392333, -0.050994188, 0.013369047, -0.031277575, -0.057127792, 0.026656566, 0.012472042, 0.03171042, 0.0155100925, -0.014371186, -0.0074701216, -0.03548123, -0.019203192, 0.020641252, 0.037671227, -0.050689723, 0.012942378, -0.010964106, -0.009750868, -0.032187466, -0.030583298, 0.031428117, -0.030721085, -0.009199497, -0.025520792, -0.016073162, 0.03206433, 0.035993624, 0.005494608, -0.02187293, 0.026701238, -0.013911904, -0.0024700807, -0.013015862, 0.041535176, -0.032522723, 0.0139125, -0.043542273, -0.02516857, 0.0098249065, 0.018275063, 0.0026843066, 0.009207035, -0.0024260108, 0.014267937, 0.04338487, -0.006479658, 0.026931532, -0.013153546, -0.032537226, -0.012409599, 0.03284542, -0.014427827, 9.0851216E-4, 0.034384534, 0.0022898254, 0.013645849, -0.0264273, 0.04843669, -0.037393637, -0.026378367, -0.03421471, 0.023813134, -0.037445217, -0.018552892, 0.006716699, 0.033491645, 0.046465095, -0.024037533, -0.027822671, 0.017161718, -0.0103931315, 0.043290958, -0.04675785, 0.045929935, -0.07786675, -0.033439267, -0.07128675, 0.009419761, -0.0013642106, -0.022022273, -0.019086521, -0.0038238734, -7.658402E-4, -0.0077877254, 0.035752963, -0.031361237, -0.0020773965, 0.021713957], id:1, title:Dashboards in Python: 3 Advanced Examples for Dash Beginners and Everyone Else, claps:726]]
}
}# Retrieve a single entity by ID
# Go to Zilliz Cloud console, and look for the ID of an entity
# Fill the ID in the request body
curl --request POST \
--url "${PUBLIC_ENDPOINT}/v1/vector/get" \
--header "Authorization: Bearer ${TOKEN}" \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data "{
\"collectionName\": \"medium_articles_2020\",
\"id\": 442169042773492589,
\"outputFields\": [\"id\", \"title\"]
}"
# Output
#
# {
# "code": 200,
# "data": [
# {
# "id": 442147653350117440,
# "title": "The Reported Mortality Rate of Coronavirus Is Not Important"
# }
# ]
# }Get multiple entities in a batch by their IDs
- Python
- NodeJS
- Java
- Bash
# Retrieve a set of entities by their IDs
res = client.get(
collection_name=COLLECTION_NAME,
ids=[1, 2, 3]
)
print(res[0])
# Output
#
# [
# {
# "id": 1,
# "title": "Dashboards in Python: 3 Advanced Examples for Dash Beginners and Everyone Else",
# "link": "https://medium.com/swlh/dashboards-in-python-3-advanced-examples-for-dash-beginners-and-everyone-else-b1daf4e2ec0a",
# "reading_time": 14,
# "publication": "The Startup",
# "claps": 726,
# "responses": 3,
# "vector": [
# 0.0039737443,
# 0.003020432,
# -0.0006188639,
# 0.03913546,
# -0.00089768134,
# 0.021238148,
# 0.014454661,
# 0.025742851,
# 0.0022063442,
# -0.051130578,
# -0.0010897011,
# 0.038453076,
# 0.011593861,
# -0.046852026,
# 0.0064208573,
# 0.010120634,
# -0.023668954,
# 0.041229635,
# 0.008146385,
# -0.023367394,
# "(748 more items hidden)"
# ]
# }
# ]async function main () {
// (Continued)
// Get a set of entities by their IDs
res = await client.get({
collection_name: collectionName,
ids: [0, 1, 2],
output_fields: ['id', 'title']
});
console.log(res)
// Output
//
// {
// status: { error_code: 'Success', reason: '', code: 0 },
// data: [
// { id: '0', '$meta': [Object] },
// { id: '1', '$meta': [Object] },
// { id: '2', '$meta': [Object] }
// ]
// }
//
}public class QuickStartDemo
{
public static void main( String[] args )
{
// (Continued)
// List<String> ids = Lists.newArrayList("1");
List<String> ids = Lists.newArrayList("1", "2", "3");
GetIdsParam getParam = GetIdsParam.newBuilder()
.withCollectionName(collectionName)
.withPrimaryIds(ids)
.withOutputFields(Lists.newArrayList("*"))
.build();
R<GetResponse> getRes = client.get(getParam);
if (getRes.getException() != null) {
System.err.println("Failed to get: " + getRes.getException().getMessage());
return;
}
List<RowRecord> getResults = new ArrayList<>();
for (QueryResultsWrapper.RowRecord rowRecord: getRes.getData().getRowRecords()) {
getResults.add(rowRecord);
}
System.out.println(getResults);
// Output:
// [[reading_time:14, publication:The Startup, link:https://medium.com/swlh/dashboards-in-python-3-advanced-examples-for-dash-beginners-and-everyone-else-b1daf4e2ec0a, responses:3, vector:[0.0039737443, 0.003020432, -6.188639E-4, 0.03913546, -8.9768134E-4, 0.021238148, 0.014454661, 0.025742851, 0.0022063442, -0.051130578, -0.0010897011, 0.038453076, 0.011593861, -0.046852026, 0.0064208573, 0.010120634, -0.023668954, 0.041229635, 0.008146385, -0.023367394, -0.029139837, -0.023222756, -0.016318452, -0.076287195, 0.035851076, 0.044926822, 0.0037161126, 0.024241403, -0.024827085, -0.012770665, 0.0018561907, 0.047921725, -0.030281143, -0.031129083, -0.038785066, -0.048101038, 0.008587025, -0.0036647166, -0.013043694, -0.044786748, 0.0015023423, -0.02393749, 0.027479807, 0.03407725, -0.011031249, -0.016997544, -0.11140522, -0.0012403706, -0.0116099715, 0.010803051, -0.042221617, 0.071550176, 0.029078195, 0.02936992, -0.016870253, 0.024187507, -0.0064322287, -0.0018420032, -0.010838795, 0.005448679, 0.042049922, 0.015199081, -0.00612731, 0.04651738, -4.543191E-4, 0.0018536948, -0.021741537, 0.042303678, -0.016282137, 0.031659417, 0.03347323, -0.05687932, -0.04784338, 0.047716856, -0.04012971, -0.024161791, -0.015605036, 0.01364975, 0.023177518, 0.01887649, 0.040253926, 0.021470893, 0.09768697, -0.032784328, 0.03222924, 0.03559948, -0.0028161134, 0.03687029, -0.013814558, -0.009652667, 0.021593641, -0.05943368, 0.026042875, 0.028282177, 0.007687183, 0.020226369, -0.0016281981, -0.008526736, 0.025751492, -0.003104332, -0.0061201006, 0.02595484, -0.021449475, -0.014293144, -0.029449001, 0.0020593074, -0.034804724, -0.022180008, -0.006285631, 0.013707787, -0.037423145, -0.009107584, -0.009432007, 0.010610414, -0.056727782, 0.0233536, -0.0060632285, 0.055170756, 0.015278058, -0.0074357074, 0.038479842, 0.07088861, 0.06036749, 0.015448346, 0.024050185, 0.015041763, 0.022847643, 0.018183885, 0.047313735, 0.026332416, -0.002408156, 0.04366259, 0.0057872427, -0.02127312, -0.020023786, -0.02634593, 0.028322363, 0.020426102, 0.026535949, 0.031108813, -0.03800821, -0.016794013, -0.0022405083, -0.028002623, 0.013555326, -0.020880137, -0.040561143, -0.024379047, -0.058721762, 0.009864129, -0.0060728258, 0.019879017, -0.027474888, 0.004868736, -0.01618118, 0.07627549, -0.009566949, -0.0362882, -0.0013981637, 3.6380984E-4, 0.025276562, 0.061608184, -0.048915602, -0.043986745, -0.0055106534, -0.03694729, 0.0018953384, 0.0063064545, 0.010227479, -0.0068412647, -0.011093203, -0.0093250135, -0.019277632, 0.026233265, 0.009567129, 0.008851426, 0.01565083, 0.02383659, 0.058387164, 0.007578936, -0.039052304, -0.020484922, 0.041768145, -0.038177934, 0.032690376, -0.0088214185, 0.040147487, 0.015718441, -0.026545178, -0.023138655, -0.055501554, -0.06176257, 0.01347796, -0.043426935, 0.09015595, -0.05628449, -0.03414897, 0.077925004, 0.039848283, 0.004569112, -0.021932716, -0.008975595, 0.032322578, 0.0011694044, -0.008094395, 0.013524566, -0.010504273, -0.008891303, -0.047701288, -0.003401436, -0.006817342, -0.0131783355, 0.013252014, -0.02291292, 0.005158376, -0.005217175, -0.009027178, 0.01674159, 0.0062977904, -0.0021274886, 0.1001569, -0.010145763, 0.00398632, 0.016642937, -0.04561657, -0.00593123, 0.068103015, 0.022859594, 0.055262484, -0.07711217, -0.013573, 0.00793467, -0.00206392, -0.055678505, -0.0027695482, -0.008978216, 0.023205645, 0.010584002, 0.036940057, 0.0055925045, -0.03128972, 0.008169264, 0.002143065, 0.0054644635, 0.007751248, -0.049370192, -0.017171964, 0.012460248, -0.039616507, -0.008905116, -0.029277697, 0.0316178, 0.007783805, -0.046197712, -0.02389374, 0.03949501, 0.012882567, -0.050312858, -0.0025155935, 0.05531826, -0.0060943947, 0.040836193, -0.0057800347, 0.0639973, 0.009591699, -0.05218372, -0.03645041, -0.05206777, 0.053644467, 0.071591765, 0.008294372, 0.0028174156, 0.0048404625, 0.013453085, 0.022866488, -0.06087804, 0.023474297, 0.027761765, -0.040729735, -0.009113696, 0.020109607, 0.010756393, 0.066961266, -0.03530044, -0.0013631586, -0.034647003, 0.03281657, -0.055955954, -0.043759737, -0.014830927, -0.0012740378, 0.053068876, 0.0041171, -0.009249764, 0.04119711, -0.0022221678, 0.008220726, 0.011716879, 0.04751782, -0.021161754, -0.0034890848, 0.017168297, 0.018082855, -0.054346565, 0.01130623, -0.014759945, -0.020925378, -0.011718521, -0.5058962, -0.016079627, -0.05195381, -0.065540574, -0.024114326, 0.0045832954, 0.05303542, -0.040304415, -0.001513657, 0.019103762, 0.008554532, 0.053032935, -0.00915671, -0.009092158, -0.009177251, 0.028371146, 0.028055405, -0.008145964, 0.011927662, 0.027140373, -0.04623, -0.026633251, -1.9752477E-4, 0.045192443, 0.02449006, 0.013997616, -0.06873905, 0.027910134, 0.003347047, 0.0013439717, 0.034202795, -0.015585498, -0.055015743, 1.6024683E-4, -0.015891591, -0.021741774, 0.025558911, 0.011084363, 0.014056266, -0.018982887, 0.0016998561, 0.048058353, 0.007829392, 0.0018672302, 0.041273497, -0.039120134, 3.624535E-4, -0.0011298673, -0.006326307, 0.032140832, -0.037109844, -4.1404666E-4, -0.0084530655, 0.0077904286, 0.012144728, -0.03869803, 0.047453202, 0.04121898, -0.032067478, 0.022875102, 0.07410041, -0.024542922, -0.036993448, -0.039777547, 0.0094557, -0.025156112, -0.035101883, -0.048749104, -0.0045563756, -0.006167684, -0.048193872, 0.0017396678, 0.019029584, -0.061944872, 0.050563816, -0.021848006, 0.008817201, 0.010323988, 0.020705162, 0.018577144, -0.048376583, -0.041189134, -0.0047300197, -0.00836772, -0.0052992413, -0.035920832, -0.029942693, 0.028925791, 0.030509083, 0.00738733, 0.124217756, -0.04977689, 0.023752924, 0.027065763, 0.057005685, 0.03732509, 0.069008276, -0.022444589, 0.0035944746, -0.041807327, 0.028195074, -0.011788701, -0.0034672262, -0.014074685, -0.009594197, 0.0018883395, -0.024706602, 0.015436245, 0.054175258, -0.03945695, -0.029252004, -0.006543419, -0.064558335, 0.00635337, 0.014417143, 0.013945442, -0.009091861, 5.249867E-4, 0.010337455, -0.009454559, -0.035721924, -0.022774082, -0.031336624, 0.0416093, -0.038794383, -0.008280955, 0.033273164, 0.013371025, -0.0129316645, -0.012368203, 0.022565264, -0.0012145197, 0.01841233, -0.002506566, 0.02414115, -0.047187645, -0.0046407585, 0.032652196, 0.053410284, -0.0365266, -0.0063986774, 0.023949109, 0.010821287, 0.013743939, 0.04780526, 0.008855356, -0.028712442, 0.010830425, -0.0039607813, 0.022576412, -0.009031381, -0.04623192, 0.0140510835, 0.009459673, -0.0033195931, 0.02447672, 0.025940116, 0.015182389, -0.03030254, -0.042433836, 0.043204527, -0.009033531, -0.09083154, -3.1694994E-4, 0.030156016, -0.030984623, -0.031595454, 0.002228252, -0.003698093, -0.006667667, 0.023925511, -0.045642223, -0.0054936595, -0.020487037, -0.011321221, -0.008023139, -0.0022487226, 0.016701572, -0.004573161, -0.0076336027, -0.007048531, -0.03015078, 0.03309948, 0.028124114, 0.014135684, 0.009500284, -0.0033359944, 0.017857917, 0.034960285, 0.005099243, 0.021408139, -0.0065242476, 0.03559723, 0.002711937, -0.028567772, -0.044500142, 0.025019938, 0.020869007, -0.023909464, -0.06710058, -0.04702157, -0.012781483, -0.03416069, 0.009026116, 0.016877936, -0.015858926, 0.0432861, 0.029753765, -0.016831696, -0.04155155, -0.056399744, -0.0632834, -0.030745849, -0.023681961, -0.02031578, -0.006460313, 0.009156013, -0.03944369, -0.05559119, 0.011855634, 0.0043062386, -0.026944742, -0.05057878, -0.033390008, 0.0012567446, 0.00859911, 0.031703074, -0.024424741, 0.011032831, -0.03794956, -0.0058376114, 0.050361525, 0.02664676, 0.035737876, 9.327007E-5, -0.0036208995, -0.07552407, 0.008858675, 0.06525408, -0.03309569, -0.019470563, 0.029411364, -0.023945473, -0.02741788, 0.025530888, -0.004085135, -0.023078475, -0.05026493, -0.047704235, 0.0063968995, 0.05705471, -0.039139755, -0.016409663, -0.050894372, 0.0229268, 0.024625905, -0.020794865, -0.018509613, -0.0286961, 0.02955773, -0.012118265, 0.007289678, -0.017907536, -9.589148E-5, -0.014387568, 0.01077215, -0.0057492387, -0.070152126, 0.011277187, -0.06932382, 0.0064085126, -0.002137664, 0.020172758, 0.018431762, 0.02997658, -0.035457257, -0.027747527, 0.023011072, 0.0044074785, 0.022357704, -0.011456843, -0.014637661, 0.028279554, -0.018716238, 0.03532025, 0.003035383, 0.028103184, -0.026085945, -0.012884989, 0.024874324, 0.0021957066, 0.038837254, -0.013919544, 0.021001196, -0.006413539, 0.03233318, 0.054959916, 0.002057221, -0.008223584, 0.02089053, 0.031112751, 0.06568271, 0.07437756, -0.032314405, 0.0063390816, 0.021723315, 0.009370877, -0.019755581, -0.009407542, 0.008717818, -0.012684821, -0.015996328, 0.019934947, 0.05044348, -0.03040645, -0.0076975147, 0.013472682, -0.04469578, 0.059487574, 0.0077290037, -0.0062347664, 0.017982362, 0.047718633, -0.029480672, -0.049545363, 0.019446652, -0.012957434, 0.021308606, 0.0034625032, 0.016427478, 0.062390056, 0.074961245, -0.0017664412, -0.0374053, 0.006156502, -0.023779914, 0.022087418, -0.0018362328, 0.036417086, -0.031101517, 0.03615886, 0.0011009142, -0.009626947, 0.0020367356, -0.024929306, 0.05029518, 0.01021691, 0.02706921, -0.055606462, 0.050653223, -0.020299971, 0.022907283, -0.0078015765, 0.0013674265, -0.016805433, -0.005469926, -0.010843944, 0.024753453, 0.0036051865, 0.021984477, 0.019608894, 0.056622125, 0.0168941, 5.6558E-5, -0.037705585, 0.010488043, 0.055042468, -0.012437194, 0.017340036, 0.008242167, -0.032131612, 0.046392333, -0.050994188, 0.013369047, -0.031277575, -0.057127792, 0.026656566, 0.012472042, 0.03171042, 0.0155100925, -0.014371186, -0.0074701216, -0.03548123, -0.019203192, 0.020641252, 0.037671227, -0.050689723, 0.012942378, -0.010964106, -0.009750868, -0.032187466, -0.030583298, 0.031428117, -0.030721085, -0.009199497, -0.025520792, -0.016073162, 0.03206433, 0.035993624, 0.005494608, -0.02187293, 0.026701238, -0.013911904, -0.0024700807, -0.013015862, 0.041535176, -0.032522723, 0.0139125, -0.043542273, -0.02516857, 0.0098249065, 0.018275063, 0.0026843066, 0.009207035, -0.0024260108, 0.014267937, 0.04338487, -0.006479658, 0.026931532, -0.013153546, -0.032537226, -0.012409599, 0.03284542, -0.014427827, 9.0851216E-4, 0.034384534, 0.0022898254, 0.013645849, -0.0264273, 0.04843669, -0.037393637, -0.026378367, -0.03421471, 0.023813134, -0.037445217, -0.018552892, 0.006716699, 0.033491645, 0.046465095, -0.024037533, -0.027822671, 0.017161718, -0.0103931315, 0.043290958, -0.04675785, 0.045929935, -0.07786675, -0.033439267, -0.07128675, 0.009419761, -0.0013642106, -0.022022273, -0.019086521, -0.0038238734, -7.658402E-4, -0.0077877254, 0.035752963, -0.031361237, -0.0020773965, 0.021713957], id:1, title:Dashboards in Python: 3 Advanced Examples for Dash Beginners and Everyone Else, claps:726]]
}
}# Retrieve a set of entities by their IDs
# Go to Zilliz Cloud console, and look for the ID of some entities
# Fill the IDs in the request body
curl --request POST \
--url "${PUBLIC_ENDPOINT}/v1/vector/get" \
--header "Authorization: Bearer ${TOKEN}" \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data "{
\"collectionName\": \"medium_articles_2020\",
\"id\": [442169042773492591, 442169042773492593, 442169042773492595],
\"outputFields\": [\"id\", \"title\"]
}"
# Output
#
# {
# "code": 200,
# "data": [
# {
# "id": 442147653350117570,
# "title": "Dashboards in Python: 3 Advanced Examples for Dash Beginners and Everyone Else"
# },
# {
# "id": 442147653350117570,
# "title": "How Can We Best Switch in Python?"
# },
# {
# "id": 442147653350117570,
# "title": "Maternity leave shouldn’t set women back"
# }
# ]
# }
Delete entities
If entities are outdated or no longer needed, you can delete them from a collection by their IDs. You can delete one or more entities at a time.
Here are some examples of deleting entities.
Delete a single entity by its ID
- Python
- NodeJS
- Java
- Bash
# Delete a single entity
res = client.delete(
collection_name=COLLECTION_NAME,
pks=0
)
print(res)
# Output
#
# [0]async function main () {
// (Continued)
// Delete an entity by its ID
res = await client.delete({
collection_name: collectionName,
ids: [0]
});
console.log(res);
// Output
//
// {
// succ_index: [],
// err_index: [],
// status: { error_code: 'Success', reason: '', code: 0 },
// IDs: {},
// acknowledged: false,
// insert_cnt: '0',
// delete_cnt: '1',
// upsert_cnt: '0',
// timestamp: '445337093833752585'
// }
//
}public class QuickStartDemo
{
public static void main( String[] args )
{
// (Continued)
List<String> ids = Lists.newArrayList("1");
// List<String> ids = Lists.newArrayList("1", "2", "3");
DeleteIdsParam deleteParam = DeleteIdsParam.newBuilder()
.withCollectionName(collectionName)
.withPrimaryIds(ids)
.build();
R<DeleteResponse> deleteRes = client.delete(deleteParam);
if (deleteRes.getException() != null) {
System.err.println("Failed to delete: " + deleteRes.getException().getMessage());
return;
}
System.out.println("Successfully deleted " + deleteRes.getData().toString() + " records");
// Output:
// Successfully deleted DeleteResponse(deleteIds=[]) records }
}# Deletes an entity
# Go to Zilliz Cloud console, and look for the ID of an entity
# Fill the ID in the request body
curl --request POST \
--url "${PUBLIC_ENDPOINT}/v1/vector/delete" \
--header "Authorization: Bearer ${API_KEY}" \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data "{
\"collectionName\": \"medium_articles_2020\",
\"id\": 442169042773492589
}"
# Output
#
# {
# "code": 200,
# "data": {}
# }Delete multiple entities in a batch by their IDs
- Python
- NodeJS
- Java
- Bash
# Delete a set of entities in a batch
res = client.delete(
collection_name=COLLECTION_NAME,
pks=[1, 2, 3]
)
print(res)
# Output
#
# [1, 2, 3]async function main () {
// (Continued)
// Delete a set of entities by their IDs
res = await client.delete({
collection_name: collectionName,
ids: [1, 2, 3]
});
console.log(res);
// Output
//
// {
// succ_index: [],
// err_index: [],
// status: { error_code: 'Success', reason: '', code: 0 },
// IDs: {},
// acknowledged: false,
// insert_cnt: '0',
// delete_cnt: '3',
// upsert_cnt: '0',
// timestamp: '445337093833752590'
// }
//
}public class QuickStartDemo
{
public static void main( String[] args )
{
// (Continued)
// List<String> ids = Lists.newArrayList("1");
List<String> ids = Lists.newArrayList("1", "2", "3");
DeleteIdsParam deleteParam = DeleteIdsParam.newBuilder()
.withCollectionName(collectionName)
.withPrimaryIds(ids)
.build();
R<DeleteResponse> deleteRes = client.delete(deleteParam);
if (deleteRes.getException() != null) {
System.err.println("Failed to delete: " + deleteRes.getException().getMessage());
return;
}
System.out.println("Successfully deleted " + deleteRes.getData().toString() + " records");
// Output:
// Successfully deleted DeleteResponse(deleteIds=[]) records }
}# Delete a set of entities in a batch
# Go to Zilliz Cloud console, and look for the ID of some entities
# Fill the IDs in the request body
curl --request POST \
--url "${PUBLIC_ENDPOINT}/v1/vector/delete" \
--header "Authorization: Bearer ${TOKEN}" \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data "{
\"collectionName\": \"medium_articles_2020\",
\"id\": [442169042773492591, 442169042773492593, 442169042773492595]
}"
# Output
#
# {
# "code": 200,
# "data": {}
# }
Drop a collection
If a collection is no longer used, you can drop it from a cluster by collection name.
- Python
- NodeJS
- Java
- Bash
# Drop a collection
res = client.drop_collection(
collection_name=COLLECTION_NAME
)
print(res)
# Output
#
# None
async function main () {
// (Continued)
// Drop collection
res = await client.dropCollection({
collection_name: collectionName
});
console.log(res);
// Output
//
// { error_code: 'Success', reason: '', code: 0 }
//
}
public class QuickStartDemo
{
public static void main( String[] args )
{
// (Continued)
DropCollectionParam dropCollectionParam = DropCollectionParam.newBuilder()
.withCollectionName(collectionName)
.build();
R<RpcStatus> dropCollection = client.dropCollection(dropCollectionParam);
if (dropCollection.getException() != null) {
System.err.println("Failed to drop collection: " + dropCollection.getException().getMessage());
return;
}
System.out.println("Successfully dropped collection " + collectionName);
// Output:
// Successfully dropped collection medium_articles
}
# Drop a collection
# Replace uri and API key with your own
curl --request POST \
--url "${PUBLIC_ENDPOINT}/v1/vector/collections/drop" \
--header "Authorization: Bearer ${TOKEN}" \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data "{
\"collectionName\": \"medium_articles_2020\"
}"
# Output
#
# {
# "code": 200,
# "data": {}
# }