Ollama Embeddings

Generate embeddings using locally-hosted Ollama models

Overview

Ollama allows you to run embedding models locally on your machine with no API costs.

Quick Start

python
from praisonaiagents import embedding

result = embedding(
    input="Hello world",
    model="ollama/nomic-embed-text"
)
print(f"Dimensions: {len(result.embeddings[0])}")

CLI Usage

bash
praisonai embed "Hello world" --model ollama/nomic-embed-text

Setup

  1. Install Ollama: https://ollama.ai
  2. Pull an embedding model:
bash
ollama pull nomic-embed-text

Available Models

ModelDimensionsSize
ollama/nomic-embed-text768274MB
ollama/mxbai-embed-large1024669MB
ollama/all-minilm38445MB
ollama/snowflake-arctic-embednot auto-detected669MB

Custom API Base

python
from praisonaiagents import embedding

result = embedding(
    input="Hello world",
    model="ollama/nomic-embed-text",
    api_base="http://localhost:11434"
)

Batch Embeddings

python
from praisonaiagents import embedding

texts = ["Document 1", "Document 2", "Document 3"]
result = embedding(
    input=texts,
    model="ollama/nomic-embed-text"
)
print(f"Generated {len(result.embeddings)} embeddings")

Using Ollama embeddings for memory / knowledge

Point agent memory or knowledge at a local Ollama embedder with the same embedder block used across PraisonAI:

python
from praisonaiagents import Agent

agent = Agent(
    name="assistant",
    memory={
        "provider": "mongodb",
        "config": {
            "connection_string": "mongodb://localhost:27017/",
            "database": "praisonai",
            "use_vector_search": True,
            "embedder": {
                "provider": "ollama",
                "config": {"model": "nomic-embed-text"},
            },
        },
    },
)

See MongoDB Memory and MongoDB Knowledge for the full setup, or Local Memory & Knowledge to wire both fully local end to end.

Related