Skip to main content

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 the HYBRID_COMPLETION default.
  • 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_COMPLETION is the fallback whenever no routing rule matches, which is the common case.
  • Source tagging: each recall result includes a source field ("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_type only when you want to force a specific retrieval mode.
  • Use datasets to scope results to a specific knowledge base.

What happens under the hood

  1. Check session scope
    • If you pass session_id without datasets and without query_type, Cognee first searches the session cache directly.
    • Session search is keyword-based over stored question, context, and answer fields.
  2. Choose the retrieval strategy
    • If query_type is provided, Cognee uses it directly.
    • Otherwise, if auto_route=True, a rule-based router checks the query against five ordered rules and uses HYBRID_COMPLETION when none matches. See Auto-routing behavior below for the exact rules.
    • If auto_route=False, Cognee falls back to HYBRID_COMPLETION.
    • If no usable LLM is configured, routing still runs, but only to types that work without one, and the default becomes HYBRID_COMPLETION with only_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 routed CODE or BROAD search cannot answer the datasets, and when a routed CHUNKS_LEXICAL, CODING_RULES, CODE or BROAD search returns nothing.
  3. 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.

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_id plus graph-scoping inputs like datasets or query_type, recall uses the permanent graph path rather than session-only lookup.

Examples and details

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.
If you call 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() 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.
If you need to confirm a dataset is fully ready before querying it, check its status with cognee.datasets.get_status() or the indexing-status guidance on Remember.
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 recognizesRules 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 CODE raises CodeSeedNotFoundError (no symbol matched) or CodeGraphUnavailableError (the dataset has no code graph), or a routed BROAD raises BroadQueryError, BroadLimitError or BroadNoTextError; or
  • a routed CHUNKS_LEXICAL, CODING_RULES, CODE or BROAD returned no results at all. For a routed CODE, datasets whose ask found no symbol, or that have no code graph, count as misses, so a search where every dataset missed is empty and is retried. A routed TEMPORAL is not retried on empty: when it finds no time window or nothing dated inside it, it already answers with plain hybrid results.
The retry applies only to a type the router chose. A 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_RULES or CODE runs as usual; none of them calls an LLM.
  • A routed TEMPORAL, which needs an LLM to extract its time window, or BROAD, which needs one to decide how to answer, resolves to HYBRID_COMPLETION with only_context=True.
  • The default, and a pinned HYBRID_COMPLETION, GRAPH_COMPLETION or RAG_COMPLETION, run with only_context=True: the result’s text is the user prompt and system_prompt holds the system prompt an LLM would have received. A pinned type is never rerouted, so any other pinned type that needs an LLM (for example GRAPH_COMPLETION_COT) still fails without one.
Confirming what the router choseThe router logs its decision at 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 CHUNKS or SUMMARIES.
  • 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, or GRAPH_SUMMARY_COMPLETION. Time-aware search is routed only for absolute dates; pass TEMPORAL for anything else.
  • Your query needs a multi-part breakdown that suits GRAPH_COMPLETION_DECOMPOSITION or HYBRID_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 deprecated TRIPLET_COMPLETION now runs as GRAPH_COMPLETION, with a FutureWarning.
  • 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_type makes every call use the same retriever. auto_route=False pins it to HYBRID_COMPLETION.
CYPHER is never auto-routed, whatever the query looks like — a query beginning with MATCH or RETURN runs as HYBRID_COMPLETION like any other text. A Cypher retriever runs the query text verbatim against the graph engine while recall only ever checks read permission, so routing on text alone would let a request body such as MATCH (n) DETACH DELETE n mutate the graph for anyone who can read it. Reaching CYPHER takes an explicit query_type=SearchType.CYPHER, which is a deliberate act by the caller. It still requires ALLOW_CYPHER_QUERY=true, which is off by default; otherwise it raises SearchTypeDisabledError (HTTP 403, a subclass of UnsupportedSearchTypeError): “CYPHER search is disabled by default for security reasons.”
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
If you want to understand or control the lower-level retrieval behavior directly, see the lower-level search reference.Each retriever exposes its stages as separate methods — 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.
  • 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 text can contain a plain answer, retrieved context, chunk text, or rendered structured output.
  • Each recall result is tagged with source so callers can distinguish session, graph, trace, and graph-context results.
  • only_context=True skips 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=True exposes extra retrieval details from the lower-level graph search path.
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:
  • time
  • qa_id
  • question
  • context
  • answer
  • feedback_text
  • feedback_score
  • source
Set 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 text is 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 separate system_prompt field
  • for the non-generative types (CHUNKS, SUMMARIES, CODE, …) and the opt-outs CYPHER and AGENTIC_COMPLETION, which never send one templated prompt, text is the retrieved context as before
This is useful when you want to:
  • 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
The prompt is assembled read-only by the same code a real completion uses: no LLM completion call, no session write, and no QA entry. Because it is one artifact rather than one entry per retrieved item, recall returns a single item for it; a query that retrieved nothing returns the bare context instead, so “nothing found” stays detectable. See Inspecting the LLM input for the full shape and its limits.
session_id makes recall session-aware, but the exact behavior depends on the recall mode.Session reads:
  • With session_id and no explicit query_type, recall() searches session-cache QA entries by keyword and returns matches tagged with source="session".
  • If session_id is used with datasets or dataset_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 pass scope.
  • scope=["session_first"] asks for the session-hit short-circuit by name: it expands to session plus graph, 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 explicit query_type or datasets.
  • scope also reaches the two session sources that auto never picks on its own: scope=["trace"] searches recorded agent traces, and scope=["session_context"] renders the session’s accumulated guidance. The guidance read takes a context_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 pass record_context_usage=True, which stamps the guidance served in your own session and archives agent guidance that has gone unused. See the recall() API reference for every scope value and context_profile.
Graph-backed completion with session history:When graph-backed recall runs with 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.
Use only_context=True when you want the LLM input without LLM summarization and without growing the session cache.
  • Scoping is exclusive. When you pass datasets (or dataset_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.
  • datasets limits graph retrieval to named datasets. With backend access control enabled, names are resolved only against datasets owned by the current user.
  • dataset_ids scopes 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 over datasets and the name-to-UUID resolution step is skipped.
  • With session_id plus either datasets or dataset_ids, recall becomes hybrid: session context is available, but graph retrieval is scoped to the selected dataset or dataset UUIDs.
If you set query_type=SearchType.AGENTIC_COMPLETION, the resolved graph scope must contain exactly one dataset. Passing multiple dataset names or UUIDs, or leaving scope broad enough to match multiple readable datasets, can raise 422 InvalidAgenticDatasetScope.
If Alice created shared_dataset and Bob only has permission to use it, Bob should query it with dataset_ids=[shared_id], not datasets=["shared_dataset"]. Name-based lookup fails for non-owners even when they have read access: names are resolved strictly, so any name that matches no dataset you own — shared, mistyped, or deleted — raises DatasetNotFoundError (HTTP 404) before any retrieval runs, rather than being dropped from the scope.
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_K datasets (default 1) are searched. Datasets tied with the last selected one (within DATASET_ROUTING_TIE_MARGIN) are searched too.
  • Cutoff. A dataset farther than DATASET_ROUTING_DISTANCE_CUTOFF (default 0.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 pass datasets=[...].
  • 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=[...].
Bypassing routing. Passing 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().
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.
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