cognee.search() to query your processed datasets. Covers the basic call, core parameters, and result shapes.
Before you start:
- Complete Quickstart to understand basic operations
- Ensure you have LLM Providers configured for LLM-backed search types
- Run
cognee.cognify(...)to build the graph before searching - Keep at least one dataset with
readpermission for the user running the search
Code in Action
SearchType.GRAPH_COMPLETION is the default. It returns an LLM-generated answer backed by context retrieved from your knowledge graph.What Just Happened
cognee.search() retrieved relevant context from the knowledge graph and passed it to the LLM to generate an answer. Results are returned as a list.
Parameters Reference
All examples below assume you are inside an async function. Import helpers when needed:Core Parameters
Core Parameters
-
query_text(str, required): The question or phrase to search for. -
query_type(SearchType, optional, default:SearchType.GRAPH_COMPLETION): Sets the search mode. See Search Types for the full list and Retrievers for how each type maps to a retriever. -
top_k(int, optional, default: 10): Maximum number of results to return. -
only_context(bool, optional, default: False): Skip the LLM completion step and return the retrieved context directly. This avoids the final LLM call and is useful when you want to inspect or reuse the context yourself.only_context=Trueworks with any search type. For LLM-completion types (GRAPH_COMPLETION,RAG_COMPLETION, etc.) it returns the text that would have been sent to the LLM. For retrieval-only types (CHUNKS,SUMMARIES) the behavior is effectively unchanged because no final LLM call is made.
Prompt & Generation Parameters
Prompt & Generation Parameters
-
system_prompt_path(str, optional, default:"answer_simple_question.txt"): Path to a prompt file packaged with your project. -
system_prompt(Optional[str]): Inline prompt string. Overridessystem_prompt_pathwhen set. -
only_context(bool, optional, default: False): Skip LLM generation and return the raw retrieved context directly as aUnion[str, List[str]]. Useful for inspecting what the retriever found, building custom prompts, or downstream processing without an LLM call.WhenENABLE_BACKEND_ACCESS_CONTROL=false(default) and a single dataset is searched, Cognee unwraps the list one level for backwards compatibility, so you typically get a single string or a flat list of strings:Addverbose=Trueto get the full breakdown (text_result,context_result,objects_result) alongside the context, instead of the unwrapped value:WhenENABLE_BACKEND_ACCESS_CONTROL=true, the result always includes dataset metadata regardless ofverbose:
Advanced Parameters
Advanced Parameters
wide_search_top_k(int, optional, default: 100): Caps initial candidate retrieval for graph-completion retrievers before ranking. Increase for broader recall on large graphs.triplet_distance_penalty(float, optional, default: 3.5): Penalty applied in graph retrieval ranking. Controls how triplet distance influences final result ordering.retriever_specific_config(dict, optional): Per-retriever options. Examples:response_modelfor typed LLM output;max_iterfor GRAPH_COMPLETION_COT;context_extension_roundsfor GRAPH_COMPLETION_CONTEXT_EXTENSION. See the API reference for full keys.verbose(bool, optional, default: False): Whentrue, results includetext_result,context_result, andobjects_resultfields alongside the answer.
Node Sets & Filtering Parameters
Node Sets & Filtering Parameters
These options scope the search to specific node sets. Set both
node_type and node_name to filter — use the same names you passed to cognee.add(..., node_set=[...]). See NodeSets for background.node_type(Optional[Type], optional, default:NodeSet): The graph model to search. Leave asNodeSetunless you have a custom node model.node_name(Optional[List[str]]): Names of the node sets to include.`node_name` example
node_name_filter_operator(str, optional, default:"OR"): Controls how multiple node-set names are combined."OR"returns results connected to any of the listed node sets;"AND"returns results connected to all of them. Case-insensitive.`node_name_filter_operator` example
Node-set filtering applies to graph-completion search types (
GRAPH_COMPLETION, GRAPH_COMPLETION_COT, GRAPH_COMPLETION_CONTEXT_EXTENSION, GRAPH_SUMMARY_COMPLETION, TEMPORAL). It has no effect on CHUNKS, SUMMARIES, RAG_COMPLETION, CYPHER, or NATURAL_LANGUAGE.Interaction & History Parameters
Interaction & History Parameters
session_id(Optional[str]): Links this search to a conversation session. When the samesession_idis reused, previous Q&A turns are included in the LLM prompt. Only effective forGRAPH_COMPLETION,RAG_COMPLETION, andTRIPLET_COMPLETION; other search types do not read or write session history. If omitted while caching is enabled, Cognee writes todefault_session.See Sessions Guide for complete examples. To record feedback on answers, see the Feedback System.
Datasets & Users
Datasets & Users
-
datasets(Optional[Union[list[str], str]]): Limit search to specific dataset names. -
dataset_ids(Optional[Union[list[UUID], UUID]]): Same asdatasets, using UUIDs instead of names. -
user(Optional[User]): The user to run the search as. Required for multi-tenant flows or background jobs.WhenENABLE_BACKEND_ACCESS_CONTROL=true:-
Result shape: Searches run only on datasets the user can access. Results are returned as a list of per-dataset objects (
dataset_name,dataset_id,search_result). Useverbose=Trueto includetext_result,context_result, andobjects_resultin each item. -
Parallel execution: Multiple datasets are searched concurrently using
asyncio.gather()— total time is roughly that of the slowest single-dataset search. -
If no
useris given,get_default_user()is used (created if missing); an error is raised only if this user lacks dataset permissions. -
If
datasetsis not set, all datasets readable by the user are searched. An error is raised if none are accessible or if a requested dataset is forbidden.
ENABLE_BACKEND_ACCESS_CONTROL=false:- Dataset filters (
datasets,dataset_ids) are ignored — all data is searched. - Results are returned as a plain list (e.g.
["answer1", "answer2"]). If only one dataset is searched and the retriever returns a list, Cognee may unwrap one level for backwards compatibility.
-
Result shape: Searches run only on datasets the user can access. Results are returned as a list of per-dataset objects (
Citation and Source Tracking
Provenance is available at two levels:- Dataset level — when
ENABLE_BACKEND_ACCESS_CONTROL=true, results are wrapped withdataset_nameanddataset_id. - Chunk/summary level —
CHUNKSandSUMMARIESresults include anidyou can use to look up the item in the graph.
Search results do not include source file paths.
raw_data_location and document name live on the Document node, not on retrieved chunk/summary payloads. To trace a result back to a file, use dataset provenance or query the graph by id.Chunk-level fields (`CHUNKS`)
Chunk-level fields (`CHUNKS`)
SearchType.CHUNKS returns a list of dicts with these fields:| Field | Type | Description |
|---|---|---|
id | str | Chunk UUID |
text | str | Raw chunk text |
chunk_index | int | Position of this chunk within the source document |
chunk_size | int | Token count of this chunk |
cut_type | str | How the boundary was chosen (sentence_end, paragraph_end, etc.) |
Summary-level fields (`SUMMARIES`)
Summary-level fields (`SUMMARIES`)
SearchType.SUMMARIES returns a list of dicts with these fields:| Field | Type | Description |
|---|---|---|
id | str | Summary UUID |
text | str | Summary text |
Dataset-level provenance (access control enabled)
Dataset-level provenance (access control enabled)
When When
ENABLE_BACKEND_ACCESS_CONTROL=true, every result is wrapped with dataset information:ENABLE_BACKEND_ACCESS_CONTROL=false, results are a plain list with no dataset_name or dataset_id wrapper.Raw source objects (LLM-completion modes)
Raw source objects (LLM-completion modes)
For modes that return a generated answer (
GRAPH_COMPLETION, RAG_COMPLETION, etc.), use verbose=True to receive the raw retrieved objects alongside the answer:Additional Examples
A complete runnable script:Expanded example
Expanded example
Custom Prompts
Learn about custom prompts for tailored answers
Permission Snippets
Multi-tenant deployment patterns
API Reference
Explore all search types and parameters
Sessions
Enable conversational memory with sessions
Agent Memory Decorator
Attach retrieval to an agent function boundary