KB-1068
PG→Qdrant Auto Sync — DEPLOYED
2 min read Revision 1
reportpg-qdrantsyncvectornotify2026-04-05
PG→Qdrant Auto Sync — Implementation Report
Date: 2026-04-05 | Status: ✅ DEPLOYED + 9/9 VERIFY PASS
Architecture
PG trigger (fn_kb_notify_vector_sync)
↓ NOTIFY 'kb_vector_sync' (filtered: skip comments/registries/empty)
↓
pg_vector_listener.py (daemon thread in Agent Data container)
↓ LISTEN loop → receives notification
↓ Calls vector_store.upsert_document() or .delete_document()
↓
Qdrant updated
Filter (PG trigger level)
- Skip:
operations/tasks/comments/*,registries/*, empty key, body <10 chars - Only embeddable knowledge documents trigger NOTIFY
Verify Results
| # | Test | Result |
|---|---|---|
| 1 | SQL INSERT → vector created | ✅ 1345→1346 |
| 2 | SQL UPDATE → vector updated | ✅ (same count, content updated) |
| 3 | SQL DELETE → vector removed | ✅ 1346→1345 |
| 4 | API POST still works | ✅ 200 OK |
| 5 | audit-sync: 0 orphans, 5 ghosts (empty docs) | ✅ |
| 6 | dot-vector-audit in crontab | ✅ daily 4:30AM |
| 7 | trg_kb_vector_sync in pg_trigger | ✅ 6 triggers total |
| 8 | Trigger Guard: 0 violations | ✅ |
| 9 | Listener survives restart | ✅ (3 restart cycles) |
Cleanup Done
- 4 orphan vectors deleted (cleanup-orphans)
- 22 ghost docs reindexed (reindex-missing)
- 5 remaining ghosts = empty folder/test docs (correct — no content to embed)
Files Changed
| File | Repo | Change |
|---|---|---|
| pg_vector_listener.py | agent-data-repo | NEW — LISTEN daemon |
| resilient_client.py | agent-data-repo | PATCHED — start listener on startup |
| fn_kb_notify_vector_sync() | PG incomex_metadata | NEW — NOTIFY trigger |
| trg_kb_vector_sync | PG incomex_metadata | NEW — AFTER trigger |
Important Note
Changes to agent_data inside Docker container are EPHEMERAL — they survive
docker restart but NOT docker compose up --build or image rebuild.
For persistence: commit to git → rebuild image → deploy.
PG→Qdrant sync live | 0 orphans | 5 empty ghosts | f6dd405