Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new api in webserver and sdk #6

Merged
merged 2 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions core/src/server/web_impl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,8 @@ $ curl -X PUT "http://127.0.0.1:19121/collections/test_collection/vectors" -H "a
<tr><td>Body</td><td><pre><code>
{
"delete": {
"ids": [$string]
"ids": [$string],
"partition_tag": $string
}
}
</code></pre> </td></tr>
Expand All @@ -1193,9 +1194,10 @@ $ curl -X PUT "http://127.0.0.1:19121/collections/test_collection/vectors" -H "a

##### Body Parameters

| Parameter | Description | Required? |
| --------- | --------------- | --------- |
| ids | IDs of vectors. | Yes |
| Parameter | Description | Required? |
| ------------- | -------------------- | --------- |
| ids | IDs of vectors. | Yes |
| partition_tag | partition of vectors | Yes |

##### Query Parameters

Expand Down Expand Up @@ -1292,7 +1294,7 @@ $ curl -X POST "http://127.0.0.1:19121/collections/test_collection/vectors" -H "
}
```

### `/collections/{collection_name}/vectors?ids={vector_id_list}` (GET)
### `/collections/{collection_name}/vectors?ids={vector_id_list}&partition_tag=$string` (GET)

Obtain vectors by ID.

Expand All @@ -1311,6 +1313,7 @@ Obtain vectors by ID.
| ----------------- | ------------------------------------- | --------- |
| `collection_name` | Name of the collection. | Yes |
| `vector_id_list` | Vector id list, separated by commas. | Yes |
| `partition_tag` | Partition tag. | Yes |

#### Response

Expand Down Expand Up @@ -1526,6 +1529,46 @@ $ curl -X PUT "http://127.0.0.1:19121/system/task" -H "accept: application/json"
{ "code": 0, "message": "success" }
```

#### Release a collection from memory

##### Request

<table>
<tr><th>Request Component</th><th>Value</th></tr>
<tr><td> Name</td><td><pre><code>/system/task</code></pre></td></tr>
<tr><td>Header </td><td><pre><code>accept: application/json</code></pre> </td></tr>
<tr><td>Body</td><td><pre><code>
{
"release": {
"collection_name": $string,
"partition_tags": [$string, $string]
}
}
</code></pre> </td></tr>
<tr><td>Method</td><td>PUT</td></tr>
</table>

##### Response

| Status code | Description |
| ----------- | ----------------------------------------------------------------- |
| 200 | The request is successful. |
| 400 | The request is incorrect. Refer to the error message for details. |

##### Example

###### Request

```shell
$ curl -X PUT "http://127.0.0.1:19121/system/task" -H "accept: application/json" -d "{\"release\": {\"collection_name\": \"test_collection\", \"partition_tags\": [\"part_1\", \"part_2\"]}}"
```

###### Response

```json
{ "code": 0, "message": "success" }
```

## Index and search parameters

For each index type, the RESTful API has specific index parameters and search parameters.
Expand Down
16 changes: 12 additions & 4 deletions core/src/server/web_impl/handler/WebRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,12 @@ WebRequestHandler::DeleteByIDs(const std::string& collection_name, const nlohman
vector_ids.emplace_back(std::stol(id_str));
}

auto status = request_handler_.DeleteByID(context_ptr_, collection_name, "", vector_ids);
std::string partition_tag = "";
if (json.contains("partition_tag")) {
partition_tag = json["partition_tag"];
}

auto status = request_handler_.DeleteByID(context_ptr_, collection_name, partition_tag, vector_ids);

nlohmann::json result_json;
AddStatusToJson(result_json, status.code(), status.message());
Expand Down Expand Up @@ -1718,6 +1723,8 @@ WebRequestHandler::GetVector(const OString& collection_name, const OQueryParams&
RETURN_STATUS_DTO(QUERY_PARAM_LOSS, "Query param ids is required.");
}

auto partition_tag = query_params.get("partition_tag")->c_str();

std::vector<std::string> ids;
StringHelpFunctions::SplitStringByDelimeter(query_ids->c_str(), ",", ids);

Expand All @@ -1727,7 +1734,7 @@ WebRequestHandler::GetVector(const OString& collection_name, const OQueryParams&
}
engine::VectorsData vectors;
nlohmann::json vectors_json;
status = GetVectorsByIDs(collection_name->std_str(), "", vector_ids, vectors_json);
status = GetVectorsByIDs(collection_name->std_str(), partition_tag, vector_ids, vectors_json);
if (!status.ok()) {
response = "NULL";
ASSIGN_RETURN_STATUS_DTO(status)
Expand Down Expand Up @@ -1832,9 +1839,10 @@ WebRequestHandler::SystemOp(const OString& op, const OString& body_str, OString&
status = PreLoadCollection(j["load"], result_str);
} else if (j.contains("flush")) {
status = Flush(j["flush"], result_str);
}
if (j.contains("compact")) {
} else if (j.contains("compact")) {
status = Compact(j["compact"], result_str);
} else if (j.contains("release")) {
status = ReleaseCollection(j["release"], result_str);
}
} else if (op->equals("config")) {
status = SetConfig(j, result_str);
Expand Down
6 changes: 3 additions & 3 deletions sdk/examples/simple/src/ClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ ClientTest::GetEntityByID(const std::string& collection_name, const std::vector<
std::vector<milvus::Entity> entities;
{
milvus_sdk::TimeRecorder rc("GetEntityByID");
milvus::Status stat = conn_->GetEntityByID(collection_name, id_array, entities);
milvus::Status stat = conn_->GetEntityByID(collection_name, "", id_array, entities);
std::cout << "GetEntityByID function call status: " << stat.message() << std::endl;
}

Expand Down Expand Up @@ -196,7 +196,7 @@ ClientTest::SearchEntitiesByID(const std::string& collection_name, int64_t topk,
}

std::vector<milvus::Entity> entities;
milvus::Status stat = conn_->GetEntityByID(collection_name, id_array, entities);
milvus::Status stat = conn_->GetEntityByID(collection_name, "", id_array, entities);
std::cout << "GetEntityByID function call status: " << stat.message() << std::endl;

JSON json_params = {{"nprobe", nprobe}};
Expand Down Expand Up @@ -262,7 +262,7 @@ ClientTest::DeleteByIds(const std::string& collection_name, const std::vector<in
}
std::cout << std::endl;

milvus::Status stat = conn_->DeleteEntityByID(collection_name, id_array);
milvus::Status stat = conn_->DeleteEntityByID(collection_name, "", id_array);
std::cout << "DeleteByID function call status: " << stat.message() << std::endl;

Flush(collection_name);
Expand Down
Loading