autointent.context.vector_index_client.VectorIndex#
- class autointent.context.vector_index_client.VectorIndex(model_name, embedder_device, embedder_batch_size=32, embedder_max_length=None, embedder_use_cache=False)#
A class for managing a vector index using FAISS and embedding models.
This class allows adding, querying, and managing embeddings and their associated labels for efficient nearest neighbor search.
- Parameters:
- model_name#
- embedder#
- embedder_device#
- logger#
- add(texts, labels)#
Add texts and their corresponding labels to the index.
- is_empty()#
Check if the index is empty.
- Returns:
True if the index contains no embeddings, False otherwise.
- Return type:
- delete()#
Delete the vector index and all associated data from disk and memory.
- Return type:
None
- clear_ram()#
Clear the vector index from RAM.
- Return type:
None
- get_all_embeddings()#
Retrieve all embeddings stored in the index.
- Returns:
Array of all embeddings.
- Raises:
ValueError – If the index has not been created yet.
- Return type:
numpy.typing.NDArray[Any]
- get_all_labels()#
Retrieve all labels stored in the index.
- Returns:
List of all labels.
- Return type:
list[autointent.custom_types.LabelType]
- query(queries, k)#
Query the index to retrieve nearest neighbors.
- dump(dir_path)#
Save the index and associated data to disk.
- Parameters:
dir_path (pathlib.Path) – Directory path to save the data.
- Return type:
None
- load(dir_path)#
Load the index and associated data from disk.
- Parameters:
dir_path (pathlib.Path) – Directory path where the data is stored.
- Return type:
None