An experimental vector storage, built for AID Project.
Step 1/2: Install faiss-cpu or faiss-gpu based on your system.
pip install faiss-cpu # or pip install faiss-gpuStep 2/2: Install FaissDB
pip install faissdb
It should suffice on Ubuntu/Debian system.
fromfaissdb.faissdbimportFaissDBfromfaissdb.configimportFaissDBSettingssettings=FaissDBSettings()
db=FaissDB(settings)
# For the first time, create a partition with any namedb.create_partition('voc')
# Create a one-dimensional vectorfeature=np.random.random((4096,))
# Put it in database# here 1.jpg could be any string, that you want to indicate the filedb.put('voc', feature, '1.jpg')
# build the indexdb.create_index('voc')
# Now perform KNN Query# First reshape the feature, such that it becomes (k*d)# where k is the number of vectors you want to consider# In our case, we have a single query vector, hence k=1# d is the dimension of the vectors.feature=feature.reshape((1, 4096))
D, keys=db.knn_query('voc', feature, k=1)
# Since k=1, we always get the vector itself, hence D should only contains 0.print(D)
foreachinkeys:
value=db.getVal('voc', each)
# The value should be 1.jpg, or the string you specified above.print(value)