{"record":{"id":"3256084b53428a6a","repo":"chroma-core/chroma","slug":"preferred-providers-must-be-unique","errorCode":null,"errorMessage":"Preferred providers must be unique","messagePattern":"Preferred providers must be unique","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/onnx_mini_lm_l6_v2.py","lineNumber":64,"sourceCode":"\n    def __init__(self, preferred_providers: Optional[List[str]] = None) -> None:\n        \"\"\"\n        Initialize the ONNXMiniLM_L6_V2 embedding function.\n\n        Args:\n            preferred_providers (List[str], optional): The preferred ONNX runtime providers.\n                Defaults to None.\n        \"\"\"\n        # convert the list to set for unique values\n        if preferred_providers and not all(\n            [isinstance(i, str) for i in preferred_providers]\n        ):\n            raise ValueError(\"Preferred providers must be a list of strings\")\n        # check for duplicate providers\n        if preferred_providers and len(preferred_providers) != len(\n            set(preferred_providers)\n        ):\n            raise ValueError(\"Preferred providers must be unique\")\n\n        self._preferred_providers = preferred_providers\n\n        try:\n            # Equivalent to import onnxruntime\n            self.ort = importlib.import_module(\"onnxruntime\")\n        except ImportError:\n            raise ValueError(\n                \"The onnxruntime python package is not installed. Please install it with `pip install onnxruntime`\"\n            )\n        try:\n            # Equivalent to from tokenizers import Tokenizer\n            self.Tokenizer = importlib.import_module(\"tokenizers\").Tokenizer\n        except ImportError:\n            raise ValueError(\n                \"The tokenizers python package is not installed. Please install it with `pip install tokenizers`\"\n            )\n        try:","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/onnx_mini_lm_l6_v2.py#L46-L82","documentation":"The second constructor check in ONNXMiniLM_L6_V2 compares len(preferred_providers) with len(set(preferred_providers)); duplicates mean the same execution provider would be registered twice in the ONNX InferenceSession, which is meaningless and usually signals a config-generation bug, so it raises ValueError(\"Preferred providers must be unique\"). Order still matters (first match wins in ORT), so dedupe must preserve order.","triggerScenarios":"ONNXMiniLM_L6_V2(preferred_providers=[\"CPUExecutionProvider\", \"CPUExecutionProvider\"]); concatenating a user provider list with a default fallback list without deduping (e.g. cfg_providers + [\"CPUExecutionProvider\"]); config templating that injects the same provider for GPU and CPU sections.","commonSituations":"Appending CPUExecutionProvider as a fallback after user-specified providers that already include it; YAML anchors reusing a provider list twice; environment-specific overrides merged on top of defaults with the same entry.","solutions":["Dedupe while preserving order before constructing: seen=set(); providers=[p for p in providers if not (p in seen or seen.add(p))]","Fix the config merge that produces the duplicate (don't append the default CPU fallback if it is already present)","Drop the argument entirely (pass None) to let the EF use all available providers"],"exampleFix":"// before\nfn = ONNXMiniLM_L6_V2(preferred_providers=[\"CUDAExecutionProvider\", \"CPUExecutionProvider\", \"CPUExecutionProvider\"])  # ValueError\n\n// after\nproviders = list(dict.fromkeys([\"CUDAExecutionProvider\", \"CPUExecutionProvider\", \"CPUExecutionProvider\"]))\nfn = ONNXMiniLM_L6_V2(preferred_providers=providers)","handlingStrategy":"validation","validationCode":"providers = list(dict.fromkeys(providers)) if providers else providers  # order-preserving dedupe\nfn = ONNXMiniLM_L6_V2(preferred_providers=providers)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When appending a CPU fallback to user providers, check it isn't already present","Dedupe with dict.fromkeys() to preserve provider priority order","Write a unit test asserting len(providers) == len(set(providers)) for generated configs"],"tags":["onnx","embedding-function","config-validation","duplicate-values","chroma"],"backgroundTag":"invalid-config-value","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}