|
| 1 | +# Quickstart |
| 2 | + |
| 3 | +*This Quickstart suit for those who want to search something but do not know how to extract image or text to features. Others refer to [APILowLevel.md](APILowLevel.md) .* |
| 4 | + |
| 5 | +Vearch is aimed to build a simple and fast image retrieval system. Through this system, a image retrieval system could be easily built, including image object detection, feature extraction and similarity search. This quickstart demonstrates how to use it. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +## Before you begin |
| 12 | + |
| 13 | +1. Deploy Vearch system referred to [Deploy.md](https://github.com/vearch/vearch/blob/master/docs/Deploy.md). |
| 14 | + |
| 15 | + For testing you can download [coco data](https://pjreddie.com/media/files/val2014.zip), or use the images in images folder we choose from [coco data](https://pjreddie.com/media/files/val2014.zip). For more details, you can refer test folder in `plugin.src` |
| 16 | + |
| 17 | +## Different from APILowLevel.md |
| 18 | + |
| 19 | +This API is similar to [APILowLevel.md](https://github.com/vearch/vearch/blob/master/docs/APILowLevel.md), and plugin can perfectly adapt to it, Any method defined in APILowLevel.md can be used by plugin. However, if vector has existed, the APILowLevel.md is the fisrt choice. |
| 20 | + |
| 21 | +The difference: |
| 22 | + |
| 23 | +- The name of db can not be one of ['_cluster', 'list', 'db', 'space']. |
| 24 | +- Can not use `_msearch` method. |
| 25 | +- Replace the feature field with the object requiring the feature, refer to insert or search demo. |
| 26 | + |
| 27 | + |
| 28 | +## Deploy a plugin service |
| 29 | + |
| 30 | +This requires only two operations: |
| 31 | + |
| 32 | +1. Modify parameters in `src/config.py`; |
| 33 | +2. Execution script: |
| 34 | + For image, `bash ./bin/run.sh image` ; |
| 35 | + For video, `bash ./bin/run.sh video`; |
| 36 | + For text, `bash ./bin/run.sh text` ; |
| 37 | + |
| 38 | + |
| 39 | +## Create a database and space |
| 40 | + |
| 41 | +Before inserting and searching, a database and space should be creating firstly. Use the following `curl` command to create a new database and space. |
| 42 | + |
| 43 | +```shell |
| 44 | +# create a db which name test |
| 45 | +curl -XPUT -H "content-type:application/json" -d '{"name": "test"}' http://127.0.0.1:4101/db/_create |
| 46 | + |
| 47 | +# create a space in test db which name test too. |
| 48 | +## for image |
| 49 | +curl -XPUT -H "content-type: application/json" -d '{"name": "test", "partition_num": 1, "replica_num": 1, "engine": {"name": "gamma", "index_size": 70000, "max_size": 10000000, "id_type": "String", "retrieval_type": "IVFPQ", "retrieval_param": { "metric_type": "InnerProduct", "ncentroids": 256, "nsubvector": 32 } }, "properties": { "url": { "type": "keyword", "index": true }, "feature1": { "type": "vector", "dimension":512, "format": "normalization" } }} }' http://127.0.0.1:4101/space/test/_create |
| 50 | + |
| 51 | +## for text dimension is 768 |
| 52 | +curl -XPUT -H "content-type: application/json" -d '{"name": "test", "partition_num": 1, "replica_num": 1, "engine": {"name": "gamma", "index_size": 70000, "max_size": 10000000, "id_type": "String", "retrieval_type": "IVFPQ", "retrieval_param": { "metric_type": "InnerProduct", "ncentroids": 256, "nsubvector": 32 } }, "properties": { "text": { "type": "keyword", "index": true }, "feature1": { "type": "vector", "dimension":768, "format": "normalization" } }} }' http://127.0.0.1:4101/space/test/_create |
| 53 | +``` |
| 54 | + |
| 55 | +A successful response looks like this: |
| 56 | + |
| 57 | +```shell |
| 58 | +# create db |
| 59 | +{"code":200,"msg":"success","data":{"id":1,"name":"test"}} |
| 60 | + |
| 61 | +# create space |
| 62 | +{"code":200,"msg":"success","data":{"id":2,"name":"test","version":2,"db_id":1,"enabled":true,"partitions":[{"id":3,"space_id":2,"db_id":1,"partition_slot":0,"replicas":[1]},{"id":4,"space_id":2,"db_id":1,"partition_slot":2147483647,"replicas":[1]}],"partition_num":2,"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}}} |
| 63 | +``` |
| 64 | +
|
| 65 | +
|
| 66 | +
|
| 67 | +## Delete a database and space |
| 68 | +
|
| 69 | +If the database and space is not need again, Use the following `curl` command to delete a database and space. |
| 70 | +
|
| 71 | +```shell |
| 72 | + |
| 73 | +curl -XDELETE http://127.0.0.1:4101/space/test/test |
| 74 | +curl -XDELETE http://127.0.0.1:4101/db/test |
| 75 | +``` |
| 76 | +
|
| 77 | +A successful response looks like this: |
| 78 | +
|
| 79 | +```shell |
| 80 | +{"code":200,"msg":"success"} |
| 81 | +``` |
| 82 | +
|
| 83 | +
|
| 84 | +
|
| 85 | +## Insert data into space |
| 86 | +
|
| 87 | +Use the following `curl` command to insert single data into space. |
| 88 | +
|
| 89 | +The method of single import demo: |
| 90 | +
|
| 91 | +```shell |
| 92 | +# single insert |
| 93 | + |
| 94 | +## image |
| 95 | +curl -XPOST -H "content-type: application/json" -d' { "url": "../images/COCO_val2014_000000123599.jpg", "feature1":{"feature":"../images/COCO_val2014_000000123599.jpg"}} ' http://127.0.0.1:4101/test/test/AW63W9I4JG6WicwQX_RC |
| 96 | + |
| 97 | +## text |
| 98 | +curl -XPOST -H "content-type: application/json" -d' { "text": "感谢大家", "feature1":{"feature":"感谢大家"} } ' http://127.0.0.1:4101/test/test/AW63W9I4JG6WicwQX_RC' |
| 99 | +``` |
| 100 | +
|
| 101 | +A successful response like this: |
| 102 | +
|
| 103 | +```shell |
| 104 | +{"_index":"test","_type":"test","_id":"AW63W9I4JG6WicwQX_RC","status":201,"_version":1,"_shards":{"total":0,"successful":1,"failed":0},"result":"created","_seq_no":1,"_primary_term":1} |
| 105 | +``` |
| 106 | +
|
| 107 | +## Get record by ID |
| 108 | +
|
| 109 | +Use the following `curl` command to get a record by ID |
| 110 | +
|
| 111 | +```shell |
| 112 | +# request |
| 113 | +curl -XGET http://127.0.0.1:4101/test/test/AW63W9I4JG6WicwQX_RC |
| 114 | +
|
| 115 | +# response |
| 116 | +{"_index":"test","_type":"test","_id":"AW63W9I4JG6WicwQX_RC","found":true,"_version":1,"_source":{"url":"../images/COCO_val2014_000000123599.jpg"}} |
| 117 | +``` |
| 118 | +
|
| 119 | +
|
| 120 | +
|
| 121 | +## Delete record by ID |
| 122 | +
|
| 123 | +Use the following `curl` command to delete a record by ID |
| 124 | +
|
| 125 | +```shell |
| 126 | +# request |
| 127 | +curl -XDELETE http://127.0.0.1:4101/test/test/AWz2IFBSJG6WicwQVTog |
| 128 | +
|
| 129 | +# response |
| 130 | +{"_index":"test","_type":"test","_id":"AW63W9I4JG6WicwQX_RC","status":200,"_version":0,"_shards":{"total":0,"successful":1,"failed":0},"result":"unknow","_seq_no":1,"_primary_term":1} |
| 131 | +``` |
| 132 | +
|
| 133 | +
|
| 134 | +
|
| 135 | +
|
| 136 | +## Search similar result from space |
| 137 | +
|
| 138 | +Searching by an image URI for an publicly accessible online image or an image stored in images folders. |
| 139 | +
|
| 140 | +Searching by an image stored in images folders or image URI on Internet, using the following `curl` command to search similar result from space |
| 141 | +
|
| 142 | +```shell |
| 143 | +curl -H "content-type: application/json" -XPOST -d '{ "query": { "sum": [{"feature":"../images/COCO_val2014_000000123599.jpg", "field":"feature1"}]}}' http://127.0.0.1:4101/test/test/_search |
| 144 | +
|
| 145 | +``` |
| 146 | +
|
| 147 | +A successful response looks like this: |
| 148 | +
|
| 149 | +```shell |
| 150 | +{"took":14,"timed_out":false,"_shards":{"total":2,"failed":0,"successful":2},"hits":{"total":1,"max_score":0.9999997615814209,"hits":[{"_index":"test","_type":"test","_id":"AW8OftTLJG6WicwQyAt2","_score":0.9999997615814209,"_extra":{"vector_result":[{"field":"feature1","source":"","score":0.9999997615814209}]},"_version":1,"_source":{"url":"../images/COCO_val2014_000000123599.jpg"}}]}} |
| 151 | +``` |
| 152 | +
|
| 153 | +search result look like this |
| 154 | +
|
| 155 | + |
| 156 | +
|
| 157 | + |
| 158 | +
|
| 159 | +
|
1 | 160 | # Docker |
2 | 161 |
|
3 | 162 | * build: `docker build . -t vearch/plugin:latest` |
|
0 commit comments