Basic Usage
This minimal example shows how to add content, process it, and perform a search:What just happened
The code demonstrates Cognee’s three core operations:.add
— Adds data to Cognee so they can be cognified. In this case, we added a single string (“Cognee turns documents into AI memory”); from Cognee’s perspective, this string is a document..cognify
— This is where the cognification happens. All documents are chunked, entities are extracted, relationships are made, and summaries are generated. In this case, we can expect entities like Frodo, One Ring, and Mordor..search
— Queries the knowledge graph using vector similarity and graph traversal to find relevant information and return contextual results.
About async
/ await
in Cognee
Cognee uses asynchronous code extensively. That means many of its functions are defined with
async
and must be called with await
. This lets Python handle waiting (e.g. for I/O or network calls) without blocking the rest of your program.Async basics
Async basics
This example uses
async
/ await
, Python’s way of doing asynchronous programming.
Asynchronous programming is used when functions may block because they are waiting for something (for example, a reply from an API call). By writing async def
, you define a function that can pause at certain points.
The await
keyword marks those calls that may need to pause.
To run such functions, Python provides the asyncio
library. It uses a loop, called the event loop, which executes your code in order but, whenever a function is waiting, can temporarily run another one. From inside your function, though, everything still runs top-to-bottom: each line after an await
only executes once the awaited call has finished.Next Steps
Cognee core concepts
Learn about Cognee’s core concepts, architecture, building blocks, and main operations.