Skip to content

Repository files navigation

FaissDB

An experimental vector storage, built for AID Project.

Installation

  • Step 1/2: Install faiss-cpu or faiss-gpu based on your system.

    pip install faiss-cpu
    # or
    pip install faiss-gpu
  • Step 2/2: Install FaissDB

    pip install faissdb
    

It should suffice on Ubuntu/Debian system.

Usage

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)

About

A simple vector database in Python, for prototyping

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages