remember().
Before you start:
- Complete Quickstart to understand basic operations
- Ensure you have LLM Providers configured
- Have some structured data you want to model
What Custom Graph Models Do
- Define a schema (Pydantic models inheriting from
DataPoint) that constrains how Cognee extracts entities and relationships from text - Guide
remember()to produce graph nodes and edges that match the defined domain model - Improve consistency of labels, properties, and relationship structure across ingested documents
- Control search quality by choosing which fields are indexed via metadata
Code in Action
Step 1: Define Your Entity Type
DataPoint to represent the node types in your custom graph.
Step 2: Define Your Entity Classes
remember() should extract. Metadata is recommended because it tells Cognee which fields to embed and index for retrieval.
How graph_model constrains LLM extraction
How graph_model constrains LLM extraction
When you pass
graph_model=..., that model is the structured-output schema the LLM must fill in. Internally, Cognee hands your model to the LLM as the response_model for structured extraction, so the LLM can only return entities and relationships that fit the fields you declared — it is not free to invent an arbitrary shape.- Default: without
graph_model, Cognee uses its general-purposeKnowledgeGraphschema (free-form nodes and edges). - Custom model: when you pass a
DataPointsubclass, only the fields you declare on each subclass become part of the extraction schema. InheritedDataPointinfrastructure fields (likeid) are stripped out, so they do not expand the LLM’s response schema. Adding a field (e.g.release_year: int) tells the LLM to extract that value; nestedDataPointfields (likeused_in: List[Field]) tell it to extract those related entities and the edges between them. custom_promptvsgraph_model: they play different roles.graph_modeldefines the shape (which fields and relationships are allowed), whilecustom_promptreplaces the system prompt that tells the LLM what to look for. Use them together for predictable, domain-specific extraction.
Step 3: Remember Your Data with the Custom Model
graph_model acts as the extraction schema, and CUSTOM_PROMPT tells the LLM what relationships to look for.
Step 4: Visualize Your Data
Use in Custom Tasks and Pipelines
This pattern is useful when you need predictable, domain-specific extraction inside custom workflows.- Reuse the same graph schema across tasks to keep outputs consistent
- Run
remember(graph_model=...)in workflows where downstream logic expects a specific graph shape - Combine with custom prompts or custom tasks to refine extraction
- Validate pipeline results with
visualize_graphbefore promoting changes to production
Additional examples
Additional examples about custom data models are available on our github.Full Example
Latest guide
Latest guide
Legacy guide
Legacy guide
This example shows the complete workflow with metadata for indexing. In practice, you can create complex nested models with multiple relationships and sophisticated data structures.
Low-Level LLM
Learn about direct LLM interaction
Core Concepts
Understand knowledge graph fundamentals
API Reference
Explore API endpoints