Skip to content

Commit a9123e2

Browse files
junjieqifacebook-github-bot
authored andcommitted
Support cosine distance for training vectors (#4227)
Summary: same as title Differential Revision: D70724590
1 parent c109174 commit a9123e2

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

benchs/bench_fw/descriptors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class DatasetDescriptor:
106106
# desc_name
107107
desc_name: Optional[str] = None
108108

109+
normalize_L2: bool = False
110+
109111
def __hash__(self):
110112
return hash(self.get_filename())
111113

benchs/bench_fw/index.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,8 @@ def assemble(self, dry_run):
11381138
return None, None, ""
11391139
logger.info(f"assemble, train {self.factory}")
11401140
xt = self.io.get_dataset(self.training_vectors)
1141+
if self.training_vectors.normalize_L2:
1142+
faiss.normalize_L2(xt)
11411143
_, t, _ = timer("train", lambda: codec.train(xt), once=True)
11421144
t_aggregate += t
11431145

0 commit comments

Comments
 (0)