remember → recall round trip to run without any hosted API call, in a throwaway directory you can delete afterwards.
Before You Start
- Complete Quickstart to understand basic operations
- Install Ollama, start it with
ollama serve, and pull the two models the script uses: - Read Local Setup (No API Key) for the equivalent
.envconfiguration and the local-run troubleshooting list - Check LLM Providers and 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
What Just Happened
Step 1: Isolate the Example’s Storage
Step 2: Point Cognee at Ollama
LLM_ENDPOINT is the bare host — on the default litellm_native backend LiteLLM appends Ollama’s native /api/generate path, so a trailing /v1 would 404 (see LLM Providers → Ollama) — while EMBEDDING_ENDPOINT is passed through as-is by Cognee’s own embedding engine and needs the full /api/embed path. 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
GRAPH_DATABASE_PROVIDER or VECTOR_DB_PROVIDER is set in your environment. See Graph Stores for the other providers these names select between.
Step 4: Remember the Sample Text
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 logs no model-support warning; swap in a model cognee hasn’t validated and the log shows an advisory model-support warning — not a failure, extraction continues either way. The log does still show one advisory warning even with this setup: Counting tokens for embedding model 'nomic-embed-text' with HUGGINGFACE_TOKENIZER='nomic-ai/nomic-embed-text-v1.5'. Make sure they share a tokenizer…. Cognee logs it whenever HUGGINGFACE_TOKENIZER differs from the EMBEDDING_MODEL id, which an Ollama tag always does; here the two do share a tokenizer, so you can ignore it.
Step 5: Recall From the Local Graph
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.
Local Setup (No API Key)
The same configuration as
.env variables, plus local-run troubleshooting.LLM Providers
Swap in another local or hosted model for generation.
Embedding Providers
Pick a different embedding model and its matching dimensions.