Skip to content

feat(embedding): add Ollama local embedding support with native API fallback#327

Closed
maxkandel99-arch wants to merge 1 commit into
garrytan:masterfrom
maxkandel99-arch:fix/ollama-embed-windows
Closed

feat(embedding): add Ollama local embedding support with native API fallback#327
maxkandel99-arch wants to merge 1 commit into
garrytan:masterfrom
maxkandel99-arch:fix/ollama-embed-windows

Conversation

@maxkandel99-arch

Copy link
Copy Markdown

Summary

Adds Ollama as a first-class embedding provider, with a fallback to Ollama native API for Ollama v0.21+ compatibility.

Problem

  • GBrain v0.9.2 only supports OpenAI embeddings (1536 dims, paid)
  • Ollama v0.21+ /v1/embeddings (OpenAI-compatible endpoint) returns empty embeddings when input is an array (batch request)
  • Users with local Ollama setups cannot embed their knowledge base

Solution

  1. Multi-provider embedding: GBRAIN_EMBEDDING_PROVIDER=openai|ollama|local
  2. Ollama mode (ollama): Uses /v1/embeddings — works on Ollama <0.21
  3. Local mode (local): Uses /api/embeddings with prompt field — works on Ollama v0.21+ (Windows tested)

Environment Variables

Variable Default Notes
GBRAIN_EMBEDDING_PROVIDER ollama (if no API key) openai / ollama / local
GBRAIN_EMBEDDING_MODEL
omic-embed-text Any Ollama embedding model
GBRAIN_EMBEDDING_DIMS 768 Match your model's dimensions
GBRAIN_OLLAMA_URL http://localhost:11434 Ollama server URL

Testing (Windows + Ollama v0.21.0)

`�ash

Native API (Ollama v0.21+ recommended)

set GBRAIN_EMBEDDING_PROVIDER=local
set GBRAIN_EMBEDDING_MODEL=nomic-embed-text
gbrain embed --all

OpenAI-compatible (Ollama <0.21)

set GBRAIN_EMBEDDING_PROVIDER=ollama
gbrain embed --all
`

Backwards Compatible

  • If OPENAI_API_KEY is set → defaults to OpenAI (no behavior change)
  • Existing deployments unaffected

- Adds GBRAIN_EMBEDDING_PROVIDER env var (openai/ollama/local)
- Ollama endpoint via /v1/embeddings (OpenAI-compatible)
- local mode uses /api/embeddings with 'prompt' field for Ollama v0.21+
  (fixes empty embedding bug with batch input arrays on Ollama v0.21)
- Auto-detects Ollama URL and uses correct API format
- Default model: nomic-embed-text (768 dims)
@garrytan

garrytan commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Thanks for this contribution — and apologies for the slow triage. We did a full pass over the entire PR backlog. gbrain has moved fast, and the maintainer's larger "cathedral" rewrites have superseded a big share of community PRs: the AI gateway + recipes + user_provided_models system replaced almost all individual provider PRs; #1805 fixed the whole Postgres module-singleton class; #1542 unified the type taxonomy; #1657 the retrieval path; #1802 the doctor; and so on.

We're closing this one in that cleanup — either the fix already landed on master, it duplicates another PR or merged change, or it's outside the current merge bar. Where a closed PR carried a genuinely valuable idea, we've recorded it in docs/designs/COMMUNITY_IDEAS.md so nothing good is lost (a few may graduate into TODOs).

Please don't read the close as a judgment of the work — thank you for contributing. If you believe the underlying issue is still live on the latest master, reopen with a quick note and we'll take another look. 🙏

@garrytan garrytan closed this Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants