
"""simple docstring"""


import tempfile
import unittest

from transformers import SPIECE_UNDERLINE, BatchEncoding, PLBartTokenizer, is_torch_available
from transformers.testing_utils import (
    get_tests_dir,
    nested_simplify,
    require_sentencepiece,
    require_tokenizers,
    require_torch,
)

from ...test_tokenization_common import TokenizerTesterMixin


SCREAMING_SNAKE_CASE			  =  get_tests_dir("""fixtures/test_sentencepiece.model""")


if is_torch_available():
      from transformers.models.plbart.modeling_plbart import shift_tokens_right

SCREAMING_SNAKE_CASE			  =  50_003
SCREAMING_SNAKE_CASE			  =  50_002



@require_sentencepiece
@require_tokenizers
class 	__a	(   _lowerCAmelCase     ,  unittest.TestCase						):
       UpperCamelCase_		:       int				=      PLBartTokenizer
       UpperCamelCase_		:       str				=      None
       UpperCamelCase_		:       Optional[Any]				=      False






       def 						_SCREAMING_SNAKE_CASE							(	self			:				str      )->	Union[str, Any]:







              """simple docstring"""
              super().setUp()

              # We have a SentencePiece fixture for testing
              UpperCamelCase       			=		PLBartTokenizer(UpperCAmelCase_							,   language_codes="base"							,   keep_accents=UpperCAmelCase_      )
              tokenizer.save_pretrained(self.tmpdirname      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Dict      )->	Dict:







              """simple docstring"""
              UpperCamelCase       			=		PLBartTokenizer(UpperCAmelCase_							,   language_codes="base"							,   keep_accents=UpperCAmelCase_      )

              UpperCamelCase       			=		tokenizer.tokenize("This is a test"      )
              self.assertListEqual(UpperCAmelCase_							,   ["▁This", "▁is", "▁a", "▁t", "est"]      )

              self.assertListEqual(
                  tokenizer.convert_tokens_to_ids(UpperCAmelCase_      )							,   [value + tokenizer.fairseq_offset for value in [285, 46, 10, 170, 382]]							,   )

              UpperCamelCase       			=		tokenizer.tokenize("I was born in 92000, and this is falsé."      )
              self.assertListEqual(
                  UpperCAmelCase_							,   [
                      SPIECE_UNDERLINE + "I",
                      SPIECE_UNDERLINE + "was",
                      SPIECE_UNDERLINE + "b",
                      "or",
                      "n",
                      SPIECE_UNDERLINE + "in",
                      SPIECE_UNDERLINE + "",
                      "9",
                      "2",
                      "0",
                      "0",
                      "0",
                      ",",
                      SPIECE_UNDERLINE + "and",
                      SPIECE_UNDERLINE + "this",
                      SPIECE_UNDERLINE + "is",
                      SPIECE_UNDERLINE + "f",
                      "al",
                      "s",
                      "é",
                      ".",
                  ]							,   )
              UpperCamelCase       			=		tokenizer.convert_tokens_to_ids(UpperCAmelCase_      )
              self.assertListEqual(
                  UpperCAmelCase_							,   [
                      value + tokenizer.fairseq_offset
                      for value in [8, 21, 84, 55, 24, 19, 7, 2, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, 2, 4]
                  ]							,   )

              UpperCamelCase       			=		tokenizer.convert_ids_to_tokens(UpperCAmelCase_      )
              self.assertListEqual(
                  UpperCAmelCase_							,   [
                      SPIECE_UNDERLINE + "I",
                      SPIECE_UNDERLINE + "was",
                      SPIECE_UNDERLINE + "b",
                      "or",
                      "n",
                      SPIECE_UNDERLINE + "in",
                      SPIECE_UNDERLINE + "",
                      "<unk>",
                      "2",
                      "0",
                      "0",
                      "0",
                      ",",
                      SPIECE_UNDERLINE + "and",
                      SPIECE_UNDERLINE + "this",
                      SPIECE_UNDERLINE + "is",
                      SPIECE_UNDERLINE + "f",
                      "al",
                      "s",
                      "<unk>",
                      ".",
                  ]							,   )

              UpperCamelCase       			=		tokenizer.vocab_size
              UpperCamelCase       			=		[tokenizer.convert_ids_to_tokens(UpperCAmelCase_      ) for x in range(end - 4							,   UpperCAmelCase_      )]

              self.assertListEqual(UpperCAmelCase_							,   ["__java__", "__python__", "__en_XX__", "<mask>"]      )

              UpperCamelCase       			=		"java.lang.Exception, python.lang.Exception, javascript, php, ruby, go"
              UpperCamelCase       			=		tokenizer(UpperCAmelCase_      ).input_ids
              self.assertEqual(
                  tokenizer.decode(UpperCAmelCase_							,   skip_special_tokens=UpperCAmelCase_							,   clean_up_tokenization_spaces=UpperCAmelCase_      )							,   UpperCAmelCase_							,   )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Union[str, Any]      )->	List[str]:







              """simple docstring"""
              UpperCamelCase       			=		PLBartTokenizer(UpperCAmelCase_							,   language_codes="multi"							,   keep_accents=UpperCAmelCase_      )

              UpperCamelCase       			=		tokenizer.tokenize("This is a test"      )
              self.assertListEqual(UpperCAmelCase_							,   ["▁This", "▁is", "▁a", "▁t", "est"]      )

              self.assertListEqual(
                  tokenizer.convert_tokens_to_ids(UpperCAmelCase_      )							,   [value + tokenizer.fairseq_offset for value in [285, 46, 10, 170, 382]]							,   )

              UpperCamelCase       			=		tokenizer.tokenize("I was born in 92000, and this is falsé."      )
              self.assertListEqual(
                  UpperCAmelCase_							,   [
                      SPIECE_UNDERLINE + "I",
                      SPIECE_UNDERLINE + "was",
                      SPIECE_UNDERLINE + "b",
                      "or",
                      "n",
                      SPIECE_UNDERLINE + "in",
                      SPIECE_UNDERLINE + "",
                      "9",
                      "2",
                      "0",
                      "0",
                      "0",
                      ",",
                      SPIECE_UNDERLINE + "and",
                      SPIECE_UNDERLINE + "this",
                      SPIECE_UNDERLINE + "is",
                      SPIECE_UNDERLINE + "f",
                      "al",
                      "s",
                      "é",
                      ".",
                  ]							,   )
              UpperCamelCase       			=		tokenizer.convert_tokens_to_ids(UpperCAmelCase_      )
              self.assertListEqual(
                  UpperCAmelCase_							,   [
                      value + tokenizer.fairseq_offset
                      for value in [8, 21, 84, 55, 24, 19, 7, 2, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, 2, 4]
                  ]							,   )

              UpperCamelCase       			=		tokenizer.convert_ids_to_tokens(UpperCAmelCase_      )
              self.assertListEqual(
                  UpperCAmelCase_							,   [
                      SPIECE_UNDERLINE + "I",
                      SPIECE_UNDERLINE + "was",
                      SPIECE_UNDERLINE + "b",
                      "or",
                      "n",
                      SPIECE_UNDERLINE + "in",
                      SPIECE_UNDERLINE + "",
                      "<unk>",
                      "2",
                      "0",
                      "0",
                      "0",
                      ",",
                      SPIECE_UNDERLINE + "and",
                      SPIECE_UNDERLINE + "this",
                      SPIECE_UNDERLINE + "is",
                      SPIECE_UNDERLINE + "f",
                      "al",
                      "s",
                      "<unk>",
                      ".",
                  ]							,   )
              UpperCamelCase       			=		tokenizer.vocab_size
              UpperCamelCase       			=		[tokenizer.convert_ids_to_tokens(UpperCAmelCase_      ) for x in range(end - 7							,   UpperCAmelCase_      )]

              self.assertListEqual(
                  UpperCAmelCase_							,   ["__java__", "__python__", "__en_XX__", "__javascript__", "__php__", "__ruby__", "__go__"]      )
              UpperCamelCase       			=		"java.lang.Exception, python.lang.Exception, javascript, php, ruby, go"
              UpperCamelCase       			=		tokenizer(UpperCAmelCase_      ).input_ids
              self.assertEqual(
                  tokenizer.decode(UpperCAmelCase_							,   skip_special_tokens=UpperCAmelCase_							,   clean_up_tokenization_spaces=UpperCAmelCase_      )							,   UpperCAmelCase_							,   )





@require_torch
@require_sentencepiece
@require_tokenizers
class 	__a	(   unittest.TestCase						):
       UpperCamelCase_		:       Tuple				=      '''uclanlp/plbart-python-en_XX'''
       UpperCamelCase_		:       List[str]				=      [
           '''def maximum(a,b,c):NEW_LINE_INDENTreturn max([a,b,c])''',
           '''def sum(a,b,c):NEW_LINE_INDENTreturn sum([a,b,c])''',
       ]
       UpperCamelCase_		:       Union[str, Any]				=      [
           '''Returns the maximum value of a b c.''',
           '''Sums the values of a b c.''',
       ]
       UpperCamelCase_		:       Dict				=      [
           134,
           5452,
           33460,
           33441,
           33463,
           33465,
           33463,
           33449,
           988,
           20,
           33456,
           19,
           33456,
           771,
           39,
           4258,
           889,
           3318,
           33441,
           33463,
           33465,
           33463,
           33449,
           2471,
           2,
           PYTHON_CODE,
       ]






       @classmethod
       def 						_SCREAMING_SNAKE_CASE							(	cls			:				str      )->	str:







              """simple docstring"""
              UpperCamelCase       			=		PLBartTokenizer.from_pretrained(
                  cls.checkpoint_name							,   language_codes="base"							,   src_lang="python"							,   tgt_lang="en_XX"      )
              UpperCamelCase       			=		1
              return cls






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]      )->	Any:







              """simple docstring"""
              self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["__java__"]							,   50_001      )
              self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["__python__"]							,   50_002      )
              self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["__en_XX__"]							,   50_003      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[Any]      )->	List[Any]:







              """simple docstring"""
              UpperCamelCase       			=		self.tokenizer.batch_encode_plus(self.src_text      ).input_ids[0]
              self.assertListEqual(self.expected_src_tokens							,   UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[str]      )->	str:







              """simple docstring"""
              self.assertIn(UpperCAmelCase_							,   self.tokenizer.all_special_ids      )
              UpperCamelCase       			=		[EN_CODE, 9_037, 33_442, 57, 752, 153, 14, 56, 18, 9, 2]
              UpperCamelCase       			=		self.tokenizer.decode(UpperCAmelCase_							,   skip_special_tokens=UpperCAmelCase_      )
              UpperCamelCase       			=		self.tokenizer.decode(generated_ids[1:]							,   skip_special_tokens=UpperCAmelCase_      )
              self.assertEqual(UpperCAmelCase_							,   UpperCAmelCase_      )
              self.assertNotIn(self.tokenizer.eos_token							,   UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[Any]      )->	Tuple:







              """simple docstring"""
              UpperCamelCase       			=		["def sum(a,b,c):NEW_LINE_INDENTreturn sum([a,b,c])" * 20]
              self.assertIsInstance(src_text[0]							,   UpperCAmelCase_      )
              UpperCamelCase       			=		10
              UpperCamelCase       			=		self.tokenizer(UpperCAmelCase_							,   max_length=UpperCAmelCase_							,   truncation=UpperCAmelCase_      ).input_ids[0]
              self.assertEqual(ids[-2]							,   2      )
              self.assertEqual(ids[-1]							,   UpperCAmelCase_      )
              self.assertEqual(len(UpperCAmelCase_      )							,   UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Any      )->	List[Any]:







              """simple docstring"""
              self.assertListEqual(self.tokenizer.convert_tokens_to_ids(["<mask>", "__java__"]      )							,   [50_004, 50_001]      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]      )->	int:







              """simple docstring"""
              UpperCamelCase       			=		tempfile.mkdtemp()
              UpperCamelCase       			=		self.tokenizer.fairseq_tokens_to_ids
              self.tokenizer.save_pretrained(UpperCAmelCase_      )
              UpperCamelCase       			=		PLBartTokenizer.from_pretrained(UpperCAmelCase_      )
              self.assertDictEqual(new_tok.fairseq_tokens_to_ids							,   UpperCAmelCase_      )






       @require_torch
       def 						_SCREAMING_SNAKE_CASE							(	self			:				str      )->	str:







              """simple docstring"""
              UpperCamelCase       			=		self.tokenizer(self.src_text							,   text_target=self.tgt_text							,   padding=UpperCAmelCase_							,   return_tensors="pt"      )
              UpperCamelCase       			=		shift_tokens_right(batch["labels"]							,   self.tokenizer.pad_token_id      )

              # fairseq batch: https://gist.github.com/sshleifer/cba08bc2109361a74ac3760a7e30e4f4
              self.assertEqual(batch.input_ids[1][-2:].tolist()							,   [2, PYTHON_CODE]      )
              self.assertEqual(batch.decoder_input_ids[1][0]							,   UpperCAmelCase_      )
              self.assertEqual(batch.decoder_input_ids[1][-1]							,   2      )
              self.assertEqual(batch.labels[1][-2:].tolist()							,   [2, EN_CODE]      )






       @require_torch
       def 						_SCREAMING_SNAKE_CASE							(	self			:				Union[str, Any]      )->	List[Any]:







              """simple docstring"""
              UpperCamelCase       			=		self.tokenizer(
                  self.src_text							,   text_target=self.tgt_text							,   padding=UpperCAmelCase_							,   truncation=UpperCAmelCase_							,   max_length=len(self.expected_src_tokens      )							,   return_tensors="pt"							,   )
              UpperCamelCase       			=		shift_tokens_right(batch["labels"]							,   self.tokenizer.pad_token_id      )

              self.assertIsInstance(UpperCAmelCase_							,   UpperCAmelCase_      )

              self.assertEqual((2, 26)							,   batch.input_ids.shape      )
              self.assertEqual((2, 26)							,   batch.attention_mask.shape      )
              UpperCamelCase       			=		batch.input_ids.tolist()[0]
              self.assertListEqual(self.expected_src_tokens							,   UpperCAmelCase_      )
              self.assertEqual(2							,   batch.decoder_input_ids[0, -1]      )  # EOS
              # Test that special tokens are reset
              self.assertEqual(self.tokenizer.prefix_tokens							,   []      )
              self.assertEqual(self.tokenizer.suffix_tokens							,   [self.tokenizer.eos_token_id, PYTHON_CODE]      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[Any]      )->	Any:







              """simple docstring"""
              UpperCamelCase       			=		self.tokenizer(self.src_text							,   padding=UpperCAmelCase_							,   truncation=UpperCAmelCase_							,   max_length=3							,   return_tensors="pt"      )
              UpperCamelCase       			=		self.tokenizer(
                  text_target=self.tgt_text							,   padding=UpperCAmelCase_							,   truncation=UpperCAmelCase_							,   max_length=10							,   return_tensors="pt"      )
              UpperCamelCase       			=		targets["input_ids"]
              UpperCamelCase       			=		shift_tokens_right(UpperCAmelCase_							,   self.tokenizer.pad_token_id      )

              self.assertEqual(batch.input_ids.shape[1]							,   3      )
              self.assertEqual(batch.decoder_input_ids.shape[1]							,   10      )






       @require_torch
       def 						_SCREAMING_SNAKE_CASE							(	self			:				Any      )->	Dict:







              """simple docstring"""
              UpperCamelCase       			=		self.tokenizer._build_translation_inputs(
                  "A test"							,   return_tensors="pt"							,   src_lang="en_XX"							,   tgt_lang="java"      )

              self.assertEqual(
                  nested_simplify(UpperCAmelCase_      )							,   {
                      # A, test, EOS, en_XX
                      "input_ids": [[150, 242, 2, 50_003]],
                      "attention_mask": [[1, 1, 1, 1]],
                      # java
                      "forced_bos_token_id": 50_001,
                  }							,   )







"""simple docstring"""


import logging
import os
from dataclasses import dataclass, field
from functools import partial
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import List, Optional

import faiss
import torch
from datasets import Features, Sequence, Value, load_dataset

from transformers import DPRContextEncoder, DPRContextEncoderTokenizerFast, HfArgumentParser


SCREAMING_SNAKE_CASE			  =  logging.getLogger(__name__)
torch.set_grad_enabled(False)
SCREAMING_SNAKE_CASE			  =  """cuda""" if torch.cuda.is_available() else """cpu"""



def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_=1_00		,   UpperCAmelCase_=" "					)->				List[str]:







       """simple docstring"""
       UpperCamelCase       			=		text.split(UpperCAmelCase_					)
       return [character.join(text[i : i + n]					).strip() for i in range(0		,   len(UpperCAmelCase_					)		,   UpperCAmelCase_					)]



def 						lowerCamelCase__      (				UpperCAmelCase_					)->				dict:







       """simple docstring"""
       UpperCamelCase			,							UpperCamelCase       			=		[], []
       for title, text in zip(documents["title"]		,   documents["text"]					):
              if text is not None:
                     for passage in split_text(UpperCAmelCase_					):
                            titles.append(title if title is not None else ""					)
                            texts.append(UpperCAmelCase_					)
       return {"title": titles, "text": texts}



def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				dict:







       """simple docstring"""
       UpperCamelCase       			=		ctx_tokenizer(
           documents["title"]		,   documents["text"]		,   truncation=UpperCAmelCase_		,   padding="longest"		,   return_tensors="pt"					)["input_ids"]
       UpperCamelCase       			=		ctx_encoder(input_ids.to(device=UpperCAmelCase_					)		,   return_dict=UpperCAmelCase_					).pooler_output
       return {"embeddings": embeddings.detach().cpu().numpy()}



def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_		,   )->				List[str]:







       """simple docstring"""
       ######################################
       logger.info("Step 1 - Create the dataset"					)
       ######################################

       # The dataset needed for RAG must have three columns:
       # - title (string): title of the document
       # - text (string): text of a passage of the document
       # - embeddings (array of dimension d): DPR representation of the passage
       # Let's say you have documents in tab-separated csv files with columns "title" and "text"
       assert os.path.isfile(rag_example_args.csv_path					), "Please provide a valid path to a csv file"

       # You can load a Dataset object this way
       UpperCamelCase       			=		load_dataset(
           "csv"		,   data_files=[rag_example_args.csv_path]		,   split="train"		,   delimiter="\t"		,   column_names=["title", "text"]					)

       # More info about loading csv files in the documentation: https://huggingface.co/docs/datasets/loading_datasets.html?highlight=csv#csv-files

       # Then split the documents into passages of 100 words
       UpperCamelCase       			=		dataset.map(UpperCAmelCase_		,   batched=UpperCAmelCase_		,   num_proc=processing_args.num_proc					)

       # And compute the embeddings
       UpperCamelCase       			=		DPRContextEncoder.from_pretrained(rag_example_args.dpr_ctx_encoder_model_name					).to(device=UpperCAmelCase_					)
       UpperCamelCase       			=		DPRContextEncoderTokenizerFast.from_pretrained(rag_example_args.dpr_ctx_encoder_model_name					)
       UpperCamelCase       			=		Features(
           {"text": Value("string"					), "title": Value("string"					), "embeddings": Sequence(Value("float32"					)					)}					)  # optional, save as float32 instead of float64 to save space
       UpperCamelCase       			=		dataset.map(
           partial(UpperCAmelCase_		,   ctx_encoder=UpperCAmelCase_		,   ctx_tokenizer=UpperCAmelCase_					)		,   batched=UpperCAmelCase_		,   batch_size=processing_args.batch_size		,   features=UpperCAmelCase_		,   )

       # And finally save your dataset
       UpperCamelCase       			=		os.path.join(rag_example_args.output_dir		,   "my_knowledge_dataset"					)
       dataset.save_to_disk(UpperCAmelCase_					)
       # from datasets import load_from_disk
       # dataset = load_from_disk(passages_path)  # to reload the dataset

       ######################################
       logger.info("Step 2 - Index the dataset"					)
       ######################################

       # Let's use the Faiss implementation of HNSW for fast approximate nearest neighbor search
       UpperCamelCase       			=		faiss.IndexHNSWFlat(index_hnsw_args.d		,   index_hnsw_args.m		,   faiss.METRIC_INNER_PRODUCT					)
       dataset.add_faiss_index("embeddings"		,   custom_index=UpperCAmelCase_					)

       # And save the index
       UpperCamelCase       			=		os.path.join(rag_example_args.output_dir		,   "my_knowledge_dataset_hnsw_index.faiss"					)
       dataset.get_index("embeddings"					).save(UpperCAmelCase_					)
       # dataset.load_faiss_index("embeddings", index_path)  # to reload the index



@dataclass
class 	__a	:
       UpperCamelCase_		:       str				=      field(
           default=str(Path(_lowerCAmelCase						).parent / '''test_run''' / '''dummy-kb''' / '''my_knowledge_dataset.csv'''						)     ,  metadata={'''help''': '''Path to a tab-separated csv file with columns \'title\' and \'text\''''}     ,  )
       UpperCamelCase_		:       Optional[str]				=      field(
           default=_lowerCAmelCase     ,  metadata={'''help''': '''Question that is passed as input to RAG. Default is \'What does Moses\' rod turn into ?\'.'''}     ,  )
       UpperCamelCase_		:       str				=      field(
           default='''facebook/rag-sequence-nq'''     ,  metadata={'''help''': '''The RAG model to use. Either \'facebook/rag-sequence-nq\' or \'facebook/rag-token-nq\''''}     ,  )
       UpperCamelCase_		:       str				=      field(
           default='''facebook/dpr-ctx_encoder-multiset-base'''     ,  metadata={
               '''help''': (
                   '''The DPR context encoder model to use. Either \'facebook/dpr-ctx_encoder-single-nq-base\' or'''
                   ''' \'facebook/dpr-ctx_encoder-multiset-base\''''
               )
           }     ,  )
       UpperCamelCase_		:       Optional[str]				=      field(
           default=str(Path(_lowerCAmelCase						).parent / '''test_run''' / '''dummy-kb'''						)     ,  metadata={'''help''': '''Path to a directory where the dataset passages and the index will be saved'''}     ,  )





@dataclass
class 	__a	:
       UpperCamelCase_		:       Optional[int]				=      field(
           default=_lowerCAmelCase     ,  metadata={
               '''help''': '''The number of processes to use to split the documents into passages. Default is single process.'''
           }     ,  )
       UpperCamelCase_		:       int				=      field(
           default=16     ,  metadata={
               '''help''': '''The batch size to use when computing the passages embeddings using the DPR context encoder.'''
           }     ,  )





@dataclass
class 	__a	:
       UpperCamelCase_		:       int				=      field(
           default=768     ,  metadata={'''help''': '''The dimension of the embeddings to pass to the HNSW Faiss index.'''}     ,  )
       UpperCamelCase_		:       int				=      field(
           default=128     ,  metadata={
               '''help''': (
                   '''The number of bi-directional links created for every new element during the HNSW index construction.'''
               )
           }     ,  )


if __name__ == "__main__":
      logging.basicConfig(level=logging.WARNING)
      logger.setLevel(logging.INFO)

      SCREAMING_SNAKE_CASE			  =  HfArgumentParser((RagExampleArguments, ProcessingArguments, IndexHnswArguments))
      SCREAMING_SNAKE_CASE  ,   SCREAMING_SNAKE_CASE  ,   SCREAMING_SNAKE_CASE			  =  parser.parse_args_into_dataclasses()
      with TemporaryDirectory() as tmp_dir:
            SCREAMING_SNAKE_CASE			  =  rag_example_args.output_dir or tmp_dir
            main(rag_example_args, processing_args, index_hnsw_args)





