A focused walkthrough for converting an existing relational database (SQLite or Postgres) into a knowledge graph that can be queried with natural language. Before you start:Documentation Index
Fetch the complete documentation index at: https://docs.cognee.ai/llms.txt
Use this file to discover all available pages before exploring further.
- Complete Quickstart to understand basic operations
- Ensure you have LLM Providers configured
- Have connection details for the database you want to migrate
What This Does
Cognee reads your relational database schema (tables, columns, primary keys, foreign keys) and can map it into graph nodes and edges:- In full migration mode, each table becomes a
TableTypenode - Each row becomes a
TableRownode linked to its table - Non-key column values can become
ColumnValuenodes linked from each row - Foreign key relationships become edges between row nodes
- Migrated nodes and edges are embedded and indexed for semantic search
cognee.recall() with natural language.
1. Configure the Migration Database
Set the source database connection in your.env file:
- SQLite
- Postgres
2. Run the Migration
The migration pipeline itself uses lower-level APIs because it is importing an external relational schema directly into the graph. Once the graph is built, prefer
cognee.recall() as the default query interface in v1.0. Set top_k higher (100-200) for broad exploratory queries over large databases, and lower (20-50) for specific lookups to keep LLM context manageable. The example above also isolates Cognee’s local state in a temp directory so repeated runs do not pick up stale metadata from earlier experiments.Additional information
Migration Modes
Migration Modes
migrate_relational_database has two modes controlled by the schema_only flag:| Mode | Flag | What is migrated |
|---|---|---|
| Full (default) | schema_only=False | TableType, TableRow, optional ColumnValue, and foreign-key edges |
| Schema only | schema_only=True | DatabaseSchema, SchemaTable, and SchemaRelationship datapoints for structural understanding |
TableRow nodes for every record. Instead, it ingests schema-level datapoints and attaches up to a few sample rows as metadata on each SchemaTable node. Use it when you want to explore table structure and relationships without migrating the full dataset:- “What tables exist in this database?”
- “Which tables are connected by foreign keys?”
- “What kind of data does the
invoicestable contain?”
Visualize the Result
Visualize the Result
Relational Databases
Configure SQLite and Postgres connections
Recall and Search
Learn the current recall flow and lower-level search options
Graph Visualization
Explore your knowledge graph visually