Skip to content

Commit 40ad041

Browse files
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

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)