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

Documentation/Instructions on L1 metric #3458

Open
ZeyuSun opened this issue May 18, 2024 · 1 comment
Open

Documentation/Instructions on L1 metric #3458

ZeyuSun opened this issue May 18, 2024 · 1 comment

Comments

@ZeyuSun
Copy link

ZeyuSun commented May 18, 2024

I am using Python and I haven't been able to figure out how to use L1 metric to search. The closest document I found is introducing MetricType. Would anyone point me to the documentation on how to change to other metrics?

@mlomeli1
Copy link
Contributor

hi @ZeyuSun , thank you for flagging I think we should add this to the wiki, so I am marking this issue as documentation. I have created a toy example as well for your reference:

import faiss
import numpy as np

dimension = 128
n = 10000
db_vectors = np.random.random((n, dimension)).astype("float32")
k = 3
dimension = 128
query_vectors = np.random.random((n, dimension)).astype("float32")
code_size = 64
index_pq = faiss.index_factory(dimension, f"PQ{code_size}",faiss.METRIC_L1)
index_pq.train(db_vectors)
index_pq.add(db_vectors)
distances_pq, indices_pq = index_pq.search(query_vectors, k)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants