Skip to Content
How-to GuidesSearch Guide

Search Guide

Cognee provides powerful search capabilities to query your knowledge graph. This guide explains the different search types and how to use them effectively.

Note: For a comprehensive reference of all available search types, see the Search Types Reference.

Search Types

Cognee offers several main types of search:

Insights search helps you discover connections and relationships in your knowledge graph:

from cognee.modules.search.types import SearchType import cognee import asyncio async def main(): results = await cognee.search( query_text="What is the relationship between Einstein and Germany?", query_type=SearchType.INSIGHTS ) for result in results: print(result) if __name__ == "__main__": asyncio.run(main())

Use insights search when you want to:

  • Discover relationships between entities
  • Understand how concepts are connected
  • Get a deeper understanding of your knowledge graph

Information search retrieves specific facts and information from your knowledge graph:

results = await cognee.search( query_text="When was Einstein born?", query_type=SearchType.INFORMATION )

Use information search when you want to:

  • Find specific facts
  • Get direct answers to questions
  • Retrieve precise information

RAG search combines retrieval from your knowledge graph with generative AI to provide comprehensive answers:

results = await cognee.search( query_text="Explain Einstein's contributions to physics", query_type=SearchType.RAG )

Use RAG search when you want to:

  • Get detailed explanations
  • Combine multiple pieces of information
  • Generate comprehensive answers based on your knowledge graph

4. Additional Search Types

Cognee offers several additional specialized search types:

  • SUMMARIES: Get concise summaries of topics
  • CODE: Find code-related information
  • GRAPH_COMPLETION: Get contextually aware answers using graph traversal
  • GRAPH_SUMMARY_COMPLETION: Combine graph traversal with summarization

For details on these and other search types, see the Search Types Reference.

Advanced Search Options

Filtering by Node Type

You can filter search results by node type:

results = await cognee.search( query_text="Your query", query_type=SearchType.INSIGHTS, node_types=["Person", "Organization"] # Only include these node types )

Searching with Context

You can provide additional context for your search:

results = await cognee.search( query_text="Your query", query_type=SearchType.INSIGHTS, context="Additional context to help refine the search" )

Search Examples

Example 1: Finding Connections Between People

# Add some content await cognee.add("Steve Jobs co-founded Apple with Steve Wozniak in 1976.") await cognee.add("Tim Cook became CEO of Apple after Steve Jobs.") # Process the content await cognee.cognify() # Search for connections results = await cognee.search( query_text="What is the relationship between Steve Jobs and Tim Cook?", query_type=SearchType.INSIGHTS )

Example 2: Getting Specific Information

# Add some content await cognee.add("The Eiffel Tower was completed on March 31, 1889. It is 330 meters tall.") # Process the content await cognee.cognify() # Search for specific information results = await cognee.search( query_text="When was the Eiffel Tower completed?", query_type=SearchType.INFORMATION )

Example 3: Generating Comprehensive Answers

# Add some content await cognee.add("Machine learning is a subset of artificial intelligence.") await cognee.add("Deep learning is a type of machine learning that uses neural networks.") await cognee.add("Neural networks are computing systems inspired by biological neural networks.") # Process the content await cognee.cognify() # Generate a comprehensive answer results = await cognee.search( query_text="Explain the relationship between machine learning, deep learning, and neural networks", query_type=SearchType.RAG )

If you’re not getting the expected search results:

  1. No results: Make sure you’ve added relevant content and run cognee.cognify()
  2. Irrelevant results: Try refining your query or using a different search type
  3. Missing connections: Your knowledge graph might not have captured the relationships you’re looking for; try adding more relevant content

Next Steps