cognee.search()
Description
Search and query the knowledge graph for insights, information, and connections. This is the final step in the Cognee workflow that retrieves information from the processed knowledge graph. It supports multiple search modes optimized for different use cases - from simple fact retrieval to complex reasoning and code analysis. Search Prerequisites:- LLM_API_KEY: Required for GRAPH_COMPLETION and RAG_COMPLETION search types
- Data Added: Must have data previously added via
cognee.add() - Knowledge Graph Built: Must have processed data via
cognee.cognify() - Dataset Permissions: User must have ‘read’ permission on target datasets
- Vector Database: Must be accessible for semantic search functionality
- “What are the main themes in this research?”
- “How do these concepts relate to each other?”
- “Find information about machine learning algorithms”
- “What functions handle user authentication?”
- Single dataset: “research_papers”
- Multiple datasets: [“docs”, “reports”, “analysis”]
- None: Search across all user datasets
- GRAPH_COMPLETION: Slower but most intelligent, uses LLM + graph context
- RAG_COMPLETION: Medium speed, uses LLM + document chunks (no graph traversal)
- CHUNKS: Fastest, pure vector similarity search without LLM
- SUMMARIES: Fast, returns pre-computed summaries
- CODING_RULES: Medium speed, specialized for code understanding
- FEELING_LUCKY: Variable speed, uses LLM + search type selection intelligently
- top_k: Start with 10, increase for comprehensive analysis (max 100)
- datasets: Specify datasets to improve speed and relevance
- Use results for further analysis or application integration
- Combine different search types for comprehensive understanding
- Export insights for reporting or downstream processing
- Iterate with refined queries based on initial results
- LLM_API_KEY: API key for your LLM provider
- LLM_PROVIDER, LLM_MODEL: Configure LLM for search responses
- VECTOR_DB_PROVIDER: Must match what was used during cognify
- GRAPH_DATABASE_PROVIDER: Must match what was used during cognify
Parameters
Natural language search query.
Type of search to perform.
User performing the search.
Dataset name(s) to search within. Dataset names are resolved only against datasets owned by the searching user.
Dataset UUID(s) to search within. Use these for shared datasets that the user can access but did not create.
Path to a custom system prompt file.
Inline system prompt string (overrides system_prompt_path).
Maximum number of results to return.
Filter results to a specific DataPoint subclass type. Pass any class that inherits from
DataPoint, including custom classes you define in your own code. Defaults to NodeSet (the built-in group container). Internal Cognee types such as ParagraphNode are not part of the public API and cannot be used here.Names of the node sets to filter results to. Pass the same names used in
cognee.add(..., node_set=[...]). Works with graph-completion search types (e.g. GRAPH_COMPLETION, GRAPH_COMPLETION_COT, TEMPORAL). See NodeSets.Controls how multiple
node_name values are combined. "OR" returns results connected to any of the specified node sets; "AND" returns results connected to all of them.If true, return only the retrieved context without LLM completion.
Session ID for conversational context tracking.
Number of candidates for the wide search phase.
Penalty factor for triplet distance in scoring.
Include detailed retrieval metadata in results.
Additional configuration for the selected retriever.
Returns
List[SearchResult]
For the full breakdown of per-mode output shapes, see Search. The search-type accordions there now document each mode’s output directly.
Examples
Troubleshooting
Fixing 'Nodeset does not exist' (EntityNotFoundError)
Fixing 'Nodeset does not exist' (EntityNotFoundError)
NodeSets are created at ingestion time and referenced at search time — the names must match. During In regular
remember() or add(), the node_set tags you pass are attached to your data and materialized as NodeSet nodes when the graph is built. At search time, passing node_type=NodeSet with node_name=[...] projects only the subgraph connected to those names.If none of the requested names resolve to a populated subgraph, lower-level graph projection can raise:search() or recall() flows, this can also appear as empty context or no results, depending on the search path.Common causes:- The name was never created during ingestion. You filtered on a name (e.g.
"finance") that was not passed innode_setduring anyremember()oradd()call. A NodeSet only exists if data was tagged with it. - A typo or case mismatch. Names are matched exactly, so
"Finance"and"finance"are different NodeSets. - Search ran before ingestion finished. With
run_in_background=True, await theRememberResultbefore searching so theNodeSetnodes exist. - Wrong scope. NodeSets live in the graph they were ingested into. If you query a different dataset or a different user/tenant under multi-user mode, the names won’t be found.
ANDfiltering with no overlap. Usingnode_name_filter_operator="AND"requires nodes connected to all listed names simultaneously; if no node belongs to every name, the projection is empty.
search() or recall(), scoped to the same dataset.include_global_context_index only has an effect after the dataset has been improved with build_global_context_index=True. See Global Context Index.