Index

module index

Index 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

class 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 Mode

  • preset (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__()

Initializes the IndexConfig class.


index_name()

Returns the index name.

RETURNS

str: Name of the index.


index_name()

Sets the index name.

ARGUMENTS

  • index_name (str): Name of the index.


context_param()

Returns the context parameter object.

RETURNS

ContextParameter: The parameter object for this context.


context_param()

Sets the context parameter object.

ARGUMENTS

  • context_param (ContextParameter): The parameter object for this context.


key_param()

Returns the key parameter object.

RETURNS

KeyParameter: The parameter object for the key.


key_param()

Sets the key parameter object.

ARGUMENTS

  • key_param (KeyParameter): The parameter object for the key.


index_param()

Returns the index parameter object.

RETURNS

IndexParameter: The parameter object for the index.


index_param()

Sets the index parameter object.

ARGUMENTS

  • index_param (IndexParameter): The parameter object for the index.


preset()

Returns the preset.

RETURNS

str: Preset for the index.


preset()

Sets the preset.

ARGUMENTS

  • preset (str): Preset for the index.


dim()

Returns the dimensionality of the index.

RETURNS

int: Dimensionality of the index.


dim()

Sets the dimensionality of the index.

ARGUMENTS

  • dim (int): Dimensionality of the index.


eval_mode()

Returns the evaluation mode.

RETURNS

str: Evaluation mode for the context.


eval_mode()

Sets the evaluation mode.

ARGUMENTS

  • eval_mode (str): Evaluation mode for the context.


search_type()

Returns the search type.

RETURNS

str: Search type for the index.


index_encryption()

Returns whether database encryption is enabled.

RETURNS

str: The encryption type for database, e.g. "plain", "cipher", "hybrid".


index_encryption()

Sets whether database encryption is enabled.

ARGUMENTS

  • index_encryption (str): The encryption type for database, e.g. "plain", "cipher", "hybrid".


query_encryption()

Returns whether query encryption is enabled.

RETURNS

str: The encryption type for query, e.g. "plain", "cipher", "hybrid".


query_encryption()

Sets whether query encryption is enabled.

ARGUMENTS

  • query_encryption (str): The encryption type for query, e.g. "plain", "cipher", "hybrid".


index_type()

Returns the index type.

RETURNS

str: Type of the index.


index_type()

Sets the index type.

ARGUMENTS

  • index_type (str): Type of the index.


index_params()

Returns the index parameters.

RETURNS

dict: Parameters for the index.


nlist()

Returns the nlist parameter for IVF indices.

RETURNS

int: Number of clusters (nlist) for IVF indices.


default_nprobe()

Returns the default nprobe parameter for IVF indices.

RETURNS

int: Default number of probes (nprobe) for IVF indices.


centroids()

Returns the centroids for IVF indices.

RETURNS

list[list[float]]: Centroids for IVF indices.


key_path()

Returns the key path.

RETURNS

str: Path to the key.


key_path()

Sets the key path.

ARGUMENTS

  • key_path (str): Path to the key.


key_id()

Returns the key ID.

RETURNS

str: ID of the key.


key_id()

Sets the key ID.

ARGUMENTS

  • key_id (str): ID of the key.


seal_info()

Returns the seal mode.

RETURNS

str: Seal mode for the keys.


seal_mode()

Returns the seal mode.

RETURNS

str: Seal mode for the keys.


seal_kek_path()

Returns the seal KEK path.

RETURNS

str: Path to the seal KEK.


eval_key_path()

Returns the evaluation key path.

RETURNS

str: Path to the evaluation key.


enc_key_path()

Returns the encryption key path.

RETURNS

str: Path to the encryption key.


sec_key_path()

Returns the secret key path.

RETURNS

str: Path to the secret key.


metadata_enc_key_path()

Returns the metadata encryption key path.

RETURNS

str: Path to the metadata encryption key.


key_dir()

Returns the directory where the keys are stored.

RETURNS

str: Directory for the keys.


need_cipher()

Returns whether cipher operations are needed.

RETURNS

bool: True if cipher operations are needed, False otherwise.


deepcopy()

Creates a deep copy of the index configuration.

RETURNS

IndexConfig: A deep copy of the index configuration.

class 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__()

Initializes the Index class.

Check server connection and check if the index exists.

ARGUMENTS

  • index_name (str): Name of the index.


init_connect()

Connects to the indexer.

ARGUMENTS

  • address (str): Address of the indexer.

RETURNS

Indexer: Connected indexer object.


init_key_path()

Initializes the key path for the index.

ARGUMENTS

  • key_path (str): Path to the key directory.


create_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()

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 of CipherBlock is supported for encrypted data.

  • metadata (str): Metadata for the data.

RETURNS

Index: The index object after insertion.


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()

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 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()

Decrypts the scores from the result context.

ARGUMENTS

  • result_ctxt (CipherBlock): The result context containing encrypted scores.

RETURNS

list of float: Decrypted scores.


load()

Loads the index into memory.

RETURNS

Index: The index object after loading it.


unload()

Unloads the index from memory.

RETURNS

Index: The index object after unloading it.


drop()

Drops the index.

RETURNS

Index: The index object after dropping it.


is_connected()

Checks if the indexer is connected.

RETURNS

bool: True if the indexer is connected, False otherwise.


is_loaded()

Checks if the index is loaded in memory.

RETURNS

bool: True if the index is loaded, False otherwise.

Last updated