You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Added a new service to read user corrections from Notion databases and apply them to the knowledge graph.
- Introduced endpoints for initiating correction imports and checking their status, with detailed request and response models.
- Implemented a multi-step pipeline for the correction process, including database discovery, row scanning, and applying corrections.
- Enhanced observability with OpenTelemetry spans for each pipeline step.
- Updated README.md to document the new Notion Correction Import feature and its usage.
- Created an in-memory job store to track correction import progress.
@@ -70,10 +71,17 @@ The system is built on [Graphiti](https://github.com/getzep/graphiti), a tempora
70
71
-**Dynamic Schema Design**: Gemini analyzes the graph and designs 3-10 category databases with optimal column schemas
71
72
-**MCP Agent Integration**: Uses the Notion MCP server via `create_react_agent` for flexible row creation and page building
72
73
-**Async with Polling**: Fire-and-forget pattern (202 + status polling) with step-level progress tracking
73
-
-**Feedback Loop Columns**: Every database includes "Needs Review" (checkbox) and "Correction Notes" (rich_text) for future graph corrections
74
+
-**Clean Page on Export**: Automatically removes all existing content under the parent page before each export
75
+
-**Feedback Loop Columns**: Every database includes "Needs Review" (checkbox) and "Correction Notes" (rich_text) for corrections
74
76
-**Per-Request Auth**: Notion token is passed per-request (not server-side) for multi-tenant use
75
77
76
-
### 7. 🔐 Security & Rate Limiting
78
+
### 7. 🔄 Notion Correction Import
79
+
-**Feedback Loop**: Reads user corrections from exported Notion databases and applies them back to the knowledge graph
80
+
-**Smart Row Updates**: MCP agent intelligently updates affected columns or deletes rows that are no longer relevant
81
+
-**Graphiti Integration**: Uses `add_episode()` with `custom_extraction_instructions` to ensure corrections are language-consistent and properly contradict outdated edges
82
+
-**Partial Failure Handling**: Individual correction failures don't block the pipeline; detailed failure reports included in the result
83
+
84
+
### 8. 🔐 Security & Rate Limiting
77
85
-**API Key Authentication**: All endpoints (except `/health`) require `X-API-SECRET` header
| 2b | Extract Entries | Gemini structured output (`ExtractionResult`) | Extract rows for each category (one LLM call per category) |
@@ -360,6 +369,24 @@ Instead of direct CRUD operations (which break embeddings), corrections are proc
360
369
361
370
**Job Store** (`app/services/notion_export_job_store.py`): Tracks `current_step`, `categories_count`, `entries_count`, `database_ids`, and `summary_page_url`. Same in-memory pattern as the ingest job store.
**Purpose**: Read user corrections from Notion and apply them back to the knowledge graph
374
+
375
+
**Pipeline** (3 steps, each with its own OTel span):
376
+
377
+
| Step | Name | Method | Description |
378
+
|------|------|--------|-------------|
379
+
| 0 | Discover Databases | Notion SDK (`blocks.children.list`) | Find all child databases under the parent page |
380
+
| 1 | Scan Flagged Rows | Notion SDK (`databases/{id}/query`) | Query each database for rows with "Needs Review" checked |
381
+
| 2a | Correct Graph |`graphiti.add_episode()`| Apply correction with `custom_extraction_instructions` for language + contradiction handling |
382
+
| 2b | Update Notion Row | MCP agent (`create_react_agent`) | Intelligently update affected columns or delete the row if no longer relevant |
383
+
384
+
**Correction Strategy**: Each correction is processed as a new Graphiti episode. The `custom_extraction_instructions` steer the LLM to extract only corrected facts (not the old state), and to write everything in the user's preferred language. Graphiti's built-in contradiction detection automatically invalidates outdated edges.
385
+
386
+
**MCP Agent Decision**: The agent receives the full context (current properties, column schema, updated node summaries, new facts, invalidated facts) and chooses to either update the row or archive it.
The Notion Correction Import feature closes the feedback loop: users flag incorrect data in the exported Notion databases, and the system reads those corrections, applies them to the knowledge graph, and intelligently updates or deletes the Notion rows.
939
+
940
+
Each exported database includes two feedback columns:
941
+
-**Needs Review** (checkbox): Flag a row that needs correction
942
+
-**Correction Notes** (rich_text): Describe what needs to be fixed
943
+
944
+
### How It Works
945
+
946
+
```
947
+
1. CLIENT
948
+
└─▶ POST /v1/notion/corrections
949
+
{userId, notionToken, pageName, language}
950
+
951
+
2. ROUTE HANDLER (synchronous validation)
952
+
├─▶ Validate notionToken by resolving pageName → pageId
953
+
├─▶ Create job in memory store (status: "processing")
954
+
├─▶ Launch background task (asyncio.create_task)
955
+
└─▶ Return 202 {jobId, pageId}
956
+
957
+
3. BACKGROUND PIPELINE (NotionCorrectionService)
958
+
│
959
+
├─▶ Step 0: DISCOVER DATABASES
960
+
│ └─▶ List child_database blocks under the parent page
961
+
│ → Map of category name → database ID
962
+
│
963
+
├─▶ Step 1: SCAN FOR FLAGGED ROWS
964
+
│ └─▶ Query each database filtering "Needs Review" == true
965
+
│ └─▶ Extract property values, types, and correction notes
The agent receives the full context of each correction and makes an intelligent decision:
1017
+
1018
+
-**Update**: If the correction modifies specific facts (e.g., "the dosage changed to 20mg"), the agent patches the relevant columns while keeping unaffected properties intact
1019
+
-**Delete**: If the correction invalidates the entity entirely (e.g., "this concept is no longer relevant"), the agent archives the row
1020
+
1021
+
The `language` parameter ensures all updated property values are written in the user's preferred language.
1022
+
1023
+
### Axiom Observability
1024
+
1025
+
The correction pipeline emits spans under the `correction.*` attribute namespace:
0 commit comments