Repository: activeloopai/Hub
File: deeplake/core/tensor.py (Python)

Code before:
                            partition_key = get_tensor_vdb_index_key(
                                self.key, commit_id, f"{id}_{info['name']}"
                            )
                            self.storage[partition_key] = incr_data_map[info["name"]]
                    else:
                        self.storage[
                            get_tensor_vdb_index_key(self.key, commit_id, id)
                        ] = b
                    self.storage.flush()
                self.storage.flush()
            except:
                raise
        else:
            raise AssertionError(f"Invalid operation_kind: {operation_kind}")

    def create_vdb_index(
        self,
        id: str,
        distance: Union[DistanceType, str] = DistanceType.L2_NORM,
        additional_params: Optional[Dict[str, int]] = None,
    ):
        """
        Create similarity search index for embedding tensor.

        Args:
            id (str): Unique identifier for the index.
            distance (DistanceType, str): Distance metric to be used for similarity search. Possible values are "l2_norm", "cosine_similarity".
            additional_params (Optional[Dict[str, int]]): Additional parameters for the index.
                - Structure of additional params is:
                    :"M": Increasing this value will increase the index build time and memory usage but will improve the search accuracy. Defaults to ``16``.
                    :"efConstruction": Defaults to ``200``.
                    :"partitions": If tensors contain more than 45M samples, it is recommended to use partitions to create the index. Defaults to ``1``.

        Example:
            >>> ds = deeplake.load("./test/my_embedding_ds")
            >>> # create cosine_similarity index on embedding tensor
            >>> ds.embedding.create_vdb_index(id="hnsw_1", distance=DistanceType.COSINE_SIMILARITY)
            >>> # create cosine_similarity index on embedding tensor with additional params
            >>> ds.embedding.create_vdb_index(id="hnsw_1", distance=DistanceType.COSINE_SIMILARITY, additional_params={"M": 32, "partitions": 1, 'efConstruction': 200})

        Notes:
            Index creation is supported only for embedding tensors.

        Raises:
            Exception: If the tensor is not an embedding tensor.

        Returns:
            Index: Returns the index object.
        """
        self.storage.check_readonly()
        if self.meta.htype != "embedding":

Review comment (suggestion):
@azat-manukyan We should probably modify this api so the default `id` is "hsnw_1", because right now, that's the only hard coded name that works in the search.... I think. @Sounakal 

Code after:
                            partition_key = get_tensor_vdb_index_key(
                                self.key, commit_id, f"{id}_{info['name']}"
                            )
                            self.storage[partition_key] = incr_data_map[info["name"]]
                    else:
                        self.storage[
                            get_tensor_vdb_index_key(self.key, commit_id, id)
                        ] = b
                    self.storage.flush()
                self.storage.flush()
            except:
                raise
        else:
            raise AssertionError(f"Invalid operation_kind: {operation_kind}")

    def create_vdb_index(
        self,
        id: str = "hnsw_1",
        distance: Union[DistanceType, str] = DistanceType.COSINE_SIMILARITY,
        additional_params: Optional[Dict[str, int]] = None,
    ):
        """
        Create similarity search index for embedding tensor.

        Args:
            id (str): Unique identifier for the index. Defaults to ``hnsw_1``.
            distance (DistanceType, str): Distance metric to be used for similarity search. Possible values are "l2_norm", "cosine_similarity". Defaults to ``DistanceType.COSINE_SIMILARITY``.
            additional_params (Optional[Dict[str, int]]): Additional parameters for the index.
                - Structure of additional params is:
                    :"M": Increasing this value will increase the index build time and memory usage but will improve the search accuracy. Defaults to ``16``.
                    :"efConstruction": Defaults to ``200``.
                    :"partitions": If tensors contain more than 45M samples, it is recommended to use partitions to create the index. Defaults to ``1``.

        Example:
            >>> ds = deeplake.load("./test/my_embedding_ds")
            >>> # create cosine_similarity index on embedding tensor
            >>> ds.embedding.create_vdb_index(id="hnsw_1", distance=DistanceType.COSINE_SIMILARITY)
            >>> # create cosine_similarity index on embedding tensor with additional params
            >>> ds.embedding.create_vdb_index(id="hnsw_1", distance=DistanceType.COSINE_SIMILARITY, additional_params={"M": 32, "partitions": 1, 'efConstruction': 200})

        Notes:
            Index creation is supported only for embedding tensors.

        Raises:
            Exception: If the tensor is not an embedding tensor.

        Returns:
            Index: Returns the index object.
        """
        self.storage.check_readonly()
        if self.meta.htype != "embedding":