Doc Opeartion

http://${VEARCH_URL} represents the vearch service, $db_name is the created library name, $space_name is the created space name, and $id is the unique id of the data record.

_id is the unique identifier of the record generated by the server, which can be specified by the user. This unique identifier needs to be used to modify and delete data.

$id is a unique identifier generated by the server using the specified value when inserting data. The $id value cannot use special characters such as URL paths. If the record with the unique identifier already exists in the library, it will be updated and overwritten.

document/upsert

If primary_id is set, the specified primary key will be used. If not set, generated by Vearch.

If the _id specified when inserting already exists, the existing data is updated; otherwise, it is inserted.

When the documents in the inserted data contain multiple pieces of data, it is a batch insertion. It is generally recommended that the number of batch insertions does not exceed 100 pieces.

Insertion and update now support passing in the values of only some fields. When inserting and only passing in some fields, the vector field must be included. There is no such restriction when updating.

Do not specify unique identification id when inserting

  1. curl -H "content-type: application/json" -XPOST -d'
  2. {
  3. "db_name": "ts_db",
  4. "space_name": "ts_space",
  5. "documents": [{
  6. "field_int": 90399,
  7. "field_float": 90399,
  8. "field_double": 90399,
  9. "field_string": "111399",
  10. "field_vector": [...]
  11. }, {
  12. "field_int": 45085,
  13. "field_float": 45085,
  14. "field_double": 45085,
  15. "field_string": "106085",
  16. "field_vector": [...]
  17. }, {
  18. "field_int": 52968,
  19. "field_float": 52968,
  20. "field_double": 52968,
  21. "field_string": "113968",
  22. "field_vector": [...]
  23. }]
  24. }
  25. ' http://${VEARCH_URL}/document/upsert

field_vector is vector field. All field names, value types, and table structures are consistent

Specify unique identifier when inserting

  1. curl -H "content-type: application/json" -XPOST -d'
  2. {
  3. "db_name": "ts_db",
  4. "space_name": "ts_space",
  5. "documents": [{
  6. "_id": "1000000",
  7. "field_int": 90399,
  8. "field_float": 90399,
  9. "field_double": 90399,
  10. "field_string": "111399",
  11. "field_vector": [...]
  12. }, {
  13. "_id": "1000001",
  14. "field_int": 45085,
  15. "field_float": 45085,
  16. "field_double": 45085,
  17. "field_string": "106085",
  18. "field_vector": [...]
  19. }, {
  20. "_id": "1000002",
  21. "field_int": 52968,
  22. "field_float": 52968,
  23. "field_double": 52968,
  24. "field_string": "113968",
  25. "field_vector": [...]
  26. }]
  27. }
  28. ' http://${VEARCH_URL}/document/upsert

The format of the return value of the upsert interface is as follows

  1. {
  2. "code": 0,
  3. "msg": "success",
  4. "data": {
  5. "total": 3,
  6. "document_ids": [
  7. {
  8. "_id": "-526059949411103803"
  9. },
  10. {
  11. "_id": "1287805132970120733"
  12. },
  13. {
  14. "_id": "-1948185285365684656"
  15. }
  16. ]
  17. }
  18. }

total identifies the number of successful insertions, and document_ids returns the generated _id and insertion result information.

document/query

The /document/query interface is used to accurately search for data that exactly matches the query conditions. The search does not include vector data.

Two methods are supported: one is to obtain documents directly through primary keys, and the other is to obtain corresponding documents based on filter conditions.

If partition_id is set, get the corresponding document on the specified data partition. At this time, the meaning of document_id is the document number on the partition. document_id can be [0, max_docid] of the specified partition, and max_docid and partition information can be obtained through the http://master_server/dbs/$db_name/spaces/$space_name interface. Complete data for the cluster can be obtained this way.

query Parameter Description:

field name

field type

must

remarks

document_ids

string array

Query conditions, filter and document_ids must contain one item

partition_id

int

Specify which partition to obtain data from, used in combination with document_ids

filters

json

Query condition filtering: numerical filtering + label filtering, filter and document_ids must contain one item

fields

string array

Specify which fields to return. By default, all fields except vector fields are returned.

vector_value

bool

Defaults to false, whether to return a vector

limit

int

Specify the number of returned results, the default is 50

  • filters json format description:
  1. "filters": [
  2. "operator": "AND",
  3. "conditions": [
  4. {
  5. "field": "field_int",
  6. "operator": ">=",
  7. "value": 1
  8. },
  9. {
  10. "field": "field_int",
  11. "operator": "<=",
  12. "value": 3
  13. },
  14. {
  15. "field": "field_string",
  16. "operator": "IN",
  17. "value": ["aaa", "bbb"]
  18. }
  19. ]
  20. ]

filters format description:

field name

field type

must

remarks

operator

string

true

only support AND now

conditions

json array

true

  1. Filter conditions support multiple conditions, and there is an intersection relationship between multiple conditions, that is, the outermost operator currently supports AND.

conditions format description:

field name

field type

must

remarks

field

string

true

operator

string

true

support >, >=, <, <=, IN

value

json

true

(2) conditions specific filtering conditions, currently supports two types of field type filtering, numeric type and string type (including string array type) Numeric type operators: >, >=, <, <=; String operator type IN

Find data based on unique id identifier

  1. curl -H "content-type: application/json" -XPOST -d'
  2. {
  3. "db_name": "ts_db",
  4. "space_name": "ts_space",
  5. "document_ids": ["6560995651113580768", "-5621139761924822824", "-104688682735192253"]
  6. "vector_value": true
  7. }
  8. ' http://${VEARCH_URL}/document/query

Get the corresponding document on the specified data partition. At this time, document_id can be [0, max_docid] of the specified partition.

  1. curl -H "content-type: application/json" -XPOST -d'
  2. {
  3. "db_name": "ts_db",
  4. "space_name": "ts_space",
  5. "document_ids": ["0", "1", "2"],
  6. "partition_id": 1,
  7. "vector_value": true
  8. }
  9. ' http://${VEARCH_URL}/document/query

Find based on Filter expression of custom scalar field

  1. curl -H "content-type: application/json" -XPOST -d'
  2. {
  3. "db_name": "ts_db",
  4. "space_name": "ts_space",
  5. "filters": {
  6. "operator": "AND",
  7. "conditions": [
  8. {
  9. "field": "field_int",
  10. "operator": ">=",
  11. "value": 1
  12. },
  13. {
  14. "field": "field_int",
  15. "operator": "<=",
  16. "value": 3
  17. }
  18. ]
  19. }
  20. }
  21. ' http://${VEARCH_URL}/document/query

Query interface return format

  1. {
  2. "code": 0,
  3. "msg": "success",
  4. "data": {
  5. "total": 3,
  6. "documents": [{
  7. "_id": "6560995651113580768",
  8. "field_double": 202558,
  9. "field_float": 102558,
  10. "field_int": 1558,
  11. "field_string": "1558"
  12. }, {
  13. "_id": "-5621139761924822824",
  14. "field_double": 210887,
  15. "field_float": 110887,
  16. "field_int": 89887,
  17. "field_string": "89887"
  18. }, {
  19. "_id": "-104688682735192253",
  20. "field_double": 207588,
  21. "field_float": 107588,
  22. "field_int": 46588,
  23. "field_string": "46588"
  24. }]
  25. }
  26. }

Supports similarity retrieval based on vector value, together with the Filter expression of a custom scalar field, and returns the specified Top K most similar Documents.

Parameter Description:

field name

field type

must

remarks

vectors

json array

true

embedding value

filters

json array

false

query criteria filtering: numeric filtering + label filtering

fields

json array

false

Specify which fields to return. By default, only the unique id and score are returned.

is_brute_search

int

false

default 0

vector_value

bool

false

default false

load_balance

string

false

Load balancing algorithm, random by default

limit

int

false

Specify the number of returned results, the default is 50

ranker

json

false

For further processing of multi-vector results, currently only WeightedRanker is supported, which specifies the weight of similarity.

index_params

json

false

Specify parameters for model calculation

The overall json structure of the query parameters is as follows:

  1. {
  2. "vectors": [],
  3. "filters": [],
  4. "index_params": {"nprobe": 20},
  5. "fields": ["field1", "field2"],
  6. "is_brute_search": 0,
  7. "vector_value": false,
  8. "load_balance": "leader",
  9. "limit": 10,
  10. "ranker": {
  11. "type": "WeightedRanker",
  12. "params": [0.5, 0.5]
  13. }
  14. }

The index_params parameter specifies the parameters for model calculation. Different models support different parameters, as shown in the following example:

  • metric_type: calculation type, supports InnerProduct and L2, the default is L2.

  • nprobe: Search bucket number.

  • recall_num: The number of recalls, the default is equal to the value of size in the query parameter, set the number to search from the index, and then calculate the size closest values.

  • parallel_on_queries: Default 1, parallelism between searches; 0 represents parallelism between buckets.

  • efSearch: distance of graph traversal.

IVFPQ:

  1. "index_params": {
  2. "parallel_on_queries": 1,
  3. "recall_num" : 100,
  4. "nprobe": 80,
  5. "metric_type": "L2"
  6. }
  7. When recall_num is set, the original vector will be used for calculation rearrangement (fine sorting)

GPU:

  1. "index_params": {
  2. "recall_num" : 100,
  3. "nprobe": 80,
  4. "metric_type": "L2"
  5. }

HNSW:

  1. "index_params": {
  2. "efSearch": 64,
  3. "metric_type": "L2"
  4. }

IVFFLAT:

  1. "index_params": {
  2. "parallel_on_queries": 1,
  3. "nprobe": 80,
  4. "metric_type": "L2"
  5. }

FLAT:

  1. "index_params": {
  2. "metric_type": "L2"
  3. }
  • vectors json structure elucidation:
  1. "vectors": [{
  2. "field": "field_name",
  3. "feature": [0.1, 0.2, 0.3, 0.4, 0.5],
  4. "min_score": 0.9
  5. }]
  1. vectors: Support multiple (including multiple feature fields when defining table structure correspondingly).

  2. field: Specifies the name of the feature field when the table is created.

  3. feature: Transfer feature, dimension must be the same when defining table structure

  4. min_score: Specify the minimum score of the returned result, min_score can specify the minimum score of the returned result, and max_score can specify the maximum score. For example, set “min_score”: 0.8, “max_score”: 0.95 to filter the result of 0.8 <= score <= 0.95. At the same time, another way of score filtering is to use the combination of “symbol”: “>=”, “value”: 0.9. The value types supported by symbol include: >, >=, < and <= four kinds, and the values of value.

  • filter json structure elucidation:

Refer to the description of filter json in the query interface section.

  • is_brute_search: Specify the query type. 0 means to use index if the feature has been created, and violent search if it has not been created; - 1 means to use index only for search, and 1 means not to use index only for violent search. The default value is 0.

  • vector_value: In order to reduce the network overhead, the search results contain only scalar information fields without feature data by default, and set to true to specify that the returned results contain the original feature data.

  • limit: Specifies the maximum number of results to return. use the limit value specified in the URL first.

  • load_balance: leader, random, no_leader, least_connection, default random。

Search based on vector Supports single or multiple queries. Multiple queries can splice the features of multiple queries into a feature array (such as defining 128-dimensional features and querying 10 in batches. Then 10 128-dimensional features are spliced into a 1280-dimensional feature array in order and assigned to the feature field), After receiving the request, the background splits it according to the characteristic field dimensions defined by the table structure, and returns the matching results in order.

  1. curl -H "content-type: application/json" -XPOST -d'
  2. {
  3. "vectors": [
  4. {
  5. "field": "field_vector",
  6. "feature": [
  7. "..."
  8. ]
  9. }
  10. ],
  11. "filters": {
  12. "operator": "AND",
  13. "conditions": [
  14. {
  15. "field": "field_int",
  16. "operator": ">=",
  17. "value": 1
  18. },
  19. {
  20. "field": "field_int",
  21. "operator": "<=",
  22. "value": 3
  23. },
  24. {
  25. "field": "field_string",
  26. "operator": "IN",
  27. "value": [
  28. "aaa",
  29. "bbb"
  30. ]
  31. }
  32. ]
  33. },
  34. "index_params": {
  35. "metric_type": "L2"
  36. },
  37. "limit": 3,
  38. "db_name": "ts_db",
  39. "space_name": "ts_space"
  40. }
  41. ' http://${VEARCH_URL}/document/search

multi-vector search The table space supports multiple feature fields when defined, so the query can support the features of the corresponding data.

Take two vectors for each record as an example: define table structure fields

  1. {
  2. "field_vector1": {
  3. "type": "vector",
  4. "dimension": 128
  5. },
  6. "field_vector2": {
  7. "type": "vector",
  8. "dimension": 256
  9. }
  10. }

field1 and field2 are both vector fields. When querying, the search conditions can specify two vectors:

  1. {
  2. "vectors": [{
  3. "field": "field_vector1",
  4. "feature": [...]
  5. },
  6. {
  7. "field": "field_vector2",
  8. "feature": [...]
  9. }],
  10. "ranker": {
  11. "type": "WeightedRanker",
  12. "params": [0.5, 0.5]
  13. }
  14. }

The intersection of field1 and field2 filtering results is obtained. Other parameters and request addresses are the same as ordinary queries.

search interface return format

  1. {
  2. "code": 0,
  3. "msg": "success",
  4. "data": {
  5. "documents": [
  6. [{
  7. "_id": "6979025510302030694",
  8. "_score": 16.55717658996582,
  9. "field_double": 207598,
  10. "field_float": 107598,
  11. "field_int": 6598,
  12. "field_string": "6598"
  13. }, {
  14. "_id": "-104688682735192253",
  15. "_score": 17.663991928100586,
  16. "field_double": 207588,
  17. "field_float": 107588,
  18. "field_int": 46588,
  19. "field_string": "46588"
  20. }, {
  21. "_id": "8549822044854277588",
  22. "_score": 17.88829803466797,
  23. "field_double": 220413,
  24. "field_float": 120413,
  25. "field_int": 99413,
  26. "field_string": "99413"
  27. }]
  28. ]
  29. }
  30. }

document/delete

Deletion supports two methods: specifying document_ids and filtering conditions.

Delete specified document_ids

  1. curl -H "content-type: application/json" -XPOST -d'
  2. {
  3. "db_name": "ts_db",
  4. "space_name": "ts_space",
  5. "document_ids": ["4501743250723073467", "616335952940335471", "-2422965400649882823"]
  6. }
  7. ' http://${VEARCH_URL}/document/delete

Delete documents that meet the filter conditions. size specifies the number of items to delete for each data fragment.

  1. curl -H "content-type: application/json" -XPOST -d'
  2. {
  3. "db_name": "ts_db",
  4. "space_name": "ts_space",
  5. "filters": {
  6. "operator": "AND",
  7. "conditions": [
  8. {
  9. "field": "field_int",
  10. "operator": ">=",
  11. "value": 1
  12. },
  13. {
  14. "field": "field_int",
  15. "operator": "<=",
  16. "value": 3
  17. }
  18. ]
  19. },
  20. "limit": 3
  21. }
  22. ' http://${VEARCH_URL}/document/delete

Delete interface return format

  1. {
  2. "code": 0,
  3. "msg": "success",
  4. "data": {
  5. "total": 3,
  6. "document_ids": ["4501743250723073467", "616335952940335471", "-2422965400649882823"]
  7. }
  8. }