add_data_points.
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 Data Models Do
- Define your own Pydantic models that inherit from
DataPoint - Insert structured data directly into the knowledge graph without
cognify - Create relationships between data points programmatically
- Control exactly what gets indexed and how
Code in Action
Step 1: Define Your Data Model
DataPoint. Use SkipValidation[Any] for fields that will hold other DataPoints to avoid forward reference issues. Metadata is recommended - it tells Cognee which fields to embed and store in the vector database for search.
Step 2: Create Data Instances
Step 3: Create Relationships
Edge to add weights, custom relationship types, or other metadata to your relationships.
Step 4: Insert into Graph
name field gets embedded and stored in the vector database for search.
Custom Data Model Fields
Whenadd_data_points walks your model, it decides field-by-field whether a value is a relationship or a plain property:
- Edges — a field whose value is another
DataPoint, alist[DataPoint], or an(Edge(...), DataPoint)/(Edge(...), list[DataPoint])tuple. Each referenced DataPoint becomes its own node, and the field name (or theEdge.relationship_type) becomes the edge label. - Properties — every other value type (
str,int,float,bool,dict, or a list of scalar values) is stored on the node. It is not expanded into separate nodes or edges.
metadata.index_fields are embedded for vector search — pick a text field (like name) for that, since a dict is stored but not meaningfully searchable. See DataPoints for more on indexing.
For complex nested values, such as a list of dictionaries, prefer serializing them yourself or modeling each nested object as its own DataPoint when you need portable graph behavior across database backends.
Edge Metadata Fields
Edge accepts the following fields, all optional:
Use
properties for custom edge metadata, such as properties={"since": 2015, "context": "college"}. Advanced users can also subclass Edge; subclass fields are included in the stored edge properties.
Custom Fields and Read-Back
Use plain scalar fields when you need to keep external identifiers, labels, statuses, or other simple properties on a node. Do not add those fields tometadata.index_fields unless you actually want Cognee to embed them as searchable text.
text is embedded for semantic search, while external_id and category are stored as normal node properties.
When you have the DataPoint object itself, read custom fields directly:
recall(), normalized graph entries reserve metadata for stable provenance keys such as data_id, chunk_id, chunk_index, and document_name. Custom payload fields from the result are available on raw:
Use in Custom Tasks and Pipelines
This approach is particularly useful when creating custom tasks and pipelines where you need to:- Insert structured data programmatically
- Define specific relationships between known entities
- Control exactly what gets indexed and how
- Integrate with external data sources or APIs
cognify to extract knowledge from unstructured text, then add your own structured data on top.
Linking DataPoints to a Dataset
When you calladd_data_points standalone, nodes are inserted globally with no dataset association. Dataset-level forget() calls will not remove them. To delete those unassociated DataPoints, call prune_system() instead of forget(dataset=...).
To associate DataPoints with a dataset so that forget(dataset=...) can clean them up, pass a PipelineContext as the ctx argument:
ctx carries all three values, each node and edge is tagged with dataset_id and data_id in the relational database. forget(dataset=...) then finds and removes exactly those records — nodes shared across other datasets are preserved.
When using Task(add_data_points) inside cognee.run_custom_pipeline(), the pipeline machinery builds and injects ctx automatically. If you write a custom task that calls add_data_points internally, declare ctx in your task signature so the pipeline forwards it:
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 and optional edge weights. 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