vearch-实现以图搜图

环境搭建和启动
sudo docker run -it -p 8817:8817 -p 9001:9001 -p 2378:2378 -p 2390:2390 -p 2370:2370 -p 6062:6062 -p 8818:8818 -p 6061:6061 -p 8081:8081 -p 8898:8898 -p 8899:8899 -p 6060:6060  -v $PWD/config.toml:/vearch/config.toml  ansj/vearch:0.3 all

查看本地镜像

sudo docker images
写入数据

创建database,name后面是库名

curl -XPUT -H "content-type:application/json" -d '{"name": "test123"}' http://127.0.0.1:8817/db/_create

如果成功返回

{"code":200,"msg":"success","data":{"id":1,"name":"test123"}}

再创建一个database

curl -XPUT -H "content-type:application/json" -d '{"name": "db1"}' http://127.0.0.1:8817/db/_create

返回

{"code":200,"msg":"success","data":{"id":3,"name":"db1"}}

查看创建的database

curl -XGET http://127.0.0.1:8817/list/db

返回

{"code":200,"msg":"success","data":[{"id":1,"name":"test123"},{"id":3,"name":"db1"}]}

创建表空间

name是表名
http://127.0.0.1:8817/space/test123/_create ,space后面的是库名

curl -XPUT -H "content-type: application/json" -d' { "name": "test123456", "dynamic_schema": "strict", "partition_num": 1, "replica_num": 1, "engine": {"name":"gamma","metric_type": "InnerProduct"}, "properties": { "url": { "type": "keyword", "index":true}, "feature1": { "type": "vector", "dimension":512, "format": "normalization" }}} ' http://127.0.0.1:8817/space/test123/_create

返回

{"code":200,"msg":"success","data":{"id":5,"name":"test123456","version":2,"db_id":1,"enabled":true,"partitions":[{"id":7,"space_id":5,"db_id":1,"partition_slot":0,"replicas":[180]}],"partition_num":1,"replica_num":1,"properties":{ "url": { "type": "keyword", "index":true}, "feature1": { "type": "vector", "dimension":512, "format": "normalization" }},"engine":{"name":"gamma","index_size":100000,"max_size":100000,"nprobe":-1,"metric_type":"InnerProduct","ncentroids":-1,"nsubvector":-1,"nbits_per_idx":-1}}}

再创建一次不同的

curl -XPUT -H "content-type: application/json" -d' { "name": "test5", "dynamic_schema": "strict", "partition_num": 1, "replica_num": 1, "engine": {"name":"gamma","metric_type": "InnerProduct"}, "properties": { "url": { "type": "keyword", "index":true}, "id": { "type": "keyword" }, "feature": { "type": "vector", "field": "url", "model_id": "vgg16", "dimension":512, "format": "normalization" }}} ' http://127.0.0.1:8817/space/test123/_create

返回

{"code":200,"msg":"success","data":{"id":6,"name":"test5","version":2,"db_id":1,"enabled":true,"partitions":[{"id":8,"space_id":6,"db_id":1,"partition_slot":0,"replicas":[180]}],"partition_num":1,"replica_num":1,"properties":{ "url": { "type": "keyword", "index":true}, "id": { "type": "keyword" }, "feature": { "type": "vector", "field": "url", "model_id": "vgg16", "dimension":512, "format": "normalization" }},"engine":{"name":"gamma","index_size":100000,"max_size":100000,"nprobe":-1,"metric_type":"InnerProduct","ncentroids":-1,"nsubvector":-1,"nbits_per_idx":-1}}}

再一次

curl -XPUT -H "content-type: application/json" -d' { "name": "test7",
"dynamic_schema": "strict", "partition_num": 2, "replica_num": 1, "engine":
{"name":"gamma","index_size":10000,"retrieval_type": "IVFPQ", "retrieval_param": {"metric_type": "InnerProduct","ncentroids": -1,"nsubvector": -1}}, "properties": { "url": { "type": "keyword", "index":true}, "feature1": { "type": "vector", "dimension":512, "model_id":"vgg16", "format": "normalization"}}} ' http://127.0.0.1:4101/space/test123/_create

返回

{"code":200,"msg":"success","data":{"id":7,"name":"test3","version":2,"db_id":1,"enabled":true,"partitions":[{"id":9,"space_id":7,"db_id":1,"partition_slot":0,"replicas":[180]},{"id":10,"space_id":7,"db_id":1,"partition_slot":2147483647,"replicas":[180]}],"partition_num":2,"replica_num":1,"properties":{ "url": { "type": "keyword", "index":true}, "feature1": { "type": "vector", "dimension":512, "format": "normalization"}},"engine":{"name":"gamma","index_size":10000,"max_size":100000,"nprobe":-1,"metric_type":"L2","ncentroids":-1,"nsubvector":-1,"nbits_per_idx":-1}}}

查看表空间
space/test123/test12345: test123是database名字,test12345是表名

curl -XGET http://127.0.0.1:8817/space/test123/test12345

Delete a database and space

curl -XDELETE http://127.0.0.1:4101/space/test/test
curl -XDELETE http://127.0.0.1:4101/db/test

返回

{"code":200,"msg":"success"}

在表空间插入数据
/test123/test12345/1:库名/表名/数据id

curl -XPOST -H "content-type: application/json"   -d ' { "url": "https://pics6.baidu.com/feed/a8014c086e061d95709563b7df22abd960d9ca49.png?token=acbd068e18f8a3bebd9e71817ed72c05", "feature1":{"feature":"https://pics6.baidu.com/feed/a8014c086e061d95709563b7df22abd960d9ca49.png?token=acbd068e18f8a3bebd9e71817ed72c05"}} ' http://127.0.0.1:4101/test123/test12345/1

返回

{"_index":"test123","_type":"test12345","_id":"1","status":201,"_version":1,"_shards":{"total":0,"successful":1,"failed":0},"result":"created","_seq_no":1,"_primary_term":1}
curl -XPOST -H "content-type: application/json"  -d' { "url": "/home/xhz/Desktop/vearch/img/3.jpg", "feature1":{"feature":"/home/xhz/Desktop/vearch/img/3.jpg"}} ' http://127.0.0.1:4101/test123/test3/3

返回

{"_index":"test123","_type":"test3","_id":"3","status":201,"_version":1,"_shards":{"total":0,"successful":1,"failed":0},"result":"created","_seq_no":1,"_primary_term":1}

查询

curl -H "content-type: application/json" -XPOST -d '{ "query": { "sum": [{"feature":"/home/xhz/Desktop/vearch/img/1.jpg", "field":"feature1"}]}}' http://127.0.0.1:4101/test123/test3/_search

返回

{"took":2,"timed_out":false,"_shards":{"total":2,"failed":0,"successful":2},"hits":{"total":3,"max_score":0.6794275045394897,"hits":[{"_index":"test123","_type":"test3","_id":"1","_score":3.6925154503052865e-14,"_extra":{"vector_result":[{"field":"feature1","source":"","score":3.6925154503052865e-14}]},"_version":1,"_source":{"url":"/home/xhz/Desktop/vearch/img/1.jpg"}},{"_index":"test123","_type":"test3","_id":"2","_score":0.006496822461485863,"_extra":{"vector_result":[{"field":"feature1","source":"","score":0.0064968224614858627}]},"_version":1,"_source":{"url":"/home/xhz/Desktop/vearch/img/2.jpg"}},{"_index":"test123","_type":"test3","_id":"3","_score":0.6794275045394897,"_extra":{"vector_result":[{"field":"feature1","source":"","score":0.67942750453948975}]},"_version":1,"_source":{"url":"/home/xhz/Desktop/vearch/img/3.jpg"}}]}}

查询库有多少表空间

curl -XGET http://127.0.0.1:4101/list/space?db=test123

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骨子带刺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值