Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.
Python agent-evaluationaiai-alignmentai-evaluationai-governanceai-safetyclidiagnostic-tooleu-ai-acthallucination-detectioniso-42001llm-evaluationllm-securitynist-ai-rmfowasp-llmprompt-injectionpythonresponsible-airisk-assessmentrisk-management
fix: reuse the embedding model across classifications (#234)
Rudy Mizrahi Celeklib6181b6a8bed
diff --git a/ifixai/evaluation/embedding_classifier.py b/ifixai/evaluation/embedding_classifier.pyindex 7d00a85..16e6f15 100644--- a/ifixai/evaluation/embedding_classifier.py+++ b/ifixai/evaluation/embedding_classifier.py@@ -89,7 +89,8 @@ class EmbeddingClassifier:return self._embedding_fnif _sentence_transformers_available:model = _st_lib.SentenceTransformer("all-MiniLM-L6-v2")- return lambda text: model.encode(text).tolist()+ self._embedding_fn = lambda text: model.encode(text).tolist()+ return self._embedding_fnreturn Nonedef _build_centroids(self, embed) -> dict[ResponseClass, list[float]]:diff --git a/ifixai/tests/test_embedding_model_reuse.py b/ifixai/tests/test_embedding_model_reuse.pynew file mode 100644index 0000000..8392738--- /dev/null+++ b/ifixai/tests/test_embedding_model_reuse.py@@ -0,0 +1,26 @@+from types import SimpleNamespace++from ifixai.evaluation import embedding_classifier as module+from ifixai.evaluation.response_classifier import ResponseClass+++def test_default_model_is_loaded_once_per_classifier(monkeypatch):+ loads = []++ class Model:+ def __init__(self, name):+ loads.append(name)++ def encode(self, text):+ return SimpleNamespace(tolist=lambda: [1.0, 0.0])++ monkeypatch.setattr(module, "_sentence_transformers_available", True)+ monkeypatch.setattr(+ module, "_st_lib", SimpleNamespace(SentenceTransformer=Model), raising=False+ )+ classifier = module.EmbeddingClassifier(+ exemplars={ResponseClass.ANSWER: ["approved"]}+ )+ assert classifier.classify("first") == ResponseClass.ANSWER+ assert classifier.classify("second") == ResponseClass.ANSWER+ assert loads == ["all-MiniLM-L6-v2"]