Skip to content

Commit 46b51fe

Browse files
RichmondAlakeclaude
andcommitted
fix(embeddings): Ollama embeddings via native client; ollama in base deps
The default zero-config stack crashed on a lean install: `memorizz` -> "langchain_ollama is required for Ollama embeddings". Two missing-dependency problems: 1. The Ollama embedding provider used `langchain_ollama` (only in the `[ollama]` extra). Rewrite it to use the native `ollama` client's embeddings endpoint — the same SDK the LLM side already uses. langchain_ollama is dropped entirely. 2. The `ollama` client wasn't a base dependency, so even without (1) a bare `pip install memorizz` couldn't run the default Ollama stack. Move `ollama>=0.6.0` into base (small; httpx already comes via openai). No torch. Why this slipped through testing: my dev env (memorizz_local) had langchain_ollama installed (from the [all] extra), and I tested via that interpreter rather than the shipped CLI's lean install — so the missing dep never surfaced. Now verified in a clean 3.11 venv from the wheel: ollama present, langchain_ollama/torch absent, build_session_agent + a 768-dim embedding work. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c7c855d commit 46b51fe

3 files changed

Lines changed: 33 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
### Fixes
2424

25+
* **Default local stack works on a lean install.** Ollama embeddings required
26+
`langchain_ollama` (an optional extra) and the `ollama` client wasn't a base
27+
dependency, so a plain `pip install memorizz` + `memorizz` crashed with
28+
"langchain_ollama is required for Ollama embeddings". Embeddings now use the
29+
native `ollama` client, and `ollama` is a base dependency (still no langchain,
30+
no torch).
2531
* Agents executing a scheduled automation no longer wander into managing
2632
automations — automation-management tools are suppressed for the run (fixes
2733
off-task / empty outputs from smaller models).

pyproject.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ dependencies = [
4646
"rich>=13.7.0",
4747
"prompt_toolkit>=3.0.0",
4848
"platformdirs>=4.0.0",
49+
# Ollama daemon SDK (LLM *and* embeddings via the native client). Kept in
50+
# base, not an extra, so the default zero-config local stack works on a bare
51+
# `pip install memorizz` with a running Ollama daemon. Small (httpx, already
52+
# pulled by openai) — none of the heavy local-ML stack.
53+
"ollama>=0.6.0",
4954
# NOTE: the heavy local-ML stack (transformers / sentence-transformers /
5055
# accelerate / huggingface-hub) moved OUT of base into the `huggingface`
5156
# extra so the default install stays lean (no multi-GB torch download).
@@ -62,10 +67,8 @@ cli = []
6267
# Fully-local stack: Ollama LLM + Ollama embeddings + FAISS filesystem memory.
6368
local = ["memorizz[ollama]", "memorizz[filesystem]"]
6469
anthropic = ["anthropic>=0.26.0"]
65-
# langchain-ollama 1.x dropped the `timeout=` constructor kwarg; the embedding
66-
# provider has a fallback for it but we still want the ollama daemon SDK at a
67-
# version that knows about Gemma 4 tags (>=0.6.0).
68-
ollama = ["langchain_ollama>=1.0.0", "ollama>=0.6.0"]
70+
# Ollama ships in base now; this alias keeps `pip install memorizz[ollama]` valid.
71+
ollama = ["ollama>=0.6.0"]
6972
voyageai = ["voyageai"]
7073
huggingface = [
7174
"numpy>=1.21,<2",
@@ -113,7 +116,6 @@ all = [
113116
"anthropic>=0.26.0",
114117
"pymongo>=4.0.0",
115118
"oracledb>=2.0.0",
116-
"langchain_ollama>=1.0.0",
117119
"ollama>=0.6.0",
118120
"voyageai",
119121
"faiss-cpu>=1.7.4",

src/memorizz/embeddings/ollama/provider.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,38 @@ def __init__(self, config: Dict[str, Any] = None):
5454
)
5555

5656
def _init_client(self):
57-
"""Initialize the Ollama embeddings client."""
57+
"""Initialize the native Ollama client (no langchain dependency)."""
5858
try:
59-
from langchain_ollama import OllamaEmbeddings
59+
import ollama
6060
except ImportError:
6161
raise ImportError(
62-
"langchain_ollama is required for Ollama embeddings. "
63-
"Install it with: pip install langchain-ollama"
62+
"The 'ollama' package is required for Ollama embeddings. Install "
63+
"it with: pip install ollama (or: pip install memorizz[ollama])"
6464
)
6565

66-
# langchain-ollama >=1.0 dropped the `timeout` constructor arg.
66+
client_kwargs: Dict[str, Any] = {"host": self.base_url}
67+
if self.timeout:
68+
client_kwargs["timeout"] = self.timeout
6769
try:
68-
self.embeddings = OllamaEmbeddings(
69-
model=self.model, base_url=self.base_url, timeout=self.timeout
70-
)
71-
except (TypeError, ValueError):
72-
self.embeddings = OllamaEmbeddings(model=self.model, base_url=self.base_url)
70+
self.client = ollama.Client(**client_kwargs)
71+
except TypeError:
72+
self.client = ollama.Client(host=self.base_url)
73+
74+
def _embed_one(self, text: str) -> List[float]:
75+
"""Embed a single string via the native client (attr- or dict-style resp)."""
76+
resp = self.client.embeddings(model=self.model, prompt=text)
77+
vector = getattr(resp, "embedding", None)
78+
if vector is None and isinstance(resp, dict):
79+
vector = resp.get("embedding")
80+
return list(vector or [])
7381

7482
def _probe_dimensions(self):
7583
"""Probe the actual dimensions of the model by generating a test embedding."""
7684
if self._dimensions_probed:
7785
return
7886

7987
try:
80-
test_embedding = self.embeddings.embed_query("test")
88+
test_embedding = self._embed_one("test")
8189
if test_embedding:
8290
actual_dimensions = len(test_embedding)
8391
if actual_dimensions != self.dimensions:
@@ -126,7 +134,7 @@ def get_embedding(self, text: str, **kwargs) -> List[float]:
126134
self._probe_dimensions()
127135

128136
# Generate embedding
129-
embedding = self.embeddings.embed_query(text)
137+
embedding = self._embed_one(text)
130138
return embedding
131139
except Exception as e:
132140
logger.error(f"Error generating Ollama embedding: {str(e)}")

0 commit comments

Comments
 (0)