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_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
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 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 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
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.