Commit 40ad041
authored
Create faiss_example.py
```python
import faiss
import numpy as np
# Create a random set of vectors
d = 128 # dimension
nb = 10000 # database size
nq = 100 # number of queries
xb = np.random.random((nb, d)).astype('float32')
xq = np.random.random((nq, d)).astype('float32')
# Build the index
index = faiss.IndexFlatL2(d)
index.add(xb)
# Query the index
D, I = index.search(xq, k=5) # search for the 5 nearest neighbors
# Print the results
print(I)
print(D)
```1 parent d8a709c commit 40ad041
1 file changed
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
0 commit comments