增加FAISS向量数据库检索存储等功能。

This commit is contained in:
zhanghuan
2025-09-22 10:42:57 +08:00
parent e34ecbd94d
commit be284442e4
10 changed files with 1573 additions and 0 deletions
+20
View File
@@ -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