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 to understand basic operations
- Ensure you have LLM Providers configured
- Be familiar with the
remember()workflow - See Recall for the full definition of each parameter demonstrated here (
only_context,top_k,datasets,system_prompt,include_references)
Code in Action
What Just Happened
Step 1: Ingest the Example Documents
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
only_context=True, Cognee retrieves the two most relevant chunks (top_k=2), assembles them into context and renders the prompt around them — then stops. No language model is called, so this shows exactly what would have been 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
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:
Step 4: Include Supporting References
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
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:
answer2, and:
answer3. (The exact wording depends on the LLM provider you use.)
Under the Hood
How RAG_COMPLETION Works
How RAG_COMPLETION Works
SearchType.RAG_COMPLETION always performs the same three steps:- Retrieve relevant information — a vector search over the stored document chunks returns the
top_kchunks closest to your query. - Build the context — the retrieved chunks’ text is concatenated in rank order, separated by newlines, into a single context string. Nothing is added: no summarization, no expansion to neighboring chunks, no graph lookup. With sessions enabled, a follow-up turn also retrieves for a conversation-aware rewrite of the query, but the two lanes are merged back into the same
top_kchunks. - 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 prompt built around that context instead of continuing to Step 3.When the Retrieved Chunks Only Hold Part of the Answer
When the Retrieved Chunks Only Hold Part of the Answer
The context never holds more than those
top_k chunks carry, so the answer can only be as complete as they are. If the prompt you see under only_context=True covers just part of what the query asks for, raise top_k: this guide pins it to 2 to keep the printed prompt short, while recall() defaults to 15. More chunks mean broader coverage and proportionally more prompt tokens.When no top_k is enough because the answer depends on relationships rather than passages, switch to a search type that assembles context from more than chunk text — see Search Types.Recall
Understand recall()‘s full parameter surface and auto-routing behavior
Inspecting Hybrid Retrieval Context
Go deeper with SearchType.HYBRID_COMPLETION once you’re comfortable here