Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I added an arg so that you can specify the number of segments the index vectors will be quantized to #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions colbert/indexing/faiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def load_sample(samples_paths, sample_fraction=None):
return sample


def prepare_faiss_index(slice_samples_paths, partitions, sample_fraction=None):
def prepare_faiss_index(slice_samples_paths, partitions, m=16, sample_fraction=None):
training_sample = load_sample(slice_samples_paths, sample_fraction=sample_fraction)

dim = training_sample.shape[-1]
index = FaissIndex(dim, partitions)
index = FaissIndex(dim, partitions, m)

print_message("#> Training with the vectors...")

Expand Down Expand Up @@ -84,7 +84,7 @@ def index_faiss(args):

assert not os.path.exists(output_path), output_path

index = prepare_faiss_index(slice_samples_paths, args.partitions, args.sample)
index = prepare_faiss_index(slice_samples_paths, args.partitions, args.m, args.sample)

loaded_parts = queue.Queue(maxsize=1)

Expand Down
5 changes: 3 additions & 2 deletions colbert/indexing/faiss_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@


class FaissIndex():
def __init__(self, dim, partitions):
def __init__(self, dim, partitions, m=16):
self.dim = dim
self.partitions = partitions
self.m = m

self.gpu = FaissIndexGPU()
self.quantizer, self.index = self._create_index()
self.offset = 0

def _create_index(self):
quantizer = faiss.IndexFlatL2(self.dim) # faiss.IndexHNSWFlat(dim, 32)
index = faiss.IndexIVFPQ(quantizer, self.dim, self.partitions, 16, 8)
index = faiss.IndexIVFPQ(quantizer, self.dim, self.partitions, self.m, 8)

return quantizer, index

Expand Down
1 change: 1 addition & 0 deletions colbert/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def add_index_use_input(self):
self.add_argument('--index_root', dest='index_root', required=True)
self.add_argument('--index_name', dest='index_name', required=True)
self.add_argument('--partitions', dest='partitions', default=None, type=int)
self.add_argument('--m', dest='m', default=16, type=int)

def add_retrieval_input(self):
self.add_index_use_input()
Expand Down