class_docstr: Flask Retrieval server, which helps to get the KNN tokens given the query chunk
code: def __init__(
      self,
      faiss_index: str,
      faiss_devices: str,
      nprobe: int,
      retrieval_index: str,
      tokenizer: TokenizerSpec,
      query_bert_ip: str,
      query_bert_port: int = None,
  ):
      self.app = Flask(__name__, static_url_path="")
      # server
      has_gpu = torch.cuda.is_available() and hasattr(
          faiss, "index_gpu_to_cpu"
      )
  
      if faiss_devices is None or not torch.cuda.is_available():
          device_list = None
      else:
          device_list = [
              "cuda:" + str(device)
              for device in faiss_devices.split(",")
          ]
  
      self.index = faiss.read_index(faiss_index)
      if has_gpu and device_list is not None:
          beg = time.time()
          co = faiss.GpuMultipleClonerOptions()
          co.useFloat16 = True
          co.usePrecomputed = False
          co.shard = True
          self.index = faiss.index_cpu_to_all_gpus(
              self.index, co, ngpu=len(device_list)
          )
          end = time.time()
          logging.info(f"convert Faiss db to GPU takes {end - beg} s")
      self.index.nprobe = nprobe
      self.tokenizer = tokenizer
      self.ds = MMapRetrievalIndexedDataset(retrieval_index)
      api = Api(self.app)
      api.add_resource(
          FaissRetrievalResource,
          "/knn",
          resource_class_args=[
              self.index,
              self.tokenizer,
              self.ds,
              query_bert_ip,
              query_bert_port,
          ],
      )
  
imports: import base64
  import logging
  import pickle
  import threading
  import time
  from typing import List, Union
  import faiss
  import numpy
  import torch
  from flask import Flask, jsonify, request
  from flask_restful import Api, Resource
  from nemo.collections.common.tokenizers.tokenizer_spec import TokenizerSpec
  from nemo.collections.nlp.data.language_modeling.megatron.indexed_retrieval_dataset import MMapRetrievalIndexedDataset
  from nemo.collections.nlp.modules.common.megatron.retrieval_services.util import lock, request_data
label_desc: Use image node_id 1 to create a new RetrievalServer object from inherited base classes: object with example: obj = RetrievalServer(faiss_index, faiss_devices, nprobe, retrieval_index, tokenizer, query_bert_ip, query_bert_port)