Class Introduction
Function
Provides a Faiss-based vector database.
Prototype
from mx_rag.storage.vectorstore import MindFAISS MindFAISS(x_dim, devs, load_local_index, index_type, metric_type, auto_save)
Parameters
Parameter |
Data Type |
Required/Optional |
Description |
|---|---|---|---|
x_dim |
Integer |
Required |
Vector dimension. The value is greater than 0 and less than or equal to 1024 ×1024. |
devs |
List[int] |
Required |
Device list. Currently, only one device can be set. |
load_local_index |
String |
Required |
Local index path. The path length cannot exceed 1024 characters, and the file name length cannot exceed 255 characters. The path cannot be a soft link and cannot contain two consecutive dots (..). The path cannot be in the path list: ["/etc", "/usr/bin", "/usr/lib", "/usr/lib64", "/sys/", "/dev/", "/sbin","/tmp"]. |
index_type |
String |
Optional |
Vector retrieval type. Currently, only FLAT (default value) is supported. |
metric_type |
String |
Optional |
Vector distance calculation mode, which can be IP, L2 (default), and COSINE. |
auto_save |
Bool |
Optional |
Whether to automatically save indexes. The value can be True or False. The default value is True. |
If auto_save is set to False, MindFAISS does not automatically save vectors to an offline knowledge base. You need to manually call save_local() to save vectors to an offline knowledge base. Otherwise, the vectors that are not saved will be lost after the program exits, which may cause data inconsistency between the relational database and vector database. As a result, the program fails to run.
Example
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])