class_docstr: Add indexing features to `datasets.Dataset`
class_docstr_tok: ["Add","indexing","features","to","`","datasets.Dataset","`"]
docstr: Add a dense index using Faiss for fast retrieval.
  The index is created using the vectors of the specified column.
  You can specify `device` if you want to run it on GPU (`device` must be the GPU index, see more below).
  You can find more information about Faiss here:
  - For `string factory`: https://github.com/facebookresearch/faiss/wiki/The-index-factory
  
  Args:
      column (`str`): The column of the vectors to add to the index.
      index_name (Optional `str`): The index_name/identifier of the index. This is the index_name that is used to call `.get_nearest` or `.search`.
          By default it corresponds to `column`.
      device (Optional `Union[int, List[int]]`): If positive integer, this is the index of the GPU to use. If negative integer, use all GPUs.
          If a list of positive integers is passed in, run only on those GPUs. By default it uses the CPU.
      string_factory (Optional `str`): This is passed to the index factory of Faiss to create the index. Default index class is IndexFlatIP.
      metric_type (Optional `int`): Type of metric. Ex: `faiss.METRIC_INNER_PRODUCT` or `faiss.METRIC_L2`.
      custom_index (Optional `faiss.Index`): Custom Faiss index that you already have instantiated and configured for your needs.
      batch_size (Optional `int`): Size of the batch to use while adding vectors to the FaissIndex. Default value is 1000.
          <Added version="2.4.0"/>
      train_size (Optional `int`): If the index needs a training step, specifies how many vectors will be used to train the index.
      faiss_verbose (`bool`, defaults to False): Enable the verbosity of the Faiss index.
docstr_tok: ["Add","a","dense","index","using","Faiss","for","fast","retrieval",".","The","index","is","created","using","the","vectors","of","the","specified","column",".","You","can","specify","`","device","`","if","you","want","to","run","it","on","GPU","(","`","device","`","must","be","the","GPU","index",",","see","more","below",")",".","You","can","find","more","information","about","Faiss","here",":","-","For","`","string","factory","`",":","https",":","\/\/github.com\/facebookresearch\/faiss\/wiki\/The-index-factory","Args",":","column","(","`","str","`",")",":","The","column","of","the","vectors","to","add","to","the","index",".","index_name","(","Optional","`","str","`",")",":","The","index_name\/identifier","of","the","index",".","This","is","the","index_name","that","is","used","to","call","`",".get_nearest","`","or","`",".search","`",".","By","default","it","corresponds","to","`","column","`",".","device","(","Optional","`","Union","[","int",",","List","[","int","]","]","`",")",":","If","positive","integer",",","this","is","the","index","of","the","GPU","to","use",".","If","negative","integer",",","use","all","GPUs",".","If","a","list","of","positive","integers","is","passed","in",",","run","only","on","those","GPUs",".","By","default","it","uses","the","CPU",".","string_factory","(","Optional","`","str","`",")",":","This","is","passed","to","the","index","factory","of","Faiss","to","create","the","index",".","Default","index","class","is","IndexFlatIP",".","metric_type","(","Optional","`","int","`",")",":","Type","of","metric",".","Ex",":","`","faiss.METRIC_INNER_PRODUCT","`","or","`","faiss.METRIC_L2","`",".","custom_index","(","Optional","`","faiss.Index","`",")",":","Custom","Faiss","index","that","you","already","have","instantiated","and","configured","for","your","needs",".","batch_size","(","Optional","`","int","`",")",":","Size","of","the","batch","to","use","while","adding","vectors","to","the","FaissIndex",".","Default","value","is","1000",".","<","Added","version=","''","2.4.0","''","\/",">","train_size","(","Optional","`","int","`",")",":","If","the","index","needs","a","training","step",",","specifies","how","many","vectors","will","be","used","to","train","the","index",".","faiss_verbose","(","`","bool","`",",","defaults","to","False",")",":","Enable","the","verbosity","of","the","Faiss","index","."]
code: def add_faiss_index(
      self,
      column: str,
      index_name: Optional[str] = None,
      device: Optional[Union[int, List[int]]] = None,
      string_factory: Optional[str] = None,
      metric_type: Optional[int] = None,
      custom_index: Optional["faiss.Index"] = None,
      batch_size: int = 1000,
      train_size: Optional[int] = None,
      faiss_verbose: bool = False,
  ):
      """Add a dense index using Faiss for fast retrieval.
      The index is created using the vectors of the specified column.
      You can specify `device` if you want to run it on GPU (`device` must be the GPU index, see more below).
      You can find more information about Faiss here:
      - For `string factory`: https://github.com/facebookresearch/faiss/wiki/The-index-factory
  
      Args:
          column (`str`): The column of the vectors to add to the index.
          index_name (Optional `str`): The index_name/identifier of the index. This is the index_name that is used to call `.get_nearest` or `.search`.
              By default it corresponds to `column`.
          device (Optional `Union[int, List[int]]`): If positive integer, this is the index of the GPU to use. If negative integer, use all GPUs.
              If a list of positive integers is passed in, run only on those GPUs. By default it uses the CPU.
          string_factory (Optional `str`): This is passed to the index factory of Faiss to create the index. Default index class is IndexFlatIP.
          metric_type (Optional `int`): Type of metric. Ex: `faiss.METRIC_INNER_PRODUCT` or `faiss.METRIC_L2`.
          custom_index (Optional `faiss.Index`): Custom Faiss index that you already have instantiated and configured for your needs.
          batch_size (Optional `int`): Size of the batch to use while adding vectors to the FaissIndex. Default value is 1000.
              <Added version="2.4.0"/>
          train_size (Optional `int`): If the index needs a training step, specifies how many vectors will be used to train the index.
          faiss_verbose (`bool`, defaults to False): Enable the verbosity of the Faiss index.
      """
      index_name = index_name if index_name is not None else column
      faiss_index = FaissIndex(
          device=device,
          string_factory=string_factory,
          metric_type=metric_type,
          custom_index=custom_index,
      )
      faiss_index.add_vectors(
          self,
          column=column,
          batch_size=batch_size,
          train_size=train_size,
          faiss_verbose=faiss_verbose,
      )
      self._indexes[index_name] = faiss_index
  
imports: import importlib.util
  import os
  import tempfile
  from pathlib import PurePath
  from typing import TYPE_CHECKING, Dict, List, NamedTuple, Optional, Union
  import fsspec
  import numpy
  from .utils import logging
  from .utils import tqdm
label_desc: Use image node_id 8 for calling the IndexableMixin obj's underlying member method code with example usage: obj.add_faiss_index(column, index_name, device, string_factory, metric_type, custom_index, batch_size, train_size, faiss_verbose) without return types