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

# Token Efficiency and Context Compression

> How Cognee compresses your data into a knowledge graph so each LLM call can carry a small slice of context instead of the whole corpus, with published token counts.

Cognee cuts the tokens each LLM call spends by compressing your data once, into a knowledge graph, and then sending the model only the part of that graph a question needs. In Cognee's published [token cost report](https://www.cognee.ai/token-cost-of-persistent-ai-memory), a `recall()` call carried about **1,118 tokens** of context over a 16,075-token corpus, and about **1,864 tokens** over a 201,987-token corpus, where full-context prompting sends the whole corpus on every call. Building the graph costs a one-time amount of tokens, which paid for itself after about **23–26 repeated queries** on that report's dense test corpus.

## How Cognee compresses context

There are two ways to give an LLM knowledge of a document set:

* **Full-context prompting** puts the entire corpus in the prompt on every question. The cost per call equals the corpus size, so total cost grows linearly with both corpus size and number of questions.
* **Cognee memory** does the expensive reading once. [`remember()`](/core-concepts/main-operations/remember) splits your data into chunks, then summarizes each chunk and extracts its entities and relationships into a knowledge graph. [`recall()`](/core-concepts/main-operations/recall) then finds the passages, entities and facts relevant to the question and passes only those to the LLM.

The saving comes at query time. Ingestion turns a chunk of prose into compact facts like `Apollo 11 → landed on → Moon`, and recall sends a bounded number of them per question, however large the corpus grows.

If you build a [Global Context Index](/guides/global-context-index), it adds one more layer of compression: a dataset-wide summary, which the summary prompt asks to keep within 500 tokens, plus per-topic summaries. See [Reading the Global Context Index](/guides/global-context-index-recall) for what it adds to recall.

## What recall sends

By default, recall sends at most 10 source passages, 10 entities and 10 facts per question (`top_k` is 15, and each of those three is capped at 10). The entities and facts are the compressed graph. The passages are full chunk text, so they cost the most: how many tokens a call carries depends on your chunk size, and on a corpus of only a few chunks, recall can send nearly all of it. The saving grows once your data is much larger than 10 chunks, since recall never sends more than 10 passages.

To send the graph alone, turn the passages off with `retriever_specific_config={"chunks_top_k": 0}`:

```python theme={null}
results = await cognee.recall(
    query_text="Who are the key people, and what did they do?",
    query_type=cognee.SearchType.HYBRID_COMPLETION,
    retriever_specific_config={"chunks_top_k": 0},
)
```

Without the passages, the model no longer sees the original wording, so test answer quality on your own questions before you rely on it. To see what either setting costs on your data, [measure it](#measure-it-on-your-own-data).

## When memory pays off

The token cost report compared Cognee with full-context prompting on a high-density synthetic corpus, packed with entities and relationships, at two sizes:

| | 16k-token corpus | 202k-token corpus |
| - | -: | -: |
| LLM | `openai/gpt-5-mini` | `anthropic/claude-sonnet-4-5` |
| Corpus tokens | 16,075 | 201,987 |
| One-time ingestion tokens | 395,515 | 4,659,246 |
| Mean recall context per call | 1,118 tokens | 1,864 tokens |
| Break-even | \~26 queries | \~23 queries |
| 7× fewer tokens than full context | \~334 queries | \~173 queries |

The report retrieved with `top_k = 10`. The [blog post on the 7× figure](https://www.cognee.ai/behind-the-viral-benchmark-numbers) explains these numbers further.

Dense text is the expensive case, since graph extraction writes out more tokens for denser text. Cognee's [token usage analysis](https://github.com/topoteretes/cognee/tree/main/cognee/eval_framework/token_usage_analysis) measured the one-time ingestion cost for four corpora of about 10–12k tokens each:

| Corpus | Corpus tokens | Ingestion tokens, 4,095-token chunks | Ingestion tokens, 8,191-token chunks |
| - | -: | -: | -: |
| Fiction (*War and Peace* excerpt) | 10,504 | 84,439 | 59,644 |
| News (23 Wikinews articles) | 10,161 | 99,556 | 74,225 |
| Encyclopedic (Wikipedia, *Apollo 11*) | 10,037 | 102,913 | 65,061 |
| Dense synthetic (entity-packed benchmark text) | 12,009 | 168,365 | 143,934 |

Ordinary prose costs about 8–10× its size to ingest at a 4,095-token chunk size, close to Cognee's default of 4,096, against 14× for the dense corpus. Larger chunks lower the cost, because each chunk carries the same fixed prompt overhead. The analysis finds that break-even tracks this ingestion multiplier, so ordinary prose breaks even sooner than the report's dense corpus, whose 23–26 queries are the outlier rather than typical input.

Memory pays off when you ask **repeated questions over a stable corpus**, which is how agents and assistants use memory. For a single question over a small document, sending the document directly is cheaper.

> [!NOTE]
>
> These are single runs. Graph extraction isn't fully deterministic, so its output length varies between runs, most on dense text. Treat the numbers as representative, not exact.

For answer quality, see [Accuracy Benchmarks](/core-concepts/evaluation-and-efficiency/accuracy-benchmarks): on the BEAM long-horizon memory benchmark, Cognee scored 0.79 at 100K tokens in its benchmarked configuration, which retrieves more context than the defaults above.

## How the ingestion numbers were measured

The token usage analysis runs real text through `remember()`'s summary and graph-extraction calls and reads token counts from the actual LLM responses. The prompt wrapper and graph schema are therefore included, not estimated.

| Setting | Value |
| - | - |
| LLM | `openai/gpt-5-mini` |
| Chunk size | 4,095 and 8,191 tokens |
| Chunks measured per corpus | 3, scaled to the full corpus |
| Tokens counted | LLM prompt and completion tokens. Embeddings are excluded. |

## Measure it on your own data

To see how many tokens Cognee sends for a question, ask `recall()` for the prompt it would send instead of an answer. With `only_context=True`, Cognee builds the prompt without calling the LLM, so you can count its tokens and compare against your source text. Drop `retriever_specific_config` to measure default recall, passages included:

```python theme={null}
import asyncio
import cognee
import tiktoken

encoding = tiktoken.get_encoding("o200k_base")

async def main():
    with open("my_corpus.txt") as f:
        corpus = f.read()

    await cognee.remember(corpus)

    results = await cognee.recall(
        query_text="What are the main topics?",
        query_type=cognee.SearchType.HYBRID_COMPLETION,
        retriever_specific_config={"chunks_top_k": 0},
        only_context=True,
    )
    prompt = results[0].text + (results[0].system_prompt or "")

    print("Full-context tokens:", len(encoding.encode(corpus)))
    print("Cognee prompt tokens:", len(encoding.encode(prompt)))

asyncio.run(main())
```

To estimate ingestion cost and break-even for text like yours, run the [token usage analysis](/integrations/eval-framework#token-usage-analysis) on a sample of it, passing the prompt token count from the snippet above as `--retrieved-context`.

## Next steps

> **[Recall](/core-concepts/main-operations/recall)**
>
> Retrieval modes and the `only_context` option

> **[Global Context Index](/guides/global-context-index)**
>
> Dataset-wide summaries for broad questions

> **[Chunkers](/core-concepts/further-concepts/chunkers)**
>
> How chunk size affects ingestion

> **[Token usage analysis](/integrations/eval-framework#token-usage-analysis)**
>
> Measure ingestion cost and break-even on your own data


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.