Commit a3ee623
feat(kg): KnowledgeGraphAGE skeleton + graph bootstrap
First commit of the AGE-backed knowledge graph layer. Skeleton class
in `mempalace/knowledge_graph_age.py` that opens a Postgres connection,
loads the AGE extension, sets `search_path = ag_catalog, "$user", public`
for the session, and creates a graph named `mempalace_kg` in
`ag_catalog.ag_graph` if one doesn't already exist. Idempotent
bootstrap; safe to instantiate repeatedly.
Three `pytest.skipif`-gated integration tests in
`tests/test_knowledge_graph_age.py`:
- `test_age_kg_instantiates` — class constructs cleanly, closes
without exception.
- `test_age_graph_created` — `mempalace_kg` is registered in
`ag_catalog.ag_graph` with a non-null `graphid` after init.
- `test_age_context_manager` — `with KnowledgeGraphAGE(...) as kg:`
pattern closes the connection on exit (verifies `_conn.closed`
is True after).
Verified end-to-end against the live mempalace-db container on
disks.jphe.in:5433 (PG16 + pgvector 0.8.2 + AGE 1.6.0): all 3 AGE
tests pass; full suite 1854 passed / 1 skipped / 106 deselected with
TEST_POSTGRES_DSN set — zero regressions vs the 1851 pre-AGE baseline
(+3 AGE tests).
Adapted plan code from psycopg3 to psycopg2 for consistency with
MemPalace#665's dependency choice (psycopg2-binary is what `pip install -e
".[postgres]"` brings in; introducing psycopg3 alongside would
duplicate the driver surface for no real gain at this stage).
Future commits in this layer: triple add/query operations, temporal
filtering (`as_of` queries), and a `MempalaceConfig.kg_backend`
routing flag selecting AGE over the SQLite default.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 6552dd9 commit a3ee623
2 files changed
Lines changed: 136 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
0 commit comments