类功能
功能描述
提供向量数据库。
函数原型
from mx_rag.storage.vectorstore import MindFAISS MindFAISS(x_dim, devs, load_local_index, index_type, metric_type, auto_save)
输入参数说明
参数名  | 
数据类型  | 
可选/必选  | 
说明  | 
|---|---|---|---|
x_dim  | 
int  | 
必选  | 
向量维度,取值范围为大于0,小于等于1024 * 1024。  | 
devs  | 
List[int]  | 
必选  | 
设备列表,当前仅支持设置一个设备。  | 
load_local_index  | 
str  | 
必选  | 
本地索引路径,路径长度不能超过1024,文件名长度不能超过255,不能为软链接且不允许存在".."路径不能在路径列表中: ["/etc", "/usr/bin", "/usr/lib", "/usr/lib64", "/sys/", "/dev/", "/sbin"]。  | 
index_type  | 
str  | 
可选  | 
向量检索类型,当前只支持FLAT,默认为FLAT  | 
metric_type  | 
str  | 
可选  | 
向量距离计算方式,支持IP,L2,COSINE,默认为L2  | 
auto_save  | 
bool  | 
可选  | 
是否自动保存索引,取值为“True”或“False”,默认为“True”。  | 
 若“auto_save”设置为“False”,则MindFAISS不会自动保存向量到离线知识库,需要手动调用save_local()来保存向量数据库到离线知识库,否则程序退出后未保存的向量将丢失,有可能导致关系数据库和向量数据库的数据不一致,从而造成程序运行失败的问题。
调用示例
from mx_rag.storage.vectorstore import MindFAISS
import numpy as np
vector_store = MindFAISS.create(x_dim=1024,  devs=[0],
                                        load_local_index='/path/to/index')
vecs = np.random.randn(3, 1024)
vector_store.add([0, 1, 2], vecs)
vector_store.get_ntotal()
vector_store.get_all_ids()
vector_store.delete([1])
vector_store.get_all_ids()
vector_store.search(vecs[1:2, :].tolist())
vector_store.save_local()
vector_store.get_save_file()
vector_store.update([1], vecs[:1])
父主题: MindFAISS类