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) 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
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 — Cognee searches the stored documents and selects the text chunks most relevant to your query.
- Build the context — the retrieved chunks are combined into a single context containing the information needed to answer the question.
- 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.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