Skip to content

Postgres graph database [ Daniel Scott - Draft ]#2504

Closed
dexters1 wants to merge 9 commits intodevfrom
postgres-graph-database
Closed

Postgres graph database [ Daniel Scott - Draft ]#2504
dexters1 wants to merge 9 commits intodevfrom
postgres-graph-database

Conversation

@dexters1
Copy link
Copy Markdown
Collaborator

Description

Acceptance Criteria

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Code refactoring
  • Other (please specify):

Screenshots

Pre-submission Checklist

  • I have tested my changes thoroughly before submitting this PR (See CONTRIBUTING.md)
  • This PR contains minimal changes necessary to address the issue/feature
  • My code follows the project's coding standards and style guidelines
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if applicable)
  • All new and existing tests pass
  • I have searched existing PRs to ensure this change hasn't been submitted already
  • I have linked any relevant issues in the description
  • My commits have clear and descriptive messages

DCO Affirmation

I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin.

DanielNScott and others added 9 commits March 24, 2026 12:31
Problems:
- Need to migrate basic graph functionality to relational DB

Solutions:
- New adapter implementing GraphDBInterface
- Selection branch included in get_graph_engine.py

Decisions:
- re-use SQLAlchemy setup and configuration
- Remove .query() (raw Cypher) functionality
Problems:
- Cypher search retriever exposes raw cypher interface via .query()
- Natural language retriever writes, uses Cypher via .query()
- Temporal awareness (Graphiti) subsystem directly uses cypher, neo4j

Solutions:
- Raise incompatibility errors proactively across these consumers

Decisions:
- None of these are core functionality, cost should be low
- Graphiti already unguarded hard-coding of multiple configs...
- Complex cypher search cannot be replaced in postgres at present
Problems:
- asyncpg misparses ::jsonb cast as named parameter
- prune_system drops graph tables via delete_database()
- cached adapter instance has no tables after prune
- no CI coverage for postgres graph backend
- no unit or e2e tests for postgres adapter

Solutions:
- replace ::jsonb with CAST(:param AS jsonb) throughout
- add _ensure_initialized() calling idempotent CREATE IF NOT EXISTS
- guard is_empty and delete_graph with _ensure_initialized
- add run-postgres-tests job to graph_db_tests.yml CI workflow
- add 26 unit tests against real Postgres
- add shared e2e test and postgres wrapper

Decisions:
- _ensure_initialized over defensive checks on every method
- real Postgres in tests, not SQLite (dialect differences block it)
- shared test function for future backend reuse (test_graphdb_shared)
- CI uses Postgres 16 service container, matching Kuzu/Neo4j pattern
Problems:
- some white-space and wrapping non-compliance

Solutions:
- fix via ruff
Problems:
- want joint graph and vector interaction in SQL to extent possible
- currently, graph and vector writes are separate transactions
- search requires two round-trips, vector search then graph search

Solutions:
- add PostgresHybridAdapter composing PostgresAdapter and PGVectorAdapter
- implement combined write methods with single-transaction atomicity
   - implement batching to avoid loops on session.execute calls later
- implement combined search by joining graph and vector tables
- exceptions in get_graph_engine and create_vector_engine if given pghybrid
- add pghybrid construction in get_unified_engine

Decisions:
- composition rather than inheritance on subclasses of SQLAlchemyAdapter
   - otherwise subtle configuration bugs can occur (diamond problem)
- hybrid only allowed via get_unified_engine, not individual factories
- per-row inserts for now, batch optimization deferred
- table name validation via regex to prevent SQL injection
Problems:
- pghybrid delegates query() to PostgresAdapter which raises generic error
- isinstance checks only catch PostgresAdapter, not PostgresHybridAdapter
- users would see NotImplementedError instead of descriptive message

Solutions:
- add PostgresHybridAdapter to isinstance checks in three files
- cypher search, natural language, and graphiti now guard both adapters
Problems:
- no test coverage for hybrid adapter

Solutions:
- add unit tests covering graph, vector, combined, and content paths
- content integrity test verifies IDs and payloads across both tables
- tests use local SQLAlchemyAdapter to avoid stale event loop issues
- fixture teardown cleans up vector collection tables between tests

Decisions:
- use uuid5 for test IDs because pgvector tables require UUID columns
- bypass PGVectorAdapter constructor to share connection pool with graph
- e2e and CI deferred because cognify pipeline calls get_graph_engine directly
@pull-checklist
Copy link
Copy Markdown

Please make sure all the checkboxes are checked:

  • I have tested these changes locally.
  • I have reviewed the code changes.
  • I have added end-to-end and unit tests (if applicable).
  • I have updated the documentation and README.md file (if necessary).
  • I have removed unnecessary code and debug statements.
  • PR title is clear and follows the convention.
  • I have tagged reviewers or team members for feedback.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 26, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bf4d9cca-a72b-47a6-9d22-61723dbff19b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch postgres-graph-database

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

Hello @dexters1, thank you for submitting a PR! We will respond as soon as possible.

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 26, 2026

⚠️ The sha of the head commit of this PR conflicts with #2502. Mergify cannot evaluate rules on this PR. Once #2502 is merged or closed, Mergify will resume processing this PR. ⚠️

@dexters1 dexters1 closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants