Skip to content

Commit

Permalink
Remove overallocation in faiss query path (#501)
Browse files Browse the repository at this point in the history
Removes overallocation of 2 c++ vectors in faiss querying functionality.
Performance results can be viewed in [497](#497 (comment)).
 In general, this change could provide a small improvement in memory
 footprint during search workloads.

Signed-off-by: John Mazanec <jmazane@amazon.com>
(cherry picked from commit 507bafe)
  • Loading branch information
jmazanec15 authored and github-actions[bot] committed Aug 8, 2022
1 parent 53185a0 commit c6e1a8e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions jni/src/faiss_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ jobjectArray knn_jni::faiss_wrapper::QueryIndex(knn_jni::JNIUtilInterface * jniU
throw std::runtime_error("Invalid pointer to index");
}

int dim = jniUtil->GetJavaFloatArrayLength(env, queryVectorJ);
std::vector<float> dis(kJ * dim);
std::vector<faiss::Index::idx_t> ids(kJ * dim);
// The ids vector will hold the top k ids from the search and the dis vector will hold the top k distances from
// the query point
std::vector<float> dis(kJ);
std::vector<faiss::Index::idx_t> ids(kJ);
float* rawQueryvector = jniUtil->GetFloatArrayElements(env, queryVectorJ, nullptr);

try {
Expand Down

0 comments on commit c6e1a8e

Please sign in to comment.