77from llama_index .core .embeddings .mock_embed_model import MockEmbedding
88from llama_index .embeddings .openai import OpenAIEmbedding
99from llama_index .embeddings .openai import OpenAIEmbeddingModelType
10+ from llama_index .embeddings .ollama import OllamaEmbedding
1011from langchain_openai .embeddings import OpenAIEmbeddings
1112
1213from autorag import LazyInit
@@ -35,6 +36,7 @@ def _get_vector(self) -> List[float]:
3536 "mock" : LazyInit (MockEmbeddingRandom , embed_dim = 768 ),
3637 # langchain
3738 "openai_langchain" : LazyInit (OpenAIEmbeddings ),
39+ "ollama" : LazyInit (OllamaEmbedding ),
3840}
3941
4042try :
@@ -67,11 +69,13 @@ def _get_vector(self) -> List[float]:
6769
6870class EmbeddingModel :
6971 @staticmethod
70- def load (config : Union [str , List [Dict ]]):
72+ def load (config : Union [str , Dict , List [Dict ]]):
7173 if isinstance (config , str ):
7274 return EmbeddingModel .load_from_str (config )
73- elif isinstance (config , list ):
75+ elif isinstance (config , dict ):
7476 return EmbeddingModel .load_from_dict (config )
77+ elif isinstance (config , list ):
78+ return EmbeddingModel .load_from_list (config )
7579 else :
7680 raise ValueError ("Invalid type of config" )
7781
@@ -83,11 +87,17 @@ def load_from_str(name: str):
8387 raise ValueError (f"Embedding model '{ name } ' is not supported" )
8488
8589 @staticmethod
86- def load_from_dict (option : List [dict ]):
90+ def load_from_list (option : List [dict ]):
91+ if len (option ) != 1 :
92+ raise ValueError ("Only one embedding model is supported" )
93+ return EmbeddingModel .load_from_dict (option [0 ])
94+
95+ @staticmethod
96+ def load_from_dict (option : dict ):
8797 def _check_keys (target : dict ):
8898 if "type" not in target or "model_name" not in target :
8999 raise ValueError ("Both 'type' and 'model_name' must be provided" )
90- if target ["type" ] not in ["openai" , "huggingface" , "mock" ]:
100+ if target ["type" ] not in ["openai" , "huggingface" , "mock" , "ollama" ]:
91101 raise ValueError (
92102 f"Embedding model type '{ target ['type' ]} ' is not supported"
93103 )
@@ -102,17 +112,16 @@ def _get_huggingface_class():
102112 return None
103113 return getattr (module , "HuggingFaceEmbedding" , None )
104114
105- if len (option ) != 1 :
106- raise ValueError ("Only one embedding model is supported" )
107- _check_keys (option [0 ])
115+ _check_keys (option )
108116
109- model_options = option [ 0 ]
117+ model_options = option
110118 model_type = model_options .pop ("type" )
111119
112120 embedding_map = {
113121 "openai" : OpenAIEmbedding ,
114122 "mock" : MockEmbeddingRandom ,
115123 "huggingface" : _get_huggingface_class (),
124+ "ollama" : OllamaEmbedding ,
116125 }
117126
118127 embedding_class = embedding_map .get (model_type )
0 commit comments