Skip to content

Commit 048b3ea

Browse files
authored
Merge pull request #23 from ewdlop/ewdlop-patch-19
Create faiss_example.py
2 parents d8a709c + 40ad041 commit 048b3ea

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Vector Databases/faiss_example.py

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

0 commit comments

Comments
 (0)