langchain/libs/partners/ollama
Mason Daugherty 572020c4d8
ollama: add validate_model_on_init, catch more errors (#31784)
* Ensure access to local model during `ChatOllama` instantiation
(#27720). This adds a new param `validate_model_on_init` (default:
`true`)
* Catch a few more errors from the Ollama client to assist users
2025-07-03 11:07:11 -04:00
..
langchain_ollama ollama: add validate_model_on_init, catch more errors (#31784) 2025-07-03 11:07:11 -04:00
scripts partners[lint]: run pyupgrade to get code in line with 3.9 standards (#30781) 2025-04-11 07:18:44 -04:00
tests ollama: add validate_model_on_init, catch more errors (#31784) 2025-07-03 11:07:11 -04:00
.gitignore
LICENSE
Makefile infra: add UV_FROZEN to makefiles (#29642) 2025-02-06 14:36:54 -05:00
pyproject.toml langchain-ollama[patch]: Add ruff bandit rules to linter (#31811) 2025-07-01 18:16:07 +00:00
README.md ollama: update tests, docs (#31736) 2025-06-25 20:13:20 +00:00
uv.lock ollama: add validate_model_on_init, catch more errors (#31784) 2025-07-03 11:07:11 -04:00

langchain-ollama

This package contains the LangChain integration with Ollama

Installation

pip install -U langchain-ollama

For the package to work, you will need to install and run the Ollama server locally (download).

To run integration tests (make integration_tests), you will need the following models installed in your Ollama server:

  • llama3.1
  • deepseek-r1:1.5b

Install these models by running:

ollama pull <name-of-model>

Chat Models

ChatOllama class exposes chat models from Ollama.

from langchain_ollama import ChatOllama

llm = ChatOllama(model="llama3.1")
llm.invoke("Sing a ballad of LangChain.")

Embeddings

OllamaEmbeddings class exposes embeddings from Ollama.

from langchain_ollama import OllamaEmbeddings

embeddings = OllamaEmbeddings(model="llama3.1")
embeddings.embed_query("What is the meaning of life?")

LLMs

OllamaLLM class exposes traditional LLMs from Ollama.

from langchain_ollama import OllamaLLM

llm = OllamaLLM(model="llama3.1")
llm.invoke("The meaning of life is")