We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents d8a709c + 40ad041 commit 048b3eaCopy full SHA for 048b3ea
1 file changed
Vector Databases/faiss_example.py
@@ -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