class_docstr: Index Dense Embeddings.
class_docstr_tok: ["Index","Dense","Embeddings","."]
docstr: Load dense embeddings and index with FAISS.
docstr_tok: ["Load","dense","embeddings","and","index","with","FAISS","."]
code: def run(self):
      """
      Load dense embeddings and index with FAISS.
      """
      # create index
      index_dir = self.opt["embeddings_dir"]
      embs_name = (
          f"{self.opt['embeddings_name']}_"
          if self.opt["embeddings_name"]
          else ""
      )
      num_parts = len(
          [
              f
              for f in os.listdir(index_dir)
              if f.endswith(".pt") and "sample" not in f
          ]
      )
      input_files = [
          os.path.join(index_dir, f"{embs_name}{i}.pt")
          for i in range(num_parts)
      ]
      if self.opt["indexer_type"] == "compressed":
          index_name = self.opt["compressed_indexer_factory"].replace(
              ",", "__"
          )
      elif self.opt["embeddings_name"]:
          index_name = self.opt["embeddings_name"]
      else:
          index_name = "hnsw_flat"
      index_path = os.path.join(index_dir, index_name)
  
      if self.opt["save_index_dir"]:
          index_path, index_name = os.path.split(index_path)
          index_path = os.path.join(
              self.opt["save_index_dir"], index_name
          )
          if not os.path.exists(self.opt["save_index_dir"]):
              logging.info(f"Creating directory for file {index_path}")
              os.makedirs(self.opt["save_index_dir"])
  
      logging.info(f"index path: {index_path}")
      self.index_path = index_path
  
      self.index = indexer_factory(self.opt)
      if self.opt["indexer_type"] != "exact":
          self.train_then_add(input_files)
      else:
          self.index_data(input_files)
      # save data
      self.index.serialize(index_path)
  
file_path: ParlAI/parlai/agents/rag/scripts/index_dense_embeddings.py
imports: import os
  import random
  import torch
  from typing import List
  from parlai.core.params import ParlaiParser
  from parlai.core.script import ParlaiScript
  import parlai.utils.logging
  from parlai.agents.rag.rag import RagAgent
  from parlai.agents.rag.indexers import indexer_factory, CompressedIndexer
label_desc: Use image node_id 2 for calling the Indexer obj's underlying member method code with example usage: obj.run() without return types