11import os
2- from typing import Any , Dict , Optional , cast
2+ from typing import Any , cast
33
44from chromadb import Documents , EmbeddingFunction , Embeddings
55from chromadb .api .types import validate_embedding_function
@@ -23,7 +23,7 @@ def __init__(self):
2323
2424 def configure_embedder (
2525 self ,
26- embedder_config : Optional [ Dict [ str , Any ]] = None ,
26+ embedder_config : dict [ str , Any ] | None = None ,
2727 ) -> EmbeddingFunction :
2828 """Configures and returns an embedding function based on the provided config."""
2929 if embedder_config is None :
@@ -42,9 +42,9 @@ def configure_embedder(
4242 embedding_function = self .embedding_functions [provider ]
4343 except ImportError as e :
4444 missing_package = str (e ).split ()[- 1 ]
45- raise ImportError (
45+ raise ImportError (
4646 f"{ missing_package } is not installed. Please install it with: pip install { missing_package } "
47- )
47+ ) from e
4848
4949 return (
5050 embedding_function (config )
@@ -147,7 +147,7 @@ def _configure_cohere(config, model_name):
147147
148148 @staticmethod
149149 def _configure_voyageai (config , model_name ):
150- from chromadb .utils .embedding_functions .voyageai_embedding_function import (
150+ from chromadb .utils .embedding_functions .voyageai_embedding_function import ( # type: ignore[import-not-found]
151151 VoyageAIEmbeddingFunction ,
152152 )
153153
@@ -181,9 +181,11 @@ def _configure_huggingface(config, model_name):
181181 @staticmethod
182182 def _configure_watson (config , model_name ):
183183 try :
184- import ibm_watsonx_ai .foundation_models as watson_models
185- from ibm_watsonx_ai import Credentials
186- from ibm_watsonx_ai .metanames import EmbedTextParamsMetaNames as EmbedParams
184+ import ibm_watsonx_ai .foundation_models as watson_models # type: ignore[import-not-found]
185+ from ibm_watsonx_ai import Credentials # type: ignore[import-not-found]
186+ from ibm_watsonx_ai .metanames import ( # type: ignore[import-not-found]
187+ EmbedTextParamsMetaNames as EmbedParams ,
188+ )
187189 except ImportError as e :
188190 raise ImportError (
189191 "IBM Watson dependencies are not installed. Please install them to use Watson embedding."
@@ -225,7 +227,7 @@ def _configure_custom(config):
225227 validate_embedding_function (custom_embedder )
226228 return custom_embedder
227229 except Exception as e :
228- raise ValueError (f"Invalid custom embedding function: { str ( e ) } " )
230+ raise ValueError (f"Invalid custom embedding function: { e !s } " ) from e
229231 elif callable (custom_embedder ):
230232 try :
231233 instance = custom_embedder ()
@@ -236,7 +238,7 @@ def _configure_custom(config):
236238 "Custom embedder does not create an EmbeddingFunction instance"
237239 )
238240 except Exception as e :
239- raise ValueError (f"Error instantiating custom embedder: { str ( e ) } " )
241+ raise ValueError (f"Error instantiating custom embedder: { e !s } " ) from e
240242 else :
241243 raise ValueError (
242244 "Custom embedder must be an instance of `EmbeddingFunction` or a callable that creates one"
0 commit comments