Skip to main content

Overview

The Ollama provider enables running open-source LLMs locally with LlamaIndex.TS. Ollama supports models like Llama, Mistral, CodeLlama, and more.

Installation

Prerequisites

  1. Install Ollama: https://ollama.ai
  2. Pull a model:

Basic Usage

Constructor Options

string
required
Model name (e.g., “llama3.2”, “mistral”, “codellama”)
Partial<Config>
Ollama client configuration
Partial<Options>
Model options

Llama 3.2

Mistral

CodeLlama

Phi-3

Streaming

Function Calling

Structured Output

Completion API

Custom Ollama Server

Model Options

Embeddings

With LlamaIndex

Available Models

Pull models with ollama pull <model>:
  • llama3.2: Latest Llama 3.2
  • llama3.1: Llama 3.1 (8B, 70B, 405B)
  • llama2: Llama 2 (7B, 13B, 70B)
  • mistral: Mistral 7B
  • mixtral: Mixtral 8x7B
  • codellama: Code-specialized Llama
  • phi3: Microsoft Phi-3
  • gemma: Google Gemma
  • qwen: Alibaba Qwen
See full list: https://ollama.ai/library

Model Variants

Models come in different sizes:

Performance Tips

  1. Choose appropriate model size: Smaller models (7B) for faster inference, larger (70B+) for quality
  2. Adjust context window: Reduce num_ctx for faster responses
  3. Use quantized models: Q4_0, Q5_0 variants for reduced memory usage
  4. GPU acceleration: Ollama automatically uses GPU if available
  5. Keep Ollama updated: ollama pull <model> to update models

Troubleshooting

Ollama Not Running

Model Not Found

Connection Error

Best Practices

  1. Run locally for privacy: All processing happens on your machine
  2. Choose model wisely: Balance quality vs speed/memory
  3. Monitor resource usage: Larger models need more RAM/VRAM
  4. Use streaming: Better UX for long responses
  5. Cache models: Models stay in memory for faster subsequent runs

See Also