Ollama

repository·main·Indexed 13 days ago

https://github.com/ollama/ollama

A tool for running, managing, and building open-source large language models (LLMs) locally. It features a CLI, a REST API, and official client libraries, along with a benchmarking tool called ollama-bench for measuring performance metrics like Time-to-First-Token (TTFT) and generation throughput.

Tokens
74.8K
Snippets
291
Records
414
Agent score
99%

What's inside Ollama

  1. Ollama API Overview and Endpoints

    main

    Ollama provides a RESTful API for interacting with large language models. The API supports generating completions (both text and chat), managing models (create, list, show, copy, delete, pull, push), generating embeddings, and monitoring running models.

    Note: Official documentation is migrating to https://docs.ollama.com/api.

  2. Explore Community Integrations for Ollama

    main

    Ollama has a vast ecosystem of community-driven integrations. Developers can use these to build applications, extend interfaces, or integrate Ollama into existing workflows. Integrations are categorized by use case:

    Chat Interfaces

    Development Tools

    Specialized Frameworks

    • Agents & Frameworks: Orchestrate multi-agent systems with crewAI or AutoGPT.
    • RAG (Retrieval Augmented Generation): Implement knowledge bases using RAGFlow, R2R, or MaxKB.
    • Observability: Monitor and evaluate LLM applications with Langfuse, OpenLIT, or Lunary.
    • Database & Embeddings: Use Ollama embeddings with pgai (PostgreSQL) or chromem-go.
  3. Best practices for using embeddings

    main

    When building semantic search, retrieval, or RAG (Retrieval-Augmented Generation) pipelines, follow these guidelines:

    • Similarity Metric: Use cosine similarity for most semantic search use cases.
    • Model Consistency: Always use the same embedding model for both the indexing phase (storing vectors in a database) and the querying phase (searching with a new vector).
  4. What are Ollama Cloud models?

    main
    Ollama Cloud models are a specialized type of model that offloads computation to Ollama's cloud service. This allows you to run large models that would otherwise exceed your local hardware's GPU/RAM capabilities while still using your existing local Ollama tools and workflows. Cloud models are distinct from local models and require an account on ollama.com.
  5. Handle errors during model streaming

    main

    If an error occurs while streaming a response (using application/x-ndjson), the error will be emitted as a JSON object containing an error property.

    Important: Because the response has already started streaming, the initial HTTP status code of the response will not be changed to reflect the error. You must monitor the individual NDJSON chunks for the presence of an error key to detect mid-stream failures.

    {"model":"gemma4","created_at":"2025-10-26T17:21:21.196249Z","response":" Yes","done":false}
    {"model":"gemma4","created_at":"2025-10-26T17:21:21.207235Z","response":".","done":false}
    {"error":"an error was encountered while running the model"}
  6. When authentication is required in Ollama

    main

    Accessing Ollama's API locally via http://localhost:11434 does not require authentication.

    Authentication is mandatory only when performing the following actions:

    • Running cloud models via ollama.com
    • Publishing models
    • Downloading private models
  7. Understand OpenCode configuration precedence

    main

    When using ollama launch opencode, the command uses an inline configuration for the selected model. This configuration is additive: it does not overwrite your existing ~/.config/opencode/opencode.json file, and existing settings remain in effect.

    Important Note: Models that are defined only in your opencode.json file will not appear in the ollama launch model picker.

  8. Override LLM libraries using OLLAMA_LLM_LIBRARY

    main

    Ollama attempts to autodetect the best LLM library (e.g., cuda, rocm, cpu_avx2) for your hardware. If autodetection fails or causes crashes, you can force a specific library using the OLLAMA_LLM_LIBRARY environment variable.

    Available libraries typically include:

    • cpu_avx2: Best performance for compatible CPUs.
    • cpu_avx: High compatibility for older CPUs.
    • cpu: Most compatible (used for Rosetta emulation on macOS).
    • cuda_v11: For NVIDIA GPUs.
    • rocm_v5 / rocm_v6: For AMD GPUs.

    Example: To force CPU with AVX2 support instead of using a CUDA card:

    OLLAMA_LLM_LIBRARY="cpu_avx2" ollama serve
  9. Understand limitations of Ollama's Anthropic compatibility

    main

    While Ollama provides broad compatibility with the Anthropic Messages API, some features are not supported or behave differently:

    Not Supported

    • /v1/messages/count_tokens endpoint
    • tool_choice (forcing specific tool use)
    • metadata (request metadata like user_id)
    • Prompt caching (cache_control blocks)
    • Batches API (/v1/messages/batches)
    • Citations (citations content blocks)
    • PDF support (document content blocks)

    Behavioral Differences

    • API Key: Accepted but not validated.
    • Headers: anthropic-version is accepted but not used.
    • Token Counts: Approximations based on the underlying model's tokenizer.
    • Images: Base64 images are supported; URL-based images are not.
    • Extended Thinking: Basic support; budget_tokens is accepted but not enforced.
  10. How Ollama templates work

    main

    Ollama uses a templating engine based on Go's built-in templating engine to construct prompts for Large Language Models (LLMs). A template consists of three components:

    1. Layout: The overall structure of the prompt.
    2. Variables: Placeholders for dynamic data (e.g., .Prompt, .Messages) that are replaced during rendering.
    3. Functions: Logic or actions used to manipulate content (e.g., range to iterate over messages).

    Using templates allows you to define specific markers (like <|im_start|> or [INST]) required by instruction or chat models, rather than sending user input verbatim.

    {{- range .Messages }}
    {{ .Role }}: {{ .Content }}
    {{- end }}
  11. Model requirements for OpenCode

    main

    OpenCode requires a model with a context length of 64k or higher to effectively process your repository.

    You can use:

    • Cloud models: Larger models accessed without local download.
    • Local models: Models downloaded via Ollama, provided you set a context window of 64k+.