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

# Local Ollama Pipeline

> Run remember and recall end to end against a local Ollama server and cognee's embedded stores.

A minimal guide to running a complete cognee pipeline on your own machine: Ollama for both generation and embeddings, and cognee's embedded stores for the graph, vectors, and metadata. Use it when you want the whole `remember` → `recall` round trip to run without any hosted API call, in a throwaway directory you can delete afterwards.

## Before You Start

* Complete [Quickstart](/getting-started/quickstart) to understand basic operations
* Install [Ollama](https://ollama.ai), start it with `ollama serve`, and pull the two models the script uses:
  ```bash theme={null}
  ollama pull llama3.1:8b
  ollama pull nomic-embed-text
  ```
* Read [Local Setup (No API Key)](/guides/local-setup) for the equivalent `.env` configuration and the local-run troubleshooting list
* Check [LLM Providers](/setup-configuration/llm-providers) and [Embedding Providers](/setup-configuration/embedding-providers) if you want to point the script at a different local model
* Nothing else to install: the graph, vector, and relational stores this script selects are embedded and ship with cognee

## Code in Action

```python theme={null}
import os
import asyncio
import tempfile
from pathlib import Path

# Setup temp directory to keep this example self-contained
_DATA_DIR = tempfile.mkdtemp(prefix="cognee_ollama_example_")
os.environ["ENABLE_BACKEND_ACCESS_CONTROL"] = "false"
os.environ["CACHING"] = "false"

# Configure Ollama environment settings
os.environ["LLM_PROVIDER"] = "ollama"
os.environ["LLM_MODEL"] = "llama3.1:8b"
os.environ["LLM_ENDPOINT"] = "http://localhost:11434/v1"
os.environ["LLM_API_KEY"] = "ollama"
os.environ["LLM_TEMPERATURE"] = "0.0"

os.environ["EMBEDDING_PROVIDER"] = "ollama"
os.environ["EMBEDDING_MODEL"] = "nomic-embed-text"
os.environ["EMBEDDING_ENDPOINT"] = "http://localhost:11434/api/embed"
os.environ["EMBEDDING_DIMENSIONS"] = "768"
os.environ["HUGGINGFACE_TOKENIZER"] = "nomic-ai/nomic-embed-text-v1.5"

import cognee  # noqa: E402
from cognee.modules.search.types import SearchType  # noqa: E402
from cognee.infrastructure.llm.config import get_llm_config  # noqa: E402

# Force local embedded stack configuration
cognee.config.set_graph_database_provider("kuzu")
cognee.config.set_vector_db_provider("lancedb")
cognee.config.data_root_directory(str(Path(_DATA_DIR) / "data"))
cognee.config.system_root_directory(str(Path(_DATA_DIR) / "system"))


SAMPLE_TEXT = """\
Cognee is an open-source library that helps developers turn documents into AI memory.
It builds semantic graphs, indexes entities, and stores vectors to enable structured retrieval.
Cognee supports local execution via Ollama as well as hosted cloud providers.
"""


def banner(title: str) -> None:
    print("\n" + "=" * 78)
    print(title)
    print("=" * 78)


async def main() -> None:
    # Start from a clean slate in isolated directory
    await cognee.prune.prune_data()
    await cognee.prune.prune_system(metadata=True)

    banner("LOCAL PIPELINE: REMEMBER USING OLLAMA")
    llm_config = get_llm_config()
    print(f"Using LLM: {llm_config.llm_model}")
    print(f"Using Embeddings: {os.environ.get('EMBEDDING_MODEL')}")

    # Ingest and build the knowledge graph (this will trigger a warning if an
    # unvalidated model is used)
    await cognee.remember(SAMPLE_TEXT, dataset_name="ollama_local_demo", self_improvement=False)
    print("Local knowledge graph built successfully.")

    banner("LOCAL RECALL")
    query = "What does Cognee help developers do?"
    results = await cognee.recall(
        query_text=query,
        query_type=SearchType.GRAPH_COMPLETION,
        datasets=["ollama_local_demo"],
    )
    print(f"Query: {query}")
    print("Recall Results:")
    print(results[0].text if results else "<no results>")


if __name__ == "__main__":
    asyncio.run(main())
```

## What Just Happened

### Step 1: Isolate the Example's Storage

```python theme={null}
# Setup temp directory to keep this example self-contained
_DATA_DIR = tempfile.mkdtemp(prefix="cognee_ollama_example_")
os.environ["ENABLE_BACKEND_ACCESS_CONTROL"] = "false"
os.environ["CACHING"] = "false"
```

A fresh temporary directory keeps this run's databases away from your default cognee directories, so the example leaves nothing behind. Access control stays off because the script runs as a plain single-user script, and caching stays off so every run really exercises the local models instead of replaying earlier answers.

### Step 2: Point Cognee at Ollama

```python theme={null}
# Configure Ollama environment settings
os.environ["LLM_PROVIDER"] = "ollama"
os.environ["LLM_MODEL"] = "llama3.1:8b"
os.environ["LLM_ENDPOINT"] = "http://localhost:11434/v1"
os.environ["LLM_API_KEY"] = "ollama"
os.environ["LLM_TEMPERATURE"] = "0.0"

os.environ["EMBEDDING_PROVIDER"] = "ollama"
os.environ["EMBEDDING_MODEL"] = "nomic-embed-text"
os.environ["EMBEDDING_ENDPOINT"] = "http://localhost:11434/api/embed"
os.environ["EMBEDDING_DIMENSIONS"] = "768"
os.environ["HUGGINGFACE_TOKENIZER"] = "nomic-ai/nomic-embed-text-v1.5"
```

Both halves have to be set together: configuring only the LLM leaves embeddings falling back to OpenAI, which would need an API key. The two endpoints differ because generation goes to Ollama's OpenAI-compatible path and embeddings go to its native one, `LLM_API_KEY` is a placeholder Ollama never validates, and `EMBEDDING_DIMENSIONS` plus `HUGGINGFACE_TOKENIZER` describe `nomic-embed-text` so cognee sizes its vectors and counts tokens correctly. The environment is set before `import cognee` so the configuration is in place when cognee reads it — hence the `# noqa: E402` markers on the imports that follow.

### Step 3: Pin the Embedded Local Stack

```python theme={null}
# Force local embedded stack configuration
cognee.config.set_graph_database_provider("kuzu")
cognee.config.set_vector_db_provider("lancedb")
cognee.config.data_root_directory(str(Path(_DATA_DIR) / "data"))
cognee.config.system_root_directory(str(Path(_DATA_DIR) / "system"))
```

These four calls make the storage side local too: an embedded graph database, LanceDB for vectors, and SQLite metadata, all written under the temporary directory from Step 1. Both calls select what cognee already uses out of the box (`kuzu` is an accepted alias for the default embedded graph store, and LanceDB is the default vector store), so they are explicit rather than required — they keep the script behaving the same way even if `GRAPH_DATABASE_PROVIDER` or `VECTOR_DB_PROVIDER` is set in your environment. See [Graph Stores](/setup-configuration/graph-stores) for the other providers these names select between.

### Step 4: Remember the Sample Text

```python theme={null}
SAMPLE_TEXT = """\
Cognee is an open-source library that helps developers turn documents into AI memory.
It builds semantic graphs, indexes entities, and stores vectors to enable structured retrieval.
Cognee supports local execution via Ollama as well as hosted cloud providers.
"""

await cognee.remember(SAMPLE_TEXT, dataset_name="ollama_local_demo", self_improvement=False)
print("Local knowledge graph built successfully.")
```

`remember()` runs the whole extraction pipeline against the local models: `llama3.1:8b` pulls entities and relationships out of the text and `nomic-embed-text` embeds the chunks. Three sentences is deliberately small — an 8B model on CPU is far slower than a hosted one, so keep test inputs short. `llama3.1` is on cognee's recommended list for structured extraction, so this script runs without warnings; swap in a model cognee hasn't validated and the log opens with an advisory model-support warning instead — not a failure, extraction continues either way.

### Step 5: Recall From the Local Graph

```python theme={null}
query = "What does Cognee help developers do?"
results = await cognee.recall(
    query_text=query,
    query_type=SearchType.GRAPH_COMPLETION,
    datasets=["ollama_local_demo"],
)
print(f"Query: {query}")
print("Recall Results:")
print(results[0].text if results else "<no results>")
```

`SearchType.GRAPH_COMPLETION` retrieves the triplets around the query and asks the local LLM to answer from them, which is the search type that proves the graph was actually populated. `datasets=["ollama_local_demo"]` scopes the search to the dataset built above, and printing `results[0].text` shows the generated answer rather than the raw result object.

<Columns cols={3}>
  <Card title="Local Setup (No API Key)" icon="computer" href="/guides/local-setup">
    The same configuration as `.env` variables, plus local-run troubleshooting.
  </Card>

  <Card title="LLM Providers" icon="brain" href="/setup-configuration/llm-providers">
    Swap in another local or hosted model for generation.
  </Card>

  <Card title="Embedding Providers" icon="layers" href="/setup-configuration/embedding-providers">
    Pick a different embedding model and its matching dimensions.
  </Card>
</Columns>
