Overview
The Ollama provider enables running open-source LLMs locally with LlamaIndex.TS. Ollama supports models like Llama, Mistral, CodeLlama, and more.Installation
Prerequisites
- Install Ollama: https://ollama.ai
- 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
Popular Models
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 withollama 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
Model Variants
Models come in different sizes:Performance Tips
- Choose appropriate model size: Smaller models (7B) for faster inference, larger (70B+) for quality
- Adjust context window: Reduce
num_ctxfor faster responses - Use quantized models: Q4_0, Q5_0 variants for reduced memory usage
- GPU acceleration: Ollama automatically uses GPU if available
- Keep Ollama updated:
ollama pull <model>to update models
Troubleshooting
Ollama Not Running
Model Not Found
Connection Error
Best Practices
- Run locally for privacy: All processing happens on your machine
- Choose model wisely: Balance quality vs speed/memory
- Monitor resource usage: Larger models need more RAM/VRAM
- Use streaming: Better UX for long responses
- Cache models: Models stay in memory for faster subsequent runs