What is OllamaEmbeddings?
OllamaEmbeddings connects to a running Ollama server (default: http://localhost:11434) and calls its /api/embeddings endpoint to generate vectors. Ollama acts as a local model runner — it pulls model weights from the Ollama registry, manages GPU/CPU resources, and exposes a unified HTTP API. This means you can switch embedding models by changing the model parameter and running ollama pull, without changing any application code.
The most popular embedding models available through Ollama are nomic-embed-text (768 dimensions, 8192-token context), mxbai-embed-large (1024 dimensions, stronger on English), and all-minilm (384 dimensions, very fast). The choice depends on your quality-speed trade-off. Ollama uses quantised weights by default, so resource usage is manageable on consumer hardware with at least 8 GB of RAM.
For remote deployments, point base_url at the Ollama instance on your server: OllamaEmbeddings(base_url="http://192.168.1.10:11434", model="nomic-embed-text"). This is useful when you want a shared embedding server on a GPU node while running your application on CPU workers. The langchain-ollama package (from langchain_ollama import OllamaEmbeddings) is the newer recommended import over langchain-community.
When to Use
You want completely local embeddings offline. Use for privacy, offline, or development.
Use Cases
- • Local inference
- • Offline systems
- • Privacy
- • No API keys
- • Custom models
- • Edge devices
Key Features
- ✓ Fully local
- ✓ No API
- ✓ No keys
- ✓ Fast
- ✓ Privacy
- ✓ Flexible
When NOT to Use
For cloud deployments or high throughput.
Notes
Pull the model before first use — OllamaEmbeddings will not auto-pull
Run 'ollama pull nomic-embed-text' in your terminal before using the model. OllamaEmbeddings makes HTTP calls to the Ollama server and raises a connection error if the model is not present — it does not pull models automatically. Add an ollama pull step to your project setup or Dockerfile.
langchain-ollama is the new canonical package
The langchain-community import (langchain_community.embeddings.ollama) still works but is being phased out. Install langchain-ollama and use from langchain_ollama import OllamaEmbeddings for new projects. The API is identical.
Throughput is limited by the Ollama HTTP server, not just your GPU
Ollama processes embedding requests serially by default. For high-throughput batch indexing, call embed_documents() with all documents in one batch rather than calling embed_query() in a loop — embed_documents sends one HTTP request per item but the Ollama server may queue them. Consider running multiple Ollama instances behind a load balancer for production.
base_url defaults to localhost:11434 — check the port if Ollama is remote
Ollama listens on port 11434. If you expose it on a different port or via a reverse proxy, set base_url explicitly. On macOS, Ollama binds to localhost only by default — set OLLAMA_HOST=0.0.0.0 in its environment to allow remote connections.
Import
from langchain_community.embeddings.ollama import OllamaEmbeddings
Configuration
| Parameter | Type | Default | Purpose |
|---|---|---|---|
| model | str | nomic-embed-text | Ollama model name |
Usage Examples
Local Ollama Embeddings
# First: ollama pull nomic-embed-text
from langchain_community.embeddings.ollama import OllamaEmbeddings
embeddings = OllamaEmbeddings(model='nomic-embed-text')
vec = embeddings.embed_query('What is Ollama?')
print(len(vec)) # 768 dimensions
Batch Document Embeddings
# Batch embed documents
docs = ['LangChain is a framework', 'RAG uses vector stores']
embeddings = OllamaEmbeddings(model='nomic-embed-text')
vecs = embeddings.embed_documents(docs)
print(len(vecs), len(vecs[0])) # 2, 768
Remote Ollama Server
# Remote Ollama server on a GPU machine
embeddings = OllamaEmbeddings(
model='mxbai-embed-large',
base_url='http://gpu-server:11434',
)
vec = embeddings.embed_query('query to remote server')
Common Pitfalls
❌ Forget to pull model first
✅ ollama pull nomic-embed-text
Alternative Embedding Models
| Model | When to Use |
|---|---|
| HuggingFaceEmbeddings | For more model variety |
Related LangChain References
Browse the full LangChain API reference index to explore more classes, methods, and decorators, or start with the LangChain introduction tutorial for end-to-end context on building with OllamaEmbeddings and the wider framework.
OllamaEmbeddings FAQ
What is OllamaEmbeddings in LangChain?
Use Ollama for local LLM embeddings. OllamaEmbeddings connects to a running Ollama server (default: http://localhost:11434) and calls its /api/embeddings endpoint to generate vectors. Ollama acts as a local model runner — it pulls model weights from the Ollama registry, manages GPU/CPU resources, and exposes a unified HTTP API. This means you can switch embedding models by changing the model parameter and running ollama pull, without changing any application code. The most popular embedding models available thr…
Which package provides OllamaEmbeddings?
DevShelfHub documents OllamaEmbeddings from the langchain-community package. Pin your installed LangChain version and match imports to the snippet on this page.
When should I use OllamaEmbeddings?
You want completely local embeddings offline. Use for privacy, offline, or development.
When should I avoid using OllamaEmbeddings?
For cloud deployments or high throughput.
How do I import OllamaEmbeddings in Python?
from langchain_community.embeddings.ollama import OllamaEmbeddings
Where can I explore more LangChain API reference pages?
Open the LangChain API reference index on DevShelfHub to browse classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.