Registry / llm-agents / llama-index-llms-ollama

llama-index-llms-ollama

JSON →
library0.10.1pypypi✓ verified 85d ago

The `llama-index-llms-ollama` library provides an integration for LlamaIndex to utilize Large Language Models (LLMs) hosted locally via Ollama. It enables users to leverage various open-source models (like Llama, Mistral, Gemma, Phi-3, etc.) for tasks such as completions and chat within a LlamaIndex application, without relying on cloud-based LLM services. The current version is 0.10.1, released on March 20, 2026, and follows LlamaIndex's active and rapid release cadence for its integration packages.

pip install llama-index-llms-ollama
INSTALL
IMPORT
SIG · LLAMA-INDEX-LLMS-O
L
llama-index-llms-ollama
llm-agentspythonv0.10.1
Install
18.2s avg
Import
5979ms
Disk
247MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.10.1 · 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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 4.951s · 236.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 18.2s · import 4.615s · 233MB
247MB installed
● package 247MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Ollama
from llama_index.llms.ollama import Ollama
This is the standard import path for the Ollama LLM integration. Older versions of LlamaIndex might have different structures, but for recent versions, this is correct.

This quickstart demonstrates how to initialize the `Ollama` LLM and use it for both text completion and chat interactions within LlamaIndex. It assumes the Ollama server is running locally and that a model like `llama3.1` has been pulled using `ollama pull llama3.1`. The `request_timeout` is increased for robustness, and `context_window` is an optional parameter for memory management.

# First, ensure Ollama is installed and running, and pull a model: # On your terminal: # curl -fsSL https://ollama.com/install.sh | sh # ollama serve # ollama pull llama3.1 from llama_index.llms.ollama import Ollama from llama_index.core.llms import ChatMessage import os # Initialize Ollama LLM. Adjust model and timeout as needed. # Ensure the model 'llama3.1' is pulled via 'ollama pull llama3.1' llm = Ollama( model="llama3.1:latest", request_timeout=120.0, # Increase timeout from default 30s if model is slow # context_window=8000 # Optionally set context window to limit memory usage ) # Generate a completion response_completion = llm.complete("Tell me a short story about a brave knight.") print("\n--- Completion Response ---") print(response_completion) # Send a chat message messages = [ ChatMessage(role="system", content="You are a helpful assistant."), ChatMessage(role="user", content="What is the capital of France?") ] response_chat = llm.chat(messages) print("\n--- Chat Response ---") print(response_chat.message.content)
Debug
Known issues
gotchaOllama Server Prerequisite: The Ollama application must be installed and actively running on your local machine, and the desired LLM model (e.g., `llama3.1`) must be pulled using `ollama pull <model_name>` before this integration can connect to it.
fix
Install Ollama from https://ollama.ai/, run `ollama serve` in your terminal, and pull your chosen model (e.g., `ollama pull llama3.1`).
affects: All versions
gotchaDefault Timeout: The default request timeout (often 30 seconds) may be too short for larger local LLMs or slower machines, leading to `Timeout` errors.
fix
Increase the `request_timeout` parameter when initializing `Ollama`: `llm = Ollama(..., request_timeout=120.0)`.
affects: All versions
gotchaHigh Memory Usage: Running large local LLMs (e.g., Llama 3.1 8B) through Ollama can be memory-intensive, often requiring 32GB of RAM or more, especially when combined with embedding models.
fix
Monitor system RAM usage. Consider using smaller, quantized models (e.g., `llama3.1:7b-q4_0`), or adjust the `context_window` parameter in the `Ollama` constructor to limit memory consumption.
affects: All versions
gotchaModuleNotFoundError: Users frequently encounter `ModuleNotFoundError` if `llama-index-llms-ollama` is not installed in the currently active Python environment, or if their IDE (e.g., VS Code's Pylance) is configured to use a different interpreter.
fix
Ensure the package is installed in your active environment (`pip install llama-index-llms-ollama`) and that your IDE is configured to use the correct Python interpreter. Restarting the IDE can also help.
affects: All versions
gotchaConflicting Ollama Client Versions: There have been reports of conflicts when trying to install both `llama-index-multi-modal-llms-ollama` and `llama-index-llms-ollama` due to differing `ollama-client` version requirements.
fix
If both integrations are needed, carefully check their respective `ollama-client` dependencies and try to find compatible versions. In some cases, separate virtual environments might be required or reporting the issue to LlamaIndex.
affects: Specific version ranges of `llama-index-multi-modal-llms-ollama` and `llama-index-llms-ollama` (e.g., around 0.11.1 for multi-modal package)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'llama_index.llms.ollama'
The `llama-index-llms-ollama` integration package is not installed, or there's an incorrect import path due to LlamaIndex's modularization.
fix
Install the specific integration package: `pip install llama-index-llms-ollama`.
ImportError: cannot import name 'Ollama' from 'llama_index.llms' (unknown location)
This error occurs when the `Ollama` class is imported from `llama_index.llms` directly, but it has been moved to its own dedicated integration package `llama_index.llms.ollama`.
fix
Change the import statement to `from llama_index.llms.ollama import Ollama` and ensure the `llama-index-llms-ollama` package is installed (`pip install llama-index-llms-ollama`).
[Errno 111] Connection refused
The Ollama server is not running, is not accessible at the default `base_url` (`http://localhost:11434`), or a firewall is blocking the connection.
fix
Ensure Ollama is running (`ollama serve` or check the desktop app) and that the `base_url` in your LlamaIndex `Ollama` instance matches the Ollama server address. If using Docker, ensure proper network configuration and host addressing.
model not found
The specified LLM or embedding model has not been pulled and made available in the local Ollama instance.
fix
Pull the desired model using the Ollama CLI: `ollama pull <model-name>` (e.g., `ollama pull llama3`). Verify the model name in your code matches exactly what is listed by `ollama list`.
KeyError: 'embedding'
This error typically occurs when the Ollama server's response to an embedding request does not contain the expected 'embedding' key, which can happen due to a mismatch in Ollama client/server versions or an issue with the specific embedding model.
fix
Ensure both the underlying Ollama client (if separately installed) and the `llama-index-embeddings-ollama` package are up to date. Verify the embedding model (e.g., `nomic-embed-text`) is correctly pulled and functioning within Ollama.
Upgrade
Version history
0.10.1latest on PyPI · released Mar 20, 2026
Audit
Dependencies
llama-index-corerequiredThis is a LlamaIndex integration, requiring the core LlamaIndex framework to function.
ollamarequiredRequires the Ollama server application to be installed and running locally to serve the LLM models.
Agent activity
36 hits · last 30 days
node
34
OpenAI (training)
1
Resources
llama-index-llms-ollama — pip install llama-index-llms-ollama · libregistry