From de948ae04c3879b56949d0525d27da010e5ae9e8 Mon Sep 17 00:00:00 2001 From: "xj.lin" Date: Fri, 22 Mar 2019 11:07:51 +0800 Subject: [PATCH] update faiss_wrapper --- .../engine/faiss_wrapper/faiss_wrapper.py | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/pyengine/engine/faiss_wrapper/faiss_wrapper.py b/pyengine/engine/faiss_wrapper/faiss_wrapper.py index 6a60e53d..576f22fa 100644 --- a/pyengine/engine/faiss_wrapper/faiss_wrapper.py +++ b/pyengine/engine/faiss_wrapper/faiss_wrapper.py @@ -2,27 +2,32 @@ import faiss import numpy as np class FaissSearch(): - def __init__(self, index, id_to_vector_map): - pass + def __init__(self, index, id_to_vector_map=None): + self.__index = index + if id_to_vector_map is None: + self.__id_to_vector_map = [] # def search_by_ids(self, id_list, k): # pass def search_by_vectors(self, vector_list, k): - # return both id and vector - pass - - def __search__(self, id_list, vector_list, k): - pass - - -class FaissIndex(): - def build_index(self, vector_list, dimension): - # return index - pass - - # def build_index_cpu(self): - # pass - - # def build_index_gpu(self): - # pass \ No newline at end of file + id_list = [None] * len(vector_list) + + result = self.__search(id_list, vector_list, k) + return result + + def __search(self, id_list, vector_list, k): + D, I = self.__index.search(vector_list, k) + return I + + +# class FaissIndex(): +# def build_index(self, vector_list, dimension): +# # return index +# pass +# +# def build_index_cpu(self): +# pass +# +# def build_index_gpu(self): +# pass \ No newline at end of file -- GitLab