> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Local Memory & Knowledge

> Run agent memory and knowledge fully local with Ollama embeddings

Keep both memory and knowledge on your own machine — a local LLM answers, a local Ollama embedder builds the vectors, and a local vector store holds them.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Fully Local"
        A[🤖 Agent] --> B[🧠 Local LLM<br/>Ollama]
        A --> C[📐 Local Embedder<br/>Ollama]
        C --> D[(🗄️ Vector Store<br/>Chroma / Mongo)]
    end

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef store fill:#6366F1,stroke:#7C90A0,color:#fff

    class A agent
    class B,C process
    class D store
```

## Quick Start

<Steps>
  <Step title="Pull the embedder">
    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    ollama pull nomic-embed-text
    ```
  </Step>

  <Step title="Local memory">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent

    agent = Agent(
        name="assistant",
        instructions="Remember facts across sessions.",
        memory={
            "provider": "mongodb",
            "config": {
                "connection_string": "mongodb://localhost:27017/",
                "database": "praisonai",
                "use_vector_search": True,
                "embedder": {
                    "provider": "ollama",
                    "config": {"model": "nomic-embed-text"},
                },
            },
        },
    )
    agent.start("Remember that my favourite colour is teal")
    ```
  </Step>

  <Step title="Add local knowledge">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Knowledge

    kb = Knowledge(config={
        "vector_store": {
            "provider": "mongodb",
            "config": {
                "connection_string": "mongodb://localhost:27017/",
                "database": "praisonai",
                "collection": "handbook",
            },
        },
        "embedder": {
            "provider": "ollama",
            "config": {"model": "nomic-embed-text"},
        },
    })

    kb.add("Refunds are processed within 14 days.")
    kb.search("refund window")
    ```
  </Step>
</Steps>

<Note>
  Install the MongoDB extra first: `pip install "praisonaiagents[mongodb]"`. Chroma is the default local vector store and needs no extra service.
</Note>

***

## How It Works

The same `embedder` block drives memory and knowledge — embed, store, and query all stay on your machine.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Ollama as Local Embedder
    participant Store as Vector Store

    User->>Agent: "Remember X"
    Agent->>Ollama: embed(text)
    Ollama-->>Agent: vector
    Agent->>Store: store(text, vector)
    User->>Agent: "What did I say?"
    Agent->>Ollama: embed(query)
    Ollama-->>Agent: vector
    Agent->>Store: $vectorSearch(vector)
    Store-->>Agent: nearest matches
    Agent-->>User: answer
```

The SDK now sizes the vector index at the model's real dimension — `nomic-embed-text` is 768, not the 1536 default it was silently written as before [PR #4802](https://github.com/MervinPraison/PraisonAI/pull/4802).

***

## Choosing a Local Embedder

Pick by what matters most: speed, balance, or quality.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph TB
    Q{What matters<br/>most?} -->|Speed| A[all-minilm<br/>384 dims]
    Q -->|Balance| B[nomic-embed-text<br/>768 dims]
    Q -->|Quality| C[mxbai-embed-large<br/>1024 dims]

    classDef decision fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef option fill:#189AB4,stroke:#7C90A0,color:#fff

    class Q decision
    class A,B,C option
```

| Model               | Dimensions | Best for                    |
| ------------------- | ---------- | --------------------------- |
| `all-minilm`        | 384        | Fastest, smallest footprint |
| `nomic-embed-text`  | 768        | Balanced default            |
| `mxbai-embed-large` | 1024       | Highest quality             |

***

## Common Patterns

Local memory with a local LLM:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="assistant",
    llm="ollama/llama3.2",
    memory={
        "provider": "mongodb",
        "config": {
            "connection_string": "mongodb://localhost:27017/",
            "database": "praisonai",
            "use_vector_search": True,
            "embedder": {"provider": "ollama", "config": {"model": "nomic-embed-text"}},
        },
    },
)
agent.start("Remember I prefer metric units")
```

Local knowledge with the `Knowledge` class:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Knowledge

kb = Knowledge(config={
    "vector_store": {
        "provider": "mongodb",
        "config": {
            "connection_string": "mongodb://localhost:27017/",
            "database": "praisonai",
            "collection": "handbook",
        },
    },
    "embedder": {"provider": "ollama", "config": {"model": "nomic-embed-text"}},
})
kb.add("Onboarding takes three steps: sign in, verify email, join a team.")
kb.search("onboarding steps")
```

Both together — one local LLM for memory, one local embedder for knowledge:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent, Knowledge

local_embedder = {"provider": "ollama", "config": {"model": "nomic-embed-text"}}

kb = Knowledge(config={
    "vector_store": {
        "provider": "mongodb",
        "config": {
            "connection_string": "mongodb://localhost:27017/",
            "database": "praisonai",
            "collection": "handbook",
        },
    },
    "embedder": local_embedder,
})
kb.add("Support hours are 9-5 UTC.")

agent = Agent(
    name="assistant",
    llm="ollama/llama3.2",
    memory={
        "provider": "mongodb",
        "config": {
            "connection_string": "mongodb://localhost:27017/",
            "database": "praisonai",
            "use_vector_search": True,
            "embedder": local_embedder,
        },
    },
)
agent.start("What did we agree on last session?")
```

***

## Best Practices

<AccordionGroup>
  <Accordion title="Re-create the vector index when you change the embedder">
    Atlas vector indexes are built for a fixed dimension. Moving from `text-embedding-3-small` (1536) to `nomic-embed-text` (768) means dropping and re-creating `vector_index` at the new size — otherwise writes succeed but searches error or return nothing.
  </Accordion>

  <Accordion title="Pull the embedder before running">
    The first embed call fails cold if the model isn't downloaded. Run `ollama pull nomic-embed-text` before starting the agent.
  </Accordion>

  <Accordion title="Set api_base when Ollama isn't on localhost">
    Ollama defaults to `http://localhost:11434`. Point elsewhere by setting `api_base` explicitly on the embedder call or `OLLAMA_HOST` in the environment.
  </Accordion>

  <Accordion title="Prefer the embedder block form">
    The `{"provider": "...", "config": {"model": "..."}}` block works identically across memory, knowledge, and the MongoDB adapters — reuse one dict everywhere.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="MongoDB Memory" icon="brain" href="/docs/features/mongodb-memory">
    Configure the embedder on the MongoDB memory store
  </Card>

  <Card title="MongoDB Knowledge" icon="book" href="/docs/features/mongodb-knowledge">
    Scoped, vector-searchable knowledge in MongoDB
  </Card>

  <Card title="Ollama Embeddings" icon="server" href="/docs/embeddings/providers/ollama">
    Local embedding models and auto-detected dimensions
  </Card>

  <Card title="Local Models" icon="server" href="/docs/features/local-models">
    Run the LLM side fully local
  </Card>
</CardGroup>
