While you can call Cogwit API endpoints directly, the SDK is recommended for its error handling, type safety, and overall developer experience.
Install and configure
Complete example
Let’s jump straight in with a full code example of Cogwit in action. We’ll then go over the code piece by piece and explain all the relevant parts in detail.What just happened
Client setup
async def main()
and run it with asyncio.run(main())
.
Adding data
add
operation uploads text to Cogwit and schedules preprocessing. All data is organized by dataset for proper isolation. It returns an AddResponse
with:
status
- Whether the operation completed successfullydataset_id
- Unique identifier for your dataset (save this!)dataset_name
- The name you provided
Cognifying data
cognify
operation transforms your data into a knowledge graph. It returns a CognifyResponse
that maps dataset IDs to their processing status. Wait for PipelineRunCompleted
before searching.
Searching your data
search
operation queries your knowledge graph. By default it uses GRAPH_COMPLETION
, but you can use any of the Cognee search types. See also Search Basics for detailed parameter explanations.