CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-dev-langchain4j--langchain4j-ollama

Java integration library enabling LangChain4j applications to use Ollama's local language models with support for chat, streaming, embeddings, and advanced reasoning features

Overview
Eval results
Files

model-management.mddocs/

Model Management

The OllamaModels class provides utilities for managing Ollama models, including listing available models, retrieving model information, checking running models, and deleting models.

OllamaModels

Utility class for Ollama model management operations.

Class Signature

package dev.langchain4j.model.ollama;

public class OllamaModels

Thread Safety: Immutable after build(); safe for concurrent operations

Nullability: Instance never null after successful build()

Public Methods

availableModels

public Response<List<OllamaModel>> availableModels()

Lists all models available on the Ollama server.

Returns: Response<List<OllamaModel>> containing available models

  • Never null
  • List never null (may be empty if no models)
  • Models sorted by modification time (newest first)

Throws:

  • HttpTimeoutException - If request exceeds timeout
  • IOException - If network error
  • RuntimeException - If server error

Thread Safety: Safe for concurrent calls

Example:

import java.io.IOException;

try {
    Response<List<OllamaModel>> response = ollamaModels.availableModels();
    List<OllamaModel> models = response.content();

    for (OllamaModel model : models) {
        System.out.println("Model: " + model.getName());
        System.out.println("  Size: " + model.getSize() + " bytes");
    }
} catch (IOException e) {
    System.err.println("Failed to connect to Ollama: " + e.getMessage());
}

modelCard

public Response<OllamaModelCard> modelCard(String modelName)

Retrieves detailed information (model card) for a model by name.

Parameters:

  • modelName - The name of the model (must not be null or empty)

Returns: Response<OllamaModelCard> containing detailed model information

  • Never null
  • Card never null if model exists

Throws:

  • IllegalArgumentException - If modelName is null or empty
  • RuntimeException - If model not found
  • IOException - If network error

Thread Safety: Safe for concurrent calls

deleteModel

public void deleteModel(String ollamaModelName)

Deletes a model from the Ollama server by name.

Parameters:

  • ollamaModelName - The name of the model to delete (must not be null or empty)

Returns: void

Throws:

  • IllegalArgumentException - If ollamaModelName is null or empty
  • RuntimeException - If model not found or deletion fails
  • IOException - If network error

Thread Safety: Safe for concurrent calls

Warning: Deletion is permanent; cannot be undone

runningModels

public Response<List<RunningOllamaModel>> runningModels()

Lists all currently running models on the Ollama server.

Returns: Response<List<RunningOllamaModel>> containing running model instances

  • Never null
  • List never null (may be empty if no models running)

Throws:

  • IOException - If network error
  • RuntimeException - If server error

Thread Safety: Safe for concurrent calls

See Also

  • Types - OllamaModel, OllamaModelCard, RunningOllamaModel
  • Chat Models - Using models for chat
  • Language Models - Using models for completion

Install with Tessl CLI

npx tessl i tessl/maven-dev-langchain4j--langchain4j-ollama@1.11.0

docs

architecture.md

chat-models.md

embedding-model.md

index.md

language-models.md

model-management.md

request-parameters.md

spi.md

types.md

README.md

tile.json