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

# Understand Recall with RAG Completion

> Explore the RAG retrieval workflow with cognee.recall() and learn how its main parameters affect the results

This guide teaches `cognee.recall()` and `SearchType.RAG_COMPLETION` side by side, demonstrating `only_context`, `top_k`, `datasets`, `system_prompt`, and `include_references` along the way. `RAG_COMPLETION` always performs the same three steps: retrieve relevant information, build the context, and generate the answer.

## Before You Start

* Complete [Quickstart](/getting-started/quickstart) to understand basic operations
* Ensure you have [LLM Providers](/setup-configuration/llm-providers) configured
* Be familiar with the [`remember()`](/core-concepts/main-operations/remember) workflow
* See [Recall](/core-concepts/main-operations/recall) for the full definition of each parameter demonstrated here (`only_context`, `top_k`, `datasets`, `system_prompt`, `include_references`)

## Code in Action

```python theme={null}
import asyncio

import cognee
from cognee import SearchType

DATASET_NAME = "cognee_recall_demo"

DOCUMENTS = [
    """
    Alice is learning how to use Cognee.
    She stores her project documentation using cognee.remember().
    """,
    """
    Bob is helping Alice understand retrieval.
    He explains that SearchType.RAG_COMPLETION retrieves relevant document chunks before generating an answer.
    """,
    """
    Bob also explains that only_context=True returns the retrieved context
    without asking the language model to generate a response.
    """,
]

QUERY = "What does only_context=True do?"


async def main():
    await cognee.remember(
        DOCUMENTS,
        dataset_name=DATASET_NAME,
    )

    context = await cognee.recall(
        QUERY,
        query_type=SearchType.RAG_COMPLETION,
        datasets=[DATASET_NAME],
        top_k=2,
        only_context=True,
    )

    print("Retrieved context:\n")
    print(context)

    answer = await cognee.recall(
        QUERY,
        query_type=SearchType.RAG_COMPLETION,
        datasets=[DATASET_NAME],
        top_k=2,
    )

    print("\nGenerated answer:\n")
    print(answer)

    answer1 = await cognee.recall(
        QUERY,
        query_type=SearchType.RAG_COMPLETION,
        datasets=[DATASET_NAME],
        top_k=2,
        include_references=True,
    )

    print("\nAnswer with references:\n")
    print(answer1)

    answer2 = await cognee.recall(
        QUERY,
        query_type=SearchType.RAG_COMPLETION,
        datasets=[DATASET_NAME],
        top_k=2,
        system_prompt="Answer in two sentences.",
        include_references=True,
    )

    print("\nAnswer in two sentences:\n")
    print(answer2)

    answer3 = await cognee.recall(
        QUERY,
        query_type=SearchType.RAG_COMPLETION,
        datasets=[DATASET_NAME],
        top_k=2,
        system_prompt="Answer with emojis and exclamation marks.",
        include_references=True,
    )

    print("\nAnswer with emojis:\n")
    print(answer3)


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

## What Just Happened

### Step 1: Ingest the Example Documents

```python theme={null}
await cognee.remember(
    DOCUMENTS,
    dataset_name=DATASET_NAME,
)
```

`remember()` ingests the three short documents into an isolated dataset, so `recall()` has something to search. `dataset_name` chooses which dataset the data goes into. Every `recall()` call below passes that same name via `datasets=[DATASET_NAME]`, so it searches only this dataset — not everything you may have stored.

### Step 2: Retrieve Only the Context

```python theme={null}
context = await cognee.recall(
    QUERY,
    query_type=SearchType.RAG_COMPLETION,
    datasets=[DATASET_NAME],
    top_k=2,
    only_context=True,
)

print("Retrieved context:\n")
print(context)
```

With `only_context=True`, Cognee retrieves the two most relevant chunks (`top_k=2`) and assembles them into context — then stops. No language model is called, so this shows exactly what would be sent to it. `print(context)` lets you see exactly which chunks were considered most relevant to the query, before any answer is generated from them.

### Step 3: Generate the Answer

```python theme={null}
answer = await cognee.recall(
    QUERY,
    query_type=SearchType.RAG_COMPLETION,
    datasets=[DATASET_NAME],
    top_k=2,
)

print("\nGenerated answer:\n")
print(answer)
```

The same call without `only_context=True` retrieves the same chunks and builds the same context, but this time sends it to a language model along with the query. `print(answer)` lets you see this generated answer on its own, now that the context has been used to produce it. A typical result:

```text theme={null}
Setting only_context=True returns the retrieved context without prompting the language model to generate a response.
```

(The exact wording depends on the LLM provider you use.)

### Step 4: Include Supporting References

```python theme={null}
answer1 = await cognee.recall(
    QUERY,
    query_type=SearchType.RAG_COMPLETION,
    datasets=[DATASET_NAME],
    top_k=2,
    include_references=True,
)

print("\nAnswer with references:\n")
print(answer1)
```

Same retrieval and context as Step 3 — `include_references=True` appends an Evidence section listing which retrieved chunks the answer was built from, without changing retrieval, context, or the answer's own wording. `print(answer1)` lets you see that Evidence section right below the answer text.

### Step 5: Customize the Answer with system\_prompt

```python theme={null}
answer2 = await cognee.recall(
    QUERY,
    query_type=SearchType.RAG_COMPLETION,
    datasets=[DATASET_NAME],
    top_k=2,
    system_prompt="Answer in two sentences.",
    include_references=True,
)

print("\nAnswer in two sentences:\n")
print(answer2)

answer3 = await cognee.recall(
    QUERY,
    query_type=SearchType.RAG_COMPLETION,
    datasets=[DATASET_NAME],
    top_k=2,
    system_prompt="Answer with emojis and exclamation marks.",
    include_references=True,
)

print("\nAnswer with emojis:\n")
print(answer3)
```

Same retrieval, same context as Step 3 for both calls — only `system_prompt` changes. One instructs the model to answer in two sentences; the other asks for emojis and exclamation marks instead. `system_prompt` only ever affects how the final answer is phrased, never what is retrieved or how the context is built.

`print(answer2)` and `print(answer3)` let you compare the two styles side by side — and with `include_references=True` on both, you can also see that the Evidence section lists the exact same retrieved chunks for each, confirming that only the answer's style changed, not what was retrieved. Possible answers are:

```text theme={null}
Setting only_context=True retrieves the relevant context without prompting the language model to generate a response. This allows users to access the pertinent information directly, without any additional output from the model.
```

for `answer2`, and:

```text theme={null}
Setting only_context=True retrieves the context directly, without generating a response! 🎉📚✨
```

for `answer3`. (The exact wording depends on the LLM provider you use.)

## Under the Hood

<Accordion title="How RAG_COMPLETION Works">
  `SearchType.RAG_COMPLETION` always performs the same three steps:

  1. **Retrieve relevant information** — Cognee searches the stored documents and selects the text chunks most relevant to your query.
  2. **Build the context** — the retrieved chunks are combined into a single context containing the information needed to answer the question.
  3. **Generate the answer** — Cognee sends the context, together with your query, to a language model, which uses it to generate the final answer.

  `only_context=True` stops the process after Step 2 and returns the context instead of continuing to Step 3.
</Accordion>

<Columns cols={2}>
  <Card title="Recall" icon="search" href="/core-concepts/main-operations/recall">
    Understand recall()'s full parameter surface and auto-routing behavior
  </Card>

  <Card title="Inspecting Hybrid Retrieval Context" icon="layers" href="/guides/hybrid-retrieval-recall">
    Go deeper with SearchType.HYBRID\_COMPLETION once you're comfortable here
  </Card>
</Columns>
