Commit 9947b18
authored
feat: add Ollama text vectorizer (#617)
## Summary
Adds `OllamaTextVectorizer` support for local Ollama embedding models.
This PR includes Ollama optional dependency wiring, a sync/async
`OllamaTextVectorizer` implementation, vectorizer registry/from-dict
support for `type: "ollama"`, mocked unit tests, and opt-in real Ollama
integration tests guarded by `REDISVL_TEST_OLLAMA=1`.
## Usage
```python
from redisvl.utils.vectorize import OllamaTextVectorizer
vectorizer = OllamaTextVectorizer(model="nomic-embed-text")
embedding = vectorizer.embed("hello world")
```
To run the real Ollama integration tests locally:
```bash
ollama pull nomic-embed-text
REDISVL_TEST_OLLAMA=1 uv run pytest tests/integration/test_ollama_vectorizer_integration.py
```
Testing:
```bash
uv run pytest tests/unit/test_ollama_vectorizer.py tests/integration/test_ollama_vectorizer_integration.py -q
REDISVL_TEST_OLLAMA=1 uv run pytest tests/integration/test_ollama_vectorizer_integration.py -q
uv run black --check ./redisvl ./tests
uv run isort ./redisvl ./tests --check-only --profile black
uv lock --check
uv run mypy redisvl
make test
```
Full repo test result:
<img width="556" height="51" alt="image"
src="https://github.com/user-attachments/assets/0b970471-df71-4f9e-ad8c-69b49b6e047a"
/>
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Additive embedding provider with optional install; no changes to auth,
Redis core, or existing vectorizer behavior beyond new enum and factory
branch.
>
> **Overview**
> Adds **local Ollama** as a first-class text embedding provider in
RedisVL.
>
> A new **`OllamaTextVectorizer`** talks to a running Ollama daemon
(sync/async `embed` / `embed_many`, optional `host`, dimension probing
at init, retries). It is exported from `redisvl.utils.vectorize`,
registered as **`Vectorizers.ollama`**, and constructible via
**`vectorizer_from_dict`** with `type: "ollama"`.
>
> Packaging adds optional **`redisvl[ollama]`** / `all` extra
(`ollama>=0.5.4`) and bumps the package to **0.18.2** in the lockfile.
The vectorizers user guide gains an Ollama section with skip-on-error
examples. **Unit tests** use a fake `ollama` client; **integration
tests** run only when `REDISVL_TEST_OLLAMA=1`.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
ce7b52e. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 4041119 commit 9947b18
8 files changed
Lines changed: 703 additions & 11 deletions
File tree
- docs/user_guide
- redisvl/utils/vectorize
- text
- tests
- integration
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
293 | 359 | | |
294 | 360 | | |
295 | 361 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| 60 | + | |
| 61 | + | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
0 commit comments