Skip to main content
A minimal guide to Cognee’s temporal mode. Use it when your data contains dates and you want to ask time-scoped questions — before, after, or between two points in time — answered from an event timeline rather than embedding similarity alone.

Before You Start

  • Complete Quickstart to understand basic operations
  • Ensure you have LLM Providers configured
  • Read Recall for how querying memory works
  • No data is required up front — the script ingests its own dated sample text, but it starts with cognee.forget(everything=True), which wipes all existing Cognee data; run it against a setup you can afford to reset

Code in Action

What Just Happened

Step 1: Remember Data with Temporal Mode

The script starts from a clean state, then ingests TEXT into the timeline_demo dataset. Because temporal_cognify=True, remember() extracts events and timestamps and builds the timeline during ingestion, so there is no separate cognify() step. This example uses one string treated as a single document; multiple documents, files, or entire datasets are processed the same way.

Step 2: Ask Time-aware Questions

The loop runs the three query shapes temporal mode is built for — a before query, an after query, and one bounded by a pair of dates — using SearchType.TEMPORAL, imported from the cognee package at the top of the script. Each call is scoped with datasets=["timeline_demo"] so it only searches the timeline it just ingested; drop the argument to search every dataset you have access to. The answer for each query is results[0].text.
  • If the query has clear dates, the retriever filters events by time and ranks them
  • If no dates are detected, it falls back to event or entity retrieval and still answers
  • Increase top_k to inspect more candidate events

Using the HTTP API

If your server is running, you can run temporal search via the API by setting search_type to "TEMPORAL":
The Python example above is still the easiest way to enable temporal ingestion because it lets you pass temporal_cognify=True directly to remember().

Graphiti Mode: Episode-Based Temporal Graph

Cognee also ships a second temporal path built on Graphiti-core. Instead of extracting events and timestamps from text, it stores each document as a timestamped episode directly in Neo4j. Graphiti automatically tracks entities and how facts evolve over time across episodes. If you want, you can then index those episodes into Cognee’s vector store to run standard SearchType.* queries alongside Graphiti search. When to prefer this mode:
  • You need a complete, immutable episode history
  • You want direct access to Graphiti’s graph traversal and search API
  • Your pipeline requires a Neo4j-backed temporal store
Otherwise, start with native temporal mode — it needs no extra dependencies and works with any supported graph store.

temporal_cognify=True vs. Graphiti mode

Both modes make your memory time-aware, but they work differently and are enabled in different ways:

Requirements

Neo4j is a hard requirement of graphiti-core itself, not a Cognee design choice. Installing cognee[graphiti] binds your temporal store to Neo4j or AuraDB. If you want temporal search without a Neo4j dependency, use Cognee’s native SearchType.TEMPORAL (see above) — it works with any supported graph store.
  • Running Neo4j instance (v4.4+ or AuraDB)
  • Install the graphiti extra: pip install cognee[graphiti]
  • Set the following environment variables:
search_graph_with_temporal_awareness closes the Neo4j connection after returning results. For multiple queries, call graphiti.search(query) directly on the returned instance and close with await graphiti.close() when finished.
After building the episode graph, pull the Neo4j data into Cognee’s vector store:
This step requires GRAPH_DATABASE_PROVIDER=neo4j to be set. It raises a RuntimeError if the active graph engine is not Neo4j.

Full Examples

Additional examples about temporal awareness are available on our GitHub.
  • An advanced script running temporal search over real documents is on our GitHub. Instead of the inlined four-sentence timeline above, it ingests two bundled biographies as separate documents with temporal_cognify=True, then mixes before / after / between range queries with person-centric questions that carry no dates — exercising the entity-retrieval fallback described in the tip above.

Core Concepts Overview

Understand how Cognee builds and stores knowledge graphs.

API Reference

Explore the search endpoint behind temporal queries.