Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

Fix ollama embeddings for remote machine (#1394)

Dev Khant4070fc1bf07e
diff --git a/embedchain/config/embedder/ollama.py b/embedchain/config/embedder/ollama.py
index b08b39d7e..c0a5f1dea 100644
--- a/embedchain/config/embedder/ollama.py
+++ b/embedchain/config/embedder/ollama.py
@@ -12,4 +12,4 @@ class OllamaEmbedderConfig(BaseEmbedderConfig):
base_url: Optional[str] = None,
):
super().__init__(model)
- self.base_url = base_url or "http://127.0.0.1:11434"
+ self.base_url = base_url or "http://localhost:11434"
diff --git a/embedchain/embedder/ollama.py b/embedchain/embedder/ollama.py
index a70e402e3..9e4ada473 100644
--- a/embedchain/embedder/ollama.py
+++ b/embedchain/embedder/ollama.py
@@ -2,7 +2,7 @@ import logging
from typing import Optional
try:
- import ollama
+ from ollama import Client
except ImportError:
raise ImportError("Ollama Embedder requires extra dependencies. Install with `pip install ollama`") from None
@@ -19,11 +19,12 @@ class OllamaEmbedder(BaseEmbedder):
def __init__(self, config: Optional[OllamaEmbedderConfig] = None):
super().__init__(config=config)
- local_models = ollama.list()["models"]
+ client = Client(host=config.base_url)
+ local_models = client.list()["models"]
if not any(model.get("name") == self.config.model for model in local_models):
logger.info(f"Pulling {self.config.model} from Ollama!")
- ollama.pull(self.config.model)
- embeddings = OllamaEmbeddings(model=self.config.model, base_url=self.config.base_url)
+ client.pull(self.config.model)
+ embeddings = OllamaEmbeddings(model=self.config.model, base_url=config.base_url)
embedding_fn = BaseEmbedder._langchain_default_concept(embeddings)
self.set_embedding_fn(embedding_fn=embedding_fn)