增加FAISS向量数据库检索存储等功能。
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import faiss
|
||||
import numpy as np
|
||||
|
||||
# 建一个 2 维向量的 L2 索引
|
||||
index = faiss.IndexFlatL2(2)
|
||||
|
||||
print(index.ntotal) # 初始是 0
|
||||
|
||||
# 插入 5 个向量
|
||||
data = np.random.rand(5, 2).astype("float32")
|
||||
index.add(data)
|
||||
|
||||
print(index.ntotal) # 现在是 5
|
||||
|
||||
# 再插入 3 个
|
||||
more_data = np.random.rand(3, 2).astype("float32")
|
||||
index.add(more_data)
|
||||
|
||||
print(index.ntotal) # 现在是 8
|
||||
|
||||
Reference in New Issue
Block a user