What is the recall operation
The.recall operation is the main retrieval entry point in Cognee v1.0. It searches memory using the best available source for the request.
- Auto-routing by default: when you do not specify a search type,
recall()matches the query against a short table of rules and picks a retrieval strategy automatically. The table is deliberately narrow — only five rules — so most queries land on theHYBRID_COMPLETIONdefault. - Session-aware: with
session_id, it can search session cache entries first and fall through to the permanent graph if needed. - Graph-backed by default: for permanent memory,
recall()runs graph retrieval — not plain embedding similarity.HYBRID_COMPLETIONis the fallback whenever no routing rule matches, which is the common case. - Source tagging: each recall result includes a
sourcefield ("graph","session","trace","session_context", …) so you can tell where it came from — see the full source table.
Where recall fits
- Use
recall()as the default way to ask questions over memory in v1.0. - Use it after Remember has created either permanent or session memory.
- Use explicit
query_typeonly when you want to force a specific retrieval mode. - Use datasets to scope results to a specific knowledge base.
What happens under the hood
-
Check session scope
- If you pass
session_idwithoutdatasetsand withoutquery_type, Cognee first searches the session cache directly. - Session search is keyword-based over stored question, context, and answer fields.
- If you pass
-
Choose the retrieval strategy
- If
query_typeis provided, Cognee uses it directly. - Otherwise, if
auto_route=True, a rule-based router checks the query against five ordered rules and usesHYBRID_COMPLETIONwhen none matches. See Auto-routing behavior below for the exact rules. - If
auto_route=False, Cognee falls back toHYBRID_COMPLETION. - If no usable LLM is configured, routing still runs, but only to types that work without one, and the default becomes
HYBRID_COMPLETIONwithonly_context=True, which returns the assembled prompt instead of an answer. This is decided by LLM availability alone, never by which extractor built the graph. See Without an LLM in Auto-routing behavior below. - If a rule matched and the backend rejects the routed type, recall retries once as
HYBRID_COMPLETION. It does the same when a routedCODEorBROADsearch cannot answer the datasets, and when a routedCHUNKS_LEXICAL,CODING_RULES,CODEorBROADsearch returns nothing.
- If
-
Run graph retrieval when needed
- If session search finds nothing, or if graph retrieval is requested,
recall()queries the permanent knowledge graph. - The retrieval strategy selected in step 2 determines how that graph query is executed.
- If session search finds nothing, or if graph retrieval is requested,
After recall finishes
- Session-only recall: you get matching session entries when cache hits exist, each tagged with
source="session". - Graph-backed recall: you get normalized graph result objects tagged with
source="graph". - Hybrid behavior: with
session_idplus graph-scoping inputs likedatasetsorquery_type, recall uses the permanent graph path rather than session-only lookup.
Examples and details
Prerequisites before calling recall
Prerequisites before calling recall
recall() only reads from memory — it never initializes anything itself. Populate memory first with remember() (or the legacy add() + cognify() sequence). The first ingestion run creates the relational, vector, and graph databases and the default user.recall() before any data exists, it raises RecallPreconditionError (HTTP 422), triggered by the underlying DatabaseNotCreatedError (“The database has not been created yet. Please call await setup() first.”) or UserNotFoundError. The fix is to run remember() (or add() + cognify()) first.recall() can also fail when the configured LLM provider (or LiteLLM proxy) reports that its token budget is exhausted. In that case it raises LLMPaymentRequiredError, which the API surfaces as HTTP 402 (Payment Required) with body {"detail": "LLM provider requires payment or token budget is exhausted. [LLMPaymentRequiredError]"} — or, when the provider’s own budget sentence can be identified, {"detail": "LLM budget exhausted: <provider sentence> [LLMPaymentRequiredError]"} (see 402 Payment Required). This error is terminal — Cognee does not retry budget-exhaustion failures — so treat a 402 as final for the request and prompt the user to top up their token budget rather than reissuing the call.recall() also accepts only its documented parameters — there is no catch-all **kwargs. Passing an unsupported keyword such as dataset_name raises a TypeError. Use node_name to scope retrieval to specific node sets, or add node_type to scope it to named graph nodes of one type (for example node_type=TextDocument). See the recall() API reference for the full parameter list.Recall while indexing is still running
Recall while indexing is still running
recall() can run while another dataset is still being ingested or indexed in the background.- There is no global lock that blocks retrieval while
remember()is processing. recall()only sees data that has already made it through indexing.- If a dataset is mid-run, results may be incomplete until that run reaches completion.
cognee.datasets.get_status() or the indexing-status guidance on Remember.Auto-routing behavior
Auto-routing behavior
Auto-routing is on by default, and it is rule-based, not LLM-based.
recall() decides the search type in one of these ways:What the router recognizes
Rules are checked in order and the first match wins. The shape rule comes first, so a query that is entirely quoted is treated as what it looks like even when the text inside also reads as intent:
"coding rules" — with the quotes — is a lexical search, while What are our coding rules? routes to CODING_RULES. A count question that is also a code question goes to CODE, because BROAD reads document text and code has none. A count scoped to a date (how many tickets were opened in 2024?) goes to BROAD, because TEMPORAL only reranks hybrid’s top results and cannot count. The temporal rule comes last, so a coding-rules question that also names a date keeps its CODING_RULES route.When the router picks CODE and you also pass retriever_specific_config, your keys are merged over the router’s ask config, so a key you set (for example question) wins. Routed CODE results still count only when they carry ask/subgraph seeds, so overriding operation with another operation makes the search come back empty and retry as HYBRID_COMPLETION; pin query_type=SearchType.CODE to run a different operation.Everything else is reachable only by passing query_type yourself. That includes GRAPH_COMPLETION_COT, GRAPH_COMPLETION_CONTEXT_EXTENSION, GRAPH_SUMMARY_COMPLETION, CYPHER, GRAPH_COMPLETION, SUMMARIES, CHUNKS, RAG_COMPLETION, GRAPH_COMPLETION_DECOMPOSITION, HYBRID_COMPLETION_DECOMPOSITION, NATURAL_LANGUAGE, and AGENTIC_COMPLETION. The router is scoped this way on purpose: it may only pick a strategy that is at least as good as HYBRID_COMPLETION on a default-built graph and that does not add LLM calls without an unambiguous signal. HYBRID_COMPLETION already searches document chunks, summaries, and the entity neighbourhood in one LLM call, so the first four rules fire only on inputs for which hybrid is the wrong operation rather than a worse one: input that is not a natural-language question, a question about code (hybrid cannot reach the code graph), or a count (hybrid sees only the passages most similar to the question). The temporal rule is the one exception: it fires on a question scoped to an absolute date, and TEMPORAL reranks hybrid’s own candidates by that date rather than shrinking the context. Other question-shaped intent (summary, reasoning, context extension) stays behind an explicit query_type. Pass query_type=SearchType.TEMPORAL yourself for time questions the rule does not catch.The quoted-phrase, coding-rules and code-question rules land on retrieval-only types, so an auto-routed call is not guaranteed to produce a generated answer — though the retry below covers the case where the routed type comes up empty. Beyond those three, FEELING_LUCKY’s LLM selector is the only thing that can reach a retrieval-only type on its own: it can pick SUMMARIES or CHUNKS, which return payloads instead of an answer, so if you want an answer every time, do not use FEELING_LUCKY. For the full answer-vs-payload breakdown per type, see SearchType and What recall returns.When a routed guess missesRecall re-runs the search as HYBRID_COMPLETION when the guess does not work out:- the backend rejects the routed type (
UnsupportedSearchTypeError/SearchTypeNotSupported) — a deployment-level choice, not the caller’s; this applies to every rule; - the routed lane cannot answer these datasets: a routed
CODEraisesCodeSeedNotFoundError(no symbol matched) orCodeGraphUnavailableError(the dataset has no code graph), or a routedBROADraisesBroadQueryError,BroadLimitErrororBroadNoTextError; or - a routed
CHUNKS_LEXICAL,CODING_RULES,CODEorBROADreturned no results at all. For a routedCODE, datasets whoseaskfound no symbol, or that have no code graph, count as misses, so a search where every dataset missed is empty and is retried. A routedTEMPORALis not retried on empty: when it finds no time window or nothing dated inside it, it already answers with plain hybrid results.
query_type you pinned yourself (including CODE or BROAD) is never second-guessed — it raises or returns empty as usual — and neither is the HYBRID_COMPLETION default itself. With no usable LLM the retry runs as HYBRID_COMPLETION with only_context=True. Each retry is logged at INFO (Rule … routed to …, which returned nothing; retrying as HYBRID_COMPLETION., or … which could not answer (…); retrying as HYBRID_COMPLETION. when the routed lane raised), and each result’s search_type reports the type that actually answered.Without an LLMWhen no usable LLM is configured (the provider needs a key and none is set), auto-routing still runs, but each pick is checked against what can run without an LLM:- A routed
CHUNKS_LEXICAL,CODING_RULESorCODEruns as usual; none of them calls an LLM. - A routed
TEMPORAL, which needs an LLM to extract its time window, orBROAD, which needs one to decide how to answer, resolves toHYBRID_COMPLETIONwithonly_context=True. - The default, and a pinned
HYBRID_COMPLETION,GRAPH_COMPLETIONorRAG_COMPLETION, run withonly_context=True: the result’stextis the user prompt andsystem_promptholds the system prompt an LLM would have received. A pinned type is never rerouted, so any other pinned type that needs an LLM (for exampleGRAPH_COMPLETION_COT) still fails without one.
DEBUG level under the query_router logger (see Logging). The line carries the matched rule name only — never the query text:rule=default is not an error — it is the normal line for a plain factual question, and it means recall ran HYBRID_COMPLETION. You can also read the type that actually ran off each result’s search_type field.When you pass query_type, the router does not run at all, so there is no routing line to read and no LLM cost either way.When to override query_type- You want raw payloads rather than a generated answer — pass
CHUNKSorSUMMARIES. - You want a strategy the router no longer picks for you. Chain-of-thought reasoning, context extension, and summary completion all take an explicit value now: pass
query_type=SearchType.GRAPH_COMPLETION_COT,GRAPH_COMPLETION_CONTEXT_EXTENSION, orGRAPH_SUMMARY_COMPLETION. Time-aware search is routed only for absolute dates; passTEMPORALfor anything else. - Your query needs a multi-part breakdown that suits
GRAPH_COMPLETION_DECOMPOSITIONorHYBRID_COMPLETION_DECOMPOSITION(the router never picks either), or another type outside the router’s five rules (GRAPH_COMPLETION,RAG_COMPLETION,NATURAL_LANGUAGE,AGENTIC_COMPLETION, …). The deprecatedTRIPLET_COMPLETIONnow runs asGRAPH_COMPLETION, with aFutureWarning. - A quoted query routed to lexical search when you wanted an answer — drop the quotes, or pass
query_type=SearchType.HYBRID_COMPLETION. - You want predictable latency and cost across calls — pinning
query_typemakes every call use the same retriever.auto_route=Falsepins it toHYBRID_COMPLETION.
How recall relates to retrievers
How recall relates to retrievers
Most users should think in terms of asking memory a question, not selecting a retriever manually.Under the hood, retrieval strategies — graph completion, summary, temporal, lexical, coding-rules — do the actual work.
recall() is intentionally one layer above them:- you call
recall() - Cognee chooses or accepts a
query_type - the matching retriever runs underneath
- the result comes back through the recall API
get_retrieved_objects(), get_context_from_objects(), and get_completion_from_context() — and the last two take the evidence as an argument, so they can also format evidence you assembled yourself. HybridRetriever renders a dictionary keyed chunks, entities, and facts, the sections the Inspecting Hybrid Retrieval Context guide tunes; a chunk_summaries key is accepted but not rendered.The demo examples/demos/graph_completion_to_hybrid.py shows this end to end. It runs a GraphCompletionRetriever search and sorts the returned triplets into that shape: DocumentChunk nodes become chunks, Entity nodes become entities with their edges attached, and a labeled edge touching no retrieved entity becomes a fact. A TextSummary paired with its source chunk goes into chunk_summaries, so it is not rendered; an unpaired one is kept as a passage. The result goes to hybrid’s context and completion stages, so the printed context and answer match the format SearchType.HYBRID_COMPLETION produces.What recall returns
What recall returns
- Session-only recall returns matching session cache entries.
- Graph-backed recall returns the output of the underlying retrieval mode selected by the router or
query_type. - Depending on the retrieval path, each graph result object’s
textcan contain a plain answer, retrieved context, chunk text, or rendered structured output. - Each recall result is tagged with
sourceso callers can distinguish session, graph, trace, and graph-context results. only_context=Trueskips the final LLM answer-generation step and returns what the LLM would have received instead — the user prompt for completion types, the retrieved context for the rest.verbose=Trueexposes extra retrieval details from the lower-level graph search path.
- Session Results
- Graph Results
When
recall() returns session cache hits, the result is a list of ResponseQAEntry objects tagged with source="session".These entries follow the session QA shape documented in Sessions and Caching, with fields such as:timeqa_idquestioncontextanswerfeedback_textfeedback_scoresource
Using only_context
Using only_context
Set This is useful when you want to:
only_context=True when you want what the LLM would have been sent, without asking Cognee to produce a final answer.When only_context=True, Cognee stops before the completion call:- the LLM answer is not generated
- the final completion step is skipped
- for completion search types the returned
textis the user prompt — the conversation history, then the question and retrieval context rendered through the retriever’s template, then the session guidance block — and the retriever’s task template is on the item’s separatesystem_promptfield - for the non-generative types (
CHUNKS,SUMMARIES,CODE, …) and the opt-outsCYPHERandAGENTIC_COMPLETION, which never send one templated prompt,textis the retrieved context as before
- inspect what would have been sent before answer generation
- hand the prompt to your own model instead of Cognee’s
- debug retrieval quality separately from answer quality
Session cache reads and writes during recall
Session cache reads and writes during recall
session_id makes recall session-aware, but the exact behavior depends on the recall mode.Session reads:- With
session_idand no explicitquery_type,recall()searches session-cache QA entries by keyword and returns matches tagged withsource="session". - If
session_idis used withdatasetsordataset_ids, recall can combine session lookup with graph retrieval. - If you pass an explicit
query_type, the default path is graph-backed retrieval. Session history can still be used during the LLM completion step, but session-cache QA lookup is not part of the default source set unless you passscope. scope=["session_first"]asks for the session-hit short-circuit by name: it expands tosessionplusgraph, and a session hit still skips the graph search. Use it when you want that behavior together with inputs that would otherwise disable it, such as an explicitquery_typeordatasets.scopealso reaches the two session sources thatautonever picks on its own:scope=["trace"]searches recorded agent traces, andscope=["session_context"]renders the session’s accumulated guidance. The guidance read takes acontext_profile—"qa"(the default) for what conversation turns taught the session, or"agent"for lessons drawn from agent tool traces — and the two profiles are separate, so a query under one never returns the other’s entries. Both reads are read-only unless you passrecord_context_usage=True, which stamps the guidance served in your own session and archives agent guidance that has gone unused. See therecall()API reference for every scope value andcontext_profile.
session_id and the LLM completion step is enabled, Cognee loads prior session conversation history and prepends it to the completion prompt. If improve() has built the global context index and the retriever is configured with include_global_context_index, a background-knowledge prelude — the dataset’s root summary plus the top matching bucket summaries — is also prepended. That prelude comes from the index, not from a per-session snapshot.Session writes:When the LLM completion step runs through session-enabled graph retrieval, Cognee appends a new QA entry to the session cache with the question, stored context, and generated answer. The next compatible recall on the same session_id can see that entry.A turn that is gated by the session-context analysis — a feedback-only or instruction-only message, which returns a short acknowledgement rather than a generated answer (see Session-context guidance) — is appended too, with the raw message as question, the acknowledgement as answer, and an empty context. So a QA entry is written for every recall turn the session layer answers or gates — but not for a turn that skips completion entirely, which is the only_context=True case below.Using only_context=True:Pass only_context=True to skip the final LLM completion. Because the QA write happens during completion, only_context=True also avoids adding a new QA entry to the session cache.only_context=True when you want the LLM input without LLM summarization and without growing the session cache.Dataset scoping
Dataset scoping
- Scoping is exclusive. When you pass
datasets(ordataset_ids), retrieval runs against only those datasets — Cognee does not pull from any other dataset, even ones the current user can read. - When you omit both, recall is routed: it searches the readable datasets most likely to hold the answer, not all of them. See Dataset routing below. Supply a dataset to choose the scope yourself.
datasetslimits graph retrieval to named datasets. With backend access control enabled, names are resolved only against datasets owned by the current user.dataset_idsscopes retrieval by dataset UUID instead of name. Use this for shared datasets that the current user can access but did not create. When supplied, it takes precedence overdatasetsand the name-to-UUID resolution step is skipped.- With
session_idplus eitherdatasetsordataset_ids, recall becomes hybrid: session context is available, but graph retrieval is scoped to the selected dataset or dataset UUIDs.
Dataset routing
Dataset routing
A
recall() or search() that names no dataset (no datasets, no dataset_ids) is routed to the readable datasets most likely to hold the answer:- Scoring. Every readable dataset is scored against the query using its global context index: the dataset’s root and one bucket per document. A dataset’s score is the cosine distance of its best-matching row, so a specific question is carried by the document that matches and a broad one by the root.
- Selection. Only the best
DATASET_ROUTING_TOP_Kdatasets (default1) are searched. Datasets tied with the last selected one (withinDATASET_ROUTING_TIE_MARGIN) are searched too. - Cutoff. A dataset farther than
DATASET_ROUTING_DISTANCE_CUTOFF(default0.8) is not a candidate. When no dataset is within the cutoff, every readable dataset is searched, so a question no dataset knows about is not answered from whichever happens to be nearest. - Unindexed datasets. A dataset with no index yet (never improved, the index turned off, or a code-only dataset) is not searched next to a routed dataset. It is searched by the widening pass when the routed datasets retrieve nothing, and when no dataset is routed at all, since every readable dataset is searched then. Run
improve()to build its index so it can be routed to directly, or passdatasets=[...]. - Widening. If the routed datasets retrieve nothing, the search continues over the datasets routing skipped, unindexed ones included, and merges their results.
- Logging. Every unscoped search logs at info level which datasets it covers, why, and each dataset’s distance, with the hint to pass
datasets=[...].
datasets or dataset_ids is never routed: exactly those datasets are searched. A CODE search is never routed either: a code dataset has no index rows, so it searches every readable dataset. There is no switch to turn routing off. It is inactive when ENABLE_BACKEND_ACCESS_CONTROL=false, where all datasets share one store, and when the user can read fewer than two datasets. It also needs a default vector store that can score rows by id (LanceDB, pgvector, or Turso); on any other store every readable dataset is searched.Routing assumes one embedding model for the whole deployment. If you change
EMBEDDING_MODEL without pruning, routing logs a warning and steps aside, and unscoped searches cover every readable dataset until the vector stores are pruned and the index is rebuilt. Routing rows follow deletion: deleting a document or dataset, or forget() (including memory_only=True), removes them, and prune_system drops the routing collection. After documents (not a whole dataset) are deleted from a dataset indexed by the default method, the dataset’s root routing row is written again at once from the remaining documents, so broad queries still reach the dataset. The remaining documents’ rows keep their text until the next improve().Parameters
Parameters
- Basic Parameters
- Advanced Parameters
Under the hood — legacy operations
Under the hood — legacy operations
recall() runs Search under the hood for graph-backed retrieval.Use legacy Search directly when you need to select a specific retriever, inspect retrieval internals, or use advanced parameters not exposed by recall(). See also Search Basics for the full set of retrieval options.recall() vs search(): when to use each
recall() vs search(): when to use each
Use
recall() when you want to ask a question and get an answer. It handles routing, session lookup, and source attribution automatically.Use search() directly when you need a specific retriever, lower-level parameters such as skills, tools or max_iter, or when building custom pipelines.Remember
Create permanent or session memory
Improve
Enrich the graph for better future recall
Understand Recall with RAG Completion
Hands-on guide to recall() and RAG_COMPLETION