Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 2.810s · 69.3MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 7.4s · import 2.598s · 78MB
72MB installed
● package 72MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ChatOllama
✓ from langchain_ollama import ChatOllama
✗ from langchain_community.chat_models import ChatOllama
As of recent versions, ChatOllama moved from langchain_community to langchain_ollama for direct integration, though langchain_community might still expose older or aliased versions.
OllamaLLM
✓ from langchain_ollama.llms import OllamaLLM
✗ from langchain_community.llms import Ollama
The canonical LLM import for text completion is now directly from langchain_ollama.llms.OllamaLLM, not the legacy Ollama from langchain_community.llms.
OllamaEmbeddings
✓ from langchain_ollama.embeddings import OllamaEmbeddings
✗ from langchain_community.embeddings import OllamaEmbeddings
OllamaEmbeddings has moved to langchain_ollama.embeddings for direct integration in newer versions.
This quickstart demonstrates how to set up a `ChatOllama` instance to interact with a local LLM (e.g., Llama 3) via the Ollama server. It includes a basic chat prompt template and uses `StrOutputParser` for clean output. It also shows how to instantiate `OllamaEmbeddings` to generate vector embeddings. Before running, ensure the Ollama server is installed and running, and the specified model (e.g., 'llama3') has been pulled using `ollama pull <model_name>`.
import os
from langchain_ollama import ChatOllama
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
# Ensure Ollama server is running and 'llama3' model is pulled (e.g., `ollama pull llama3`)
# You can check Ollama status at http://localhost:11434/
# Instantiate the ChatOllama model
# You can specify base_url if Ollama is not on default localhost:11434
llm = ChatOllama(model="llama3", base_url=os.environ.get("OLLAMA_BASE_URL", "http://localhost:11434"))
# Define a prompt template
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful AI assistant. Answer the user's questions truthfully."),
("user", "{question}")
])
# Create a simple chain
chain = prompt | llm | StrOutputParser()
# Invoke the chain
response = chain.invoke({"question": "What is the capital of France?"})
print(response)
# Example for embeddings
from langchain_ollama.embeddings import OllamaEmbeddings
embeddings_model = OllamaEmbeddings(model="llama3", base_url=os.environ.get("OLLAMA_BASE_URL", "http://localhost:11434"))
query_vector = embeddings_model.embed_query("What is the largest city in France?")
print(f"Embedding vector length: {len(query_vector)}")
Debug
Known issues
breakingThe primary import paths for `ChatOllama`, `OllamaLLM`, and `OllamaEmbeddings` have shifted from `langchain_community` to `langchain_ollama` (e.g., `from langchain_ollama import ChatOllama`). Older code relying on `langchain_community` imports may break or use deprecated versions.fixUpdate your import statements to use `from langchain_ollama import ...` for the latest functionality and stability. For embeddings, use `from langchain_ollama.embeddings import OllamaEmbeddings`.
affects: >=1.0.0
gotchaThe `ollama` server application must be installed and running, and the desired LLM model (e.g., 'llama3') must be pulled using `ollama pull <model_name>` via the command line before `langchain-ollama` can connect to it. Failure to do so will result in connection or model not found errors.fixInstall Ollama from https://ollama.com and run `ollama pull <model_name>` for your chosen model(s). Ensure the Ollama server is active before running your Python application.
affects: *
gotchaOllama's native tool calling support is less mature compared to providers like OpenAI. When implementing agents that use tools, `langchain-ollama` often relies on JSON-based agent workarounds, which might have a lower success rate for complex tasks than native function calling.fixFor complex agentic workflows requiring robust tool use, consider testing thoroughly and potentially simplifying tool definitions or using structured output parsers for more reliable JSON parsing. For critical production systems with advanced tool calling, evaluate if alternative LLM providers offer more native support.
affects: *
gotchaConnecting to an Ollama instance not running on the default `http://localhost:11434` requires explicitly setting the `base_url` parameter during instantiation (e.g., `ChatOllama(base_url='http://your-ollama-host:port')`). Incorrect configuration can lead to connection errors.fixPass the correct `base_url` parameter to `ChatOllama`, `OllamaLLM`, or `OllamaEmbeddings` constructors. It's recommended to use an environment variable for flexibility (e.g., `os.environ.get('OLLAMA_BASE_URL', 'http://localhost:11434')`). affects: *
deprecatedThe `OllamaEmbeddings` class in `langchain_community` was officially deprecated in favor of `langchain_ollama.embeddings.OllamaEmbeddings` around version `0.3.1` of `langchain-community`, with removal planned for `1.0.0` of `langchain-community`.fixMigrate your `OllamaEmbeddings` imports to `from langchain_ollama.embeddings import OllamaEmbeddings` to use the current and supported version.
affects: langchain-community >=0.3.1
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'langchain_community'
This error occurs because the core components of LangChain, including the Ollama integration, were moved from the main `langchain` package to `langchain-community` in recent versions. The `langchain-ollama` package depends on `langchain-community`.
fixEnsure `langchain-community` is installed: `pip install langchain-community` and update your import statements from `from langchain.llms import Ollama` to `from langchain_community.llms import Ollama` or `from langchain_community.chat_models import ChatOllama`.
ConnectionRefusedError: [Errno 111] Connection refused
This typically means the LangChain application cannot connect to the Ollama server. This can happen if the Ollama server is not running, is running on a different port than expected, or a firewall is blocking the connection.
fixFirst, ensure the Ollama server is running (e.g., by checking `ollama serve` in your terminal or accessing `http://localhost:11434` in a browser). If running in Docker, ensure proper port mapping and network configuration. You might also need to explicitly set the `base_url` parameter in your `Ollama` or `ChatOllama` initialization if it's not running on the default `http://localhost:11434`.
Ollama call failed with status code 404. Maybe your model is not found and you should pull the model with `ollama pull <model_name>`.
The Ollama server is running and accessible, but the specific model requested (e.g., 'llama2', 'mistral') has not been downloaded or is not available in your local Ollama instance.
fixOpen your terminal and pull the required model using the Ollama CLI: `ollama pull <model_name>` (e.g., `ollama pull llama2`). Verify the model is listed by running `ollama list`.
TypeError: 'module' object is not callable
This error often arises when you try to call the imported module itself as a function, rather than calling a specific class or function *from* that module. For example, trying to instantiate `ollama.Ollama()` when `Ollama` has already been imported directly, or if the class name `Ollama` is accidentally imported with a lowercase 'o' from a module.
fixEnsure you are importing the `Ollama` or `ChatOllama` class correctly and instantiating it with an uppercase 'O'. For instance, `from langchain_community.llms import Ollama; llm = Ollama(model='llama2')` is correct, while `from langchain_community.llms import ollama; llm = ollama(model='llama2')` or `llm = ollama.Ollama(model='llama2')` after `from langchain_community.llms import Ollama` would be incorrect.
Upgrade
Version history
1.1.0latest on PyPI · released Apr 7, 2026
Audit
Dependencies
langchain-corerequiredCore components for LangChain integrations.
ollama (server/cli)requiredRequired to run local LLMs that langchain-ollama connects to. Not a Python dependency, but a system prerequisite.