Skip to content

Commit

Permalink
remove get vector by termfilters codes (#723)
Browse files Browse the repository at this point in the history
* update gpu docs

* remove get vector by termfilters codes
  • Loading branch information
wxingda committed Jul 6, 2023
1 parent ca33e2f commit e9b45ab
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 102 deletions.
112 changes: 58 additions & 54 deletions docs/APILowLevelOnGPU.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Low-level API for vector search on GPU

Most API are same to APILowLevel.md, here only list the different places.
* **search size** and **nprobe** should not larger than 1024(CUDA >= 9.0) or 2048(CUDA >= 9.2).
* **search size** and **nprobe** should not larger than 2048(CUDA >= 9.2).
* Since GPU index does not support real time indexing, index_size should **set 0** to prevent auto indexing. After add documents, you should call `create index` `curl -XPOST {{ROUTER}}/test_vector_db/vector_space/_forcemerge` to build index.

* Search is not supported while add or indexing.
Expand All @@ -18,65 +18,69 @@ You should set `retrieval_type : "GPU"`.
````$xslt
curl -v --user "root:secret" -H "content-type: application/json" -XPUT -d'
{
"name": "vector_space",
"partition_num": 1,
"replica_num": 1,
"engine": {
"index_size": 0,
"retrieval_type": "GPU",
"retrieval_param": {
"metric_type": "L2",
"ncentroids": 1024,
"nsubvector": -1
}
},
"properties": {
"string": {
"type": "keyword",
"index": true
},
"int": {
"type": "integer",
"index": true
},
"float": {
"type": "float",
"index": true
},
"vector": {
"type": "vector",
"model_id": "img",
"dimension": 128,
"format": "normalization"
},
"string_tags": {
"type": "string",
"array": true,
"index": true
},
"int_tags": {
"type": "integer",
"array": true,
"index": true
},
"float_tags": {
"type": "float",
"array": true,
"index": true
}
},
"models": [{
"model_id": "vgg16",
"fields": ["string"],
"out": "feature"
}]
"name": "vector_space",
"partition_num": 1,
"replica_num": 1,
"engine": {
"index_size": 0,
"retrieval_type": "GPU",
"retrieval_param": {
"metric_type": "L2",
"ncentroids": 1024,
"nsubvector": -1
}
},
"properties": {
"string": {
"type": "keyword",
"index": true
},
"int": {
"type": "integer",
"index": true
},
"float": {
"type": "float",
"index": true
},
"vector": {
"type": "vector",
"model_id": "img",
"dimension": 128,
"format": "normalization"
},
"string_tags": {
"type": "string",
"array": true,
"index": true
},
"int_tags": {
"type": "integer",
"array": true,
"index": true
},
"float_tags": {
"type": "float",
"array": true,
"index": true
}
},
"models": [
{
"model_id": "vgg16",
"fields": [
"string"
],
"out": "feature"
}
]
}
' {{MASTER}}/space/test_vector_db/_create
````

* engine
* index_size : **index_size should set 0**
* nprobe : should not larger than 1024(CUDA >= 9.0) or 2048(CUDA >= 9.2), you can set it when at search time
* nprobe : should not larger than 2048(CUDA >= 9.2), you can set it when at search time
* keyword

* Vector field params
57 changes: 9 additions & 48 deletions engine/search/gamma_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,54 +404,15 @@ int GammaEngine::Search(Request &request, Response &response_results) {
response_results.SetEngineInfo(table_, vec_manager_, gamma_results, req_num);
} else {
GammaResult *gamma_result = new GammaResult[1];

std::vector<std::pair<string, int>> fields_ids;
std::vector<string> vec_names;

const auto range_result = range_query_result.GetAllResult();
if (range_result == nullptr && term_filters_num > 0) {
for (size_t i = 0; i < term_filters_num; ++i) {
struct TermFilter &term_filter = term_filters[i];

string value = term_filter.field;

int doc_id = -1;
if (table_->GetDocIDByKey(term_filter.value, doc_id) != 0) {
continue;
}

fields_ids.emplace_back(std::make_pair(value, doc_id));
vec_names.emplace_back(std::move(value));
}
if (fields_ids.size() > 0) {
gamma_result->init(topn, vec_names.data(), fields_ids.size());
std::vector<string> vec;
int ret = vec_manager_->GetVector(fields_ids, vec);
if (ret == 0) {
int idx = 0;
VectorDoc *doc = gamma_result->docs[gamma_result->results_count];
for (const auto &field_id : fields_ids) {
int id = field_id.second;
doc->docid = id;
doc->fields[idx].name = vec[idx];
doc->fields[idx].source = nullptr;
doc->fields[idx].source_len = 0;
++idx;
}
++(gamma_result->results_count);
gamma_result->total = 1;
}
}
} else {
gamma_result->init(topn, nullptr, 0);
for (int docid = 0; docid < max_docid_; ++docid) {
if (range_query_result.Has(docid) && !docids_bitmap_->Test(docid)) {
++(gamma_result->total);
if (gamma_result->results_count < topn) {
gamma_result->docs[(gamma_result->results_count)++]->docid = docid;
} else {
break;
}
gamma_result->init(topn, nullptr, 0);

for (int docid = 0; docid < max_docid_; ++docid) {
if (range_query_result.Has(docid) && !docids_bitmap_->Test(docid)) {
++(gamma_result->total);
if (gamma_result->results_count < topn) {
gamma_result->docs[(gamma_result->results_count)++]->docid = docid;
} else {
break;
}
}
}
Expand Down

0 comments on commit e9b45ab

Please sign in to comment.