Index
module index
indexIndex Module
This module provides classes and methods for managing index configurations and operations.
IndexConfig— Configuration class for index settings.Index— Class for managing index operations.
class IndexConfig
IndexConfigclass IndexConfig()Configuration class for index settings.
ARGUMENTS
index_name(str): Name of the index.dim(int): Dimensionality of the index.key_path(str): Path to the key.key_id(str): ID of the key.seal_mode(str): Seal mode for the key.seal_kek_path(str): KeK for AES Seal Modepreset(str): Preset for the index.eval_mode(str): Evaluation mode for the index.query_encryption(str): The encryption type for query, e.g. "plain", "cipher", "hybrid".index_encryption(str): The encryption type for database, e.g. "plain", "cipher", "hybrid".index_params(dict): Parameters for the index.metadata_encryption(bool): The encryption type for metadata, e.g. True, False.
__init__()
__init__()def __init__(index_name: Optional[str] = None,
dim: Optional[int] = None,
key_path: Optional[str] = None,
key_id: Optional[str] = None,
seal_mode: Optional[str] = None,
seal_kek_path: Optional[str] = None,
preset: Optional[str] = None,
eval_mode: Optional[str] = None,
query_encryption: Optional[str] = None,
index_encryption: Optional[str] = None,
index_params: Optional[dict] = None,
index_type: Optional[str] = None,
metadata_encryption: Optional[bool] = None)Initializes the IndexConfig class.
index_name()
index_name()@property
def index_name() -> strReturns the index name.
RETURNS
str: Name of the index.
index_name()
index_name()@index_name.setter
def index_name(index_name: str)Sets the index name.
ARGUMENTS
index_name(str): Name of the index.
context_param()
context_param()@property
def context_param() -> ContextParameterReturns the context parameter object.
RETURNS
ContextParameter: The parameter object for this context.
context_param()
context_param()@context_param.setter
def context_param(context_param: ContextParameter)Sets the context parameter object.
ARGUMENTS
context_param(ContextParameter): The parameter object for this context.
key_param()
key_param()@property
def key_param() -> KeyParameterReturns the key parameter object.
RETURNS
KeyParameter: The parameter object for the key.
key_param()
key_param()@key_param.setter
def key_param(key_param: KeyParameter)Sets the key parameter object.
ARGUMENTS
key_param(KeyParameter): The parameter object for the key.
index_param()
index_param()@property
def index_param() -> IndexParameterReturns the index parameter object.
RETURNS
IndexParameter: The parameter object for the index.
index_param()
index_param()@index_param.setter
def index_param(index_param: IndexParameter)Sets the index parameter object.
ARGUMENTS
index_param(IndexParameter): The parameter object for the index.
preset()
preset()@property
def preset() -> strReturns the preset.
RETURNS
str: Preset for the index.
preset()
preset()@preset.setter
def preset(preset: str)Sets the preset.
ARGUMENTS
preset(str): Preset for the index.
dim()
dim()@property
def dim() -> intReturns the dimensionality of the index.
RETURNS
int: Dimensionality of the index.
dim()
dim()@dim.setter
def dim(dim: int)Sets the dimensionality of the index.
ARGUMENTS
dim(int): Dimensionality of the index.
eval_mode()
eval_mode()@property
def eval_mode() -> strReturns the evaluation mode.
RETURNS
str: Evaluation mode for the context.
eval_mode()
eval_mode()@eval_mode.setter
def eval_mode(eval_mode: str)Sets the evaluation mode.
ARGUMENTS
eval_mode(str): Evaluation mode for the context.
search_type()
search_type()@property
def search_type() -> strReturns the search type.
RETURNS
str: Search type for the index.
index_encryption()
index_encryption()@property
def index_encryption() -> strReturns whether database encryption is enabled.
RETURNS
str: The encryption type for database, e.g. "plain", "cipher", "hybrid".
index_encryption()
index_encryption()@index_encryption.setter
def index_encryption(index_encryption: str)Sets whether database encryption is enabled.
ARGUMENTS
index_encryption(str): The encryption type for database, e.g. "plain", "cipher", "hybrid".
query_encryption()
query_encryption()@property
def query_encryption() -> strReturns whether query encryption is enabled.
RETURNS
str: The encryption type for query, e.g. "plain", "cipher", "hybrid".
query_encryption()
query_encryption()@query_encryption.setter
def query_encryption(query_encryption: str)Sets whether query encryption is enabled.
ARGUMENTS
query_encryption(str): The encryption type for query, e.g. "plain", "cipher", "hybrid".
index_type()
index_type()@property
def index_type() -> strReturns the index type.
RETURNS
str: Type of the index.
index_type()
index_type()@index_type.setter
def index_type(index_type: str)Sets the index type.
ARGUMENTS
index_type(str): Type of the index.
index_params()
index_params()@property
def index_params() -> dictReturns the index parameters.
RETURNS
dict: Parameters for the index.
nlist()
nlist()@property
def nlist()Returns the nlist parameter for IVF indices.
RETURNS
int: Number of clusters (nlist) for IVF indices.
default_nprobe()
default_nprobe()@property
def default_nprobe()Returns the default nprobe parameter for IVF indices.
RETURNS
int: Default number of probes (nprobe) for IVF indices.
centroids()
centroids()@property
def centroids()Returns the centroids for IVF indices.
RETURNS
list[list[float]]: Centroids for IVF indices.
key_path()
key_path()@property
def key_path() -> strReturns the key path.
RETURNS
str: Path to the key.
key_path()
key_path()@key_path.setter
def key_path(key_path: str)Sets the key path.
ARGUMENTS
key_path(str): Path to the key.
key_id()
key_id()@property
def key_id() -> strReturns the key ID.
RETURNS
str: ID of the key.
key_id()
key_id()@key_id.setter
def key_id(key_id: str)Sets the key ID.
ARGUMENTS
key_id(str): ID of the key.
seal_info()
seal_info()@property
def seal_info() -> SealInfoReturns the seal mode.
RETURNS
str: Seal mode for the keys.
seal_mode()
seal_mode()@property
def seal_mode() -> strReturns the seal mode.
RETURNS
str: Seal mode for the keys.
seal_kek_path()
seal_kek_path()@property
def seal_kek_path() -> strReturns the seal KEK path.
RETURNS
str: Path to the seal KEK.
eval_key_path()
eval_key_path()@property
def eval_key_path() -> strReturns the evaluation key path.
RETURNS
str: Path to the evaluation key.
enc_key_path()
enc_key_path()@property
def enc_key_path() -> strReturns the encryption key path.
RETURNS
str: Path to the encryption key.
sec_key_path()
sec_key_path()@property
def sec_key_path() -> strReturns the secret key path.
RETURNS
str: Path to the secret key.
metadata_enc_key_path()
metadata_enc_key_path()@property
def metadata_enc_key_path() -> strReturns the metadata encryption key path.
RETURNS
str: Path to the metadata encryption key.
key_dir()
key_dir()@property
def key_dir() -> strReturns the directory where the keys are stored.
RETURNS
str: Directory for the keys.
need_cipher()
need_cipher()@property
def need_cipher() -> boolReturns whether cipher operations are needed.
RETURNS
bool: True if cipher operations are needed, False otherwise.
deepcopy()
deepcopy()def deepcopy(index_name: Optional[str] = None,
dim: Optional[int] = None,
key_path: Optional[str] = None,
key_id: Optional[str] = None,
seal_mode: Optional[str] = None,
seal_kek_path: Optional[str] = None,
preset: Optional[str] = None,
eval_mode: Optional[str] = None,
query_encryption: Optional[str] = None,
index_encryption: Optional[str] = None,
index_params: Optional[dict] = None,
metadata_encryption: Optional[bool] = None) -> "IndexConfig"Creates a deep copy of the index configuration.
RETURNS
IndexConfig: A deep copy of the index configuration.
class Index
Indexclass Index()Class for managing index operations.
ARGUMENTS
index_config(IndexConfig): Configuration for the index.indexer(Indexer): Indexer object for managing connections.num_entities(int): Number of entities in the index.cipher(Cipher): Cipher object for encryption and decryption.
__init__()
__init__()def __init__(index_name: str, index_config: Optional[IndexConfig] = None)Initializes the Index class.
Check server connection and check if the index exists.
ARGUMENTS
index_name(str): Name of the index.
init_connect()
init_connect()@classmethod
def init_connect(cls,
address: str,
access_token: Optional[str] = None) -> "Indexer"Connects to the indexer.
ARGUMENTS
address(str): Address of the indexer.
RETURNS
Indexer: Connected indexer object.
init_key_path()
init_key_path()@classmethod
def init_key_path(cls, key_path: str)Initializes the key path for the index.
ARGUMENTS
key_path(str): Path to the key directory.
create_index()
create_index()@classmethod
def create_index(cls,
index_config: IndexConfig,
indexer: Optional[Indexer] = None) -> "Index"Creates a new index.
ARGUMENTS
index_config(IndexConfig): Configuration for the index.indexer(Indexer): Indexer object for managing connections.
RETURNS
Index: The created index.
insert()
insert()def insert(data: Union[List[List[float]], List[np.ndarray], np.ndarray,
List[CipherBlock]],
metadata: List[Any] = None)Inserts data into the index.
ARGUMENTS
data(list of floats, list of np.ndarray, 2D np.ndarray, or list of CipherBlock): Data to be inserted. It can be plaintext (list of lists, list of numpy arrays, or 2D numpy array) or ciphertext (CipherBlock). Currently, only a list ofCipherBlockis supported for encrypted data.metadata(str): Metadata for the data.
RETURNS
Index: The index object after insertion.
search()
search()def search(query: Union[List[float], np.ndarray, List[List[float]],
List[np.ndarray], List[CipherBlock]],
top_k: int,
output_fields: List[str] = None,
search_params: dict = None)Searches the index.
ARGUMENTS
query(list of float or np.ndarray): Query vector.top_k(int): Number of top results to return (default 3).output_fields(list of str): Fields to include in the output.
RETURNS
list of dict: Search results.
scoring()
scoring()def scoring(query: Union[List[float], np.ndarray, CipherBlock,
List[List[float]], List[np.ndarray],
List[CipherBlock]],
search_params: dict = None)Computes the scores for a query against the index.
ARGUMENTS
query(list): Query vector.
Raises:
ValueError: If the index is not connected.
RETURNS
list of dict: Scores for the query.
get_topk_metadata_results()
get_topk_metadata_results()def get_topk_metadata_results(result,
top_k: int,
output_fields: List[str] = None)Get top-k metadata results from the search ciphertext result.
ARGUMENTS
result(CipherBlock): The result context containing encrypted scores.top_k(int): Number of top results to return.output_fields(list of str): Fields to include in the output.
Raises:
ValueError: If the indexer is not connected or if the result is empty.
RETURNS
list of dict: List of dictionaries containing the top-k results with metadata.
decrypt_score()
decrypt_score()def decrypt_score(result_ctxt: CipherBlock,
sec_key_path: Optional[str] = None,
seal_mode: Optional[str] = None,
seal_kek_path: Optional[str] = None)Decrypts the scores from the result context.
ARGUMENTS
result_ctxt(CipherBlock): The result context containing encrypted scores.
RETURNS
list of float: Decrypted scores.
load()
load()def load()Loads the index into memory.
RETURNS
Index: The index object after loading it.
unload()
unload()def unload()Unloads the index from memory.
RETURNS
Index: The index object after unloading it.
drop()
drop()def drop()Drops the index.
RETURNS
Index: The index object after dropping it.
is_connected()
is_connected()@property
def is_connected() -> boolChecks if the indexer is connected.
RETURNS
bool: True if the indexer is connected, False otherwise.
is_loaded()
is_loaded()@property
def is_loaded() -> boolChecks if the index is loaded in memory.
RETURNS
bool: True if the index is loaded, False otherwise.
Last updated

