Repository: Marker-Inc-Korea/AutoRAG

Issue:
[BUG] Unexpected keyword argument 'embedding_model' for passage filter module
**Describe the bug**
unexpected keyword argument 'embedding_model' error occurred in passage filter module such as `SimilarityThresholdCutoff._pure()`

**To Reproduce**
1. set `embedding_model` of `similarity_threshold_cutoff` in config.yaml
2. Run autorag

**Expected behavior**
Succeed

**Full Error log**
TypeError: SimilarityThresholdCutoff._pure() got an unexpected keyword argument 'embedding_model'

**Code that bug is happened**
After init `cls` instance, `embedding_model` key must be popped from `kwargs`. But `kwargs` in `BaseModule` and `SimilarityThresholdCutoff` have different id like deep copy.
```python
class BaseModule(metaclass=ABCMeta):
    @classmethod
        def run_evaluator(
            cls,
            project_dir: Union[str, Path],
            previous_result: pd.DataFrame,
            *args,
            **kwargs,
        ):
            instance = cls(project_dir, *args, **kwargs)
            result = instance.pure(previous_result, *args, **kwargs)
            del instance
            return result
class SimilarityThresholdCutoff(BasePassageFilter):
    def __init__(self, project_dir: str, *args, **kwargs):
        super().__init__(project_dir, *args, **kwargs)
        embedding_model_str = kwargs.pop("embedding_model", "openai")
        self.embedding_model = embedding_models[embedding_model_str]()
```

Discussion:
vkehfdl1: @rjwharry Thank you for the PR and letting us know the error!
I tested and fixed the error using `pop_params` 
Thank you very much :)

Patch:
diff --git a/autorag/nodes/generator/vllm.py b/autorag/nodes/generator/vllm.py
index d612857..c6684d8 100644
--- a/autorag/nodes/generator/vllm.py
+++ b/autorag/nodes/generator/vllm.py
@@ -41,7 +41,8 @@ class Vllm(BaseGenerator):
 
 			if torch.cuda.is_available():
 				from vllm.distributed.parallel_state import (
-					destroy_model_parallel, destroy_distributed_environment
+					destroy_model_parallel,
+					destroy_distributed_environment,
 				)
 
 				destroy_model_parallel()
diff --git a/autorag/nodes/passagefilter/similarity_percentile_cutoff.py b/autorag/nodes/passagefilter/similarity_percentile_cutoff.py
index 9dd6ebb..cbed737 100644
--- a/autorag/nodes/passagefilter/similarity_percentile_cutoff.py
+++ b/autorag/nodes/passagefilter/similarity_percentile_cutoff.py
@@ -11,7 +11,7 @@ from autorag.nodes.passagefilter.similarity_threshold_cutoff import (
 	embedding_query_content,
 )
 from autorag.utils import result_to_dataframe
-from autorag.utils.util import empty_cuda_cache
+from autorag.utils.util import empty_cuda_cache, pop_params
 
 
 class SimilarityPercentileCutoff(BasePassageFilter):
@@ -21,7 +21,7 @@ class SimilarityPercentileCutoff(BasePassageFilter):
 
 		:param project_dir: The project directory to use for initializing the module
 		:param embedding_model: The embedding model string to use for calculating similarity
-			Default is "openai" which is OpenAI text-embedding-ada-002 embedding model.
+		        Default is "openai" which is OpenAI text-embedding-ada-002 embedding model.
 		"""
 		super().__init__(project_dir, *args, **kwargs)
 		embedding_model_str = kwargs.pop("embedding_model", "openai")
@@ -34,9 +34,10 @@ class SimilarityPercentileCutoff(BasePassageFilter):
 		empty_cuda_cache()
 
 	@result_to_dataframe(["retrieved_contents", "retrieved_ids", "retrieve_scores"])
-	def pure(self, previous_result: pd.DataFrame, *args, **kwargs):
+	def pure(self, previous_result: pd.DataFrame, **kwargs):
 		queries, contents, scores, ids = self.cast_to_run(previous_result)
-		return self._pure(queries, contents, scores, ids, *args, **kwargs)
+		kwargs = pop_params(self._pure, kwargs)
+		return self._pure(queries, contents, scores, ids, **kwargs)
 
 	def _pure(
 		self,
diff --git a/autorag/nodes/passagefilter/similarity_threshold_cutoff.py b/autorag/nodes/passagefilter/similarity_threshold_cutoff.py
index 96f99f1..29f0b2e 100644
--- a/autorag/nodes/passagefilter/similarity_threshold_cutoff.py
+++ b/autorag/nodes/passagefilter/similarity_threshold_cutoff.py
@@ -8,8 +8,9 @@ from autorag.evaluation.metric.util import calculate_cosine_similarity
 from autorag.nodes.passagefilter.base import BasePassageFilter
 from autorag.utils.util import (
 	embedding_query_content,
-	result_to_dataframe,
 	empty_cuda_cache,
+	result_to_dataframe,
+	pop_params,
 )
 
 
@@ -20,10 +21,10 @@ class SimilarityThresholdCutoff(BasePassageFilter):
 
 		:param project_dir: The project directory to use for initializing the module
 		:param embedding_model: The embedding model string to use for calculating similarity
-			Default is "openai" which is OpenAI text-embedding-ada-002 embedding model.
+		        Default is "openai" which is OpenAI text-embedding-ada-002 embedding model.
 		"""
 		super().__init__(project_dir, *args, **kwargs)
-		embedding_model_str = kwargs.pop("embedding_model", "openai")
+		embedding_model_str = kwargs.get("embedding_model", "openai")
 		self.embedding_model = embedding_models[embedding_model_str]()
 
 	def __del__(self):
@@ -33,6 +34,7 @@ class SimilarityThresholdCutoff(BasePassageFilter):
 
 	@result_to_dataframe(["retrieved_contents", "retrieved_ids", "retrieve_scores"])
 	def pure(self, previous_result: pd.DataFrame, *args, **kwargs):
+		kwargs = pop_params(self._pure, kwargs)
 		queries, contents, scores, ids = self.cast_to_run(previous_result)
 		return self._pure(queries, contents, scores, ids, *args, **kwargs)
 
diff --git a/autorag/vectordb/milvus.py b/autorag/vectordb/milvus.py
index 7a4a1c9..0bc4103 100644
--- a/autorag/vectordb/milvus.py
+++ b/autorag/vectordb/milvus.py
@@ -32,7 +32,7 @@ class Milvus(BaseVectorStore):
 		user: str = "",
 		password: str = "",
 		timeout: Optional[float] = None,
-  		params: Dict[str, Any] = {},	
+		params: Dict[str, Any] = {},
 	):
 		super().__init__(embedding_model, similarity_metric, embedding_batch)
 
@@ -49,7 +49,7 @@ class Milvus(BaseVectorStore):
 		self.timeout = timeout
 		self.params = params
 		self.index_type = index_type
-  
+
 		# Set Collection
 		if not utility.has_collection(collection_name, timeout=timeout):
 			# Get the dimension of the embeddings


Test patch:
diff --git a/tests/autorag/nodes/passagefilter/test_similarity_percentile_cutoff.py b/tests/autorag/nodes/passagefilter/test_similarity_percentile_cutoff.py
index 7b638f0..7e8ca80 100644
--- a/tests/autorag/nodes/passagefilter/test_similarity_percentile_cutoff.py
+++ b/tests/autorag/nodes/passagefilter/test_similarity_percentile_cutoff.py
@@ -56,6 +56,9 @@ def test_similarity_percentile_cutoff(similarity_percentile_cutoff_instance):
 )
 def test_similarity_percentile_cutoff_node():
 	result_df = SimilarityPercentileCutoff.run_evaluator(
-		project_dir=project_dir, previous_result=previous_result, percentile=0.9
+		project_dir=project_dir,
+		previous_result=previous_result,
+		percentile=0.9,
+		embedding_model="openai_embed_3_large",
 	)
 	base_passage_filter_node_test(result_df)
diff --git a/tests/autorag/nodes/passagefilter/test_similarity_threshold_cutoff.py b/tests/autorag/nodes/passagefilter/test_similarity_threshold_cutoff.py
index 224891b..495a466 100644
--- a/tests/autorag/nodes/passagefilter/test_similarity_threshold_cutoff.py
+++ b/tests/autorag/nodes/passagefilter/test_similarity_threshold_cutoff.py
@@ -49,6 +49,10 @@ def test_similarity_threshold_cutoff(similarity_threshold_cutoff_instance):
 )
 def test_similarity_threshold_cutoff_node():
 	result_df = SimilarityThresholdCutoff.run_evaluator(
-		project_dir=project_dir, previous_result=previous_result, threshold=0.9
+		project_dir=project_dir,
+		previous_result=previous_result,
+		threshold=0.9,
+		embedding_model="openai_embed_3_large",
+		marker="big-boy",
 	)
 	base_passage_filter_node_test(result_df)