Add KG Library Layer 4: Graph Backend Abstraction#2
Open
Conversation
Implements Layer 4 of the Knowledge Graph Query Library with Neo4j support: Core Components: - GraphNode, GraphEdge, GraphPath dataclasses (base.py) - GraphBackend abstract interface (graph_dbs/base.py) - Neo4jBackend full implementation (graph_dbs/neo4j.py) - MockGraphBackend for testing (graph_dbs/mock.py) Features: ✓ Execute Cypher queries with parameters ✓ Parse Neo4j results into graph structures ✓ Retrieve graph schema (node/edge types, properties) ✓ Validate Cypher syntax ✓ Automatic result deduplication ✓ Async/await throughout ✓ Proper connection management Testing: - 30 comprehensive tests (18 passing, 12 skip without Neo4j) - Unit tests for data structures - Mock backend tests - Neo4j integration tests Documentation: - Complete README with examples - Design document included - Implementation summary for reviewers No new dependencies (neo4j>=6.0.3 already in project). Follows Mellea conventions and Backend pattern.
|
The PR description has been updated. Please fill out the template for your PR to be reviewed. |
added 3 commits
January 25, 2026 10:04
- Replace list slice with next(iter()) for RUF015 - Add docstrings to all __init__.py files for D104 - Add type ignore comments for neo4j imports (no type stubs) - Add assertions for Neo4j relationship nodes (mypy union-attr) - Run ruff formatter on all files All tests still pass (18 passing, 12 skipped).
- Convert text-based architecture overview to Mermaid flowchart - Add color coding for each layer - Improve visual clarity and readability - Maintains same 4-layer structure
…the PR description
17d640e to
ef05884
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Misc PR
Type of PR
Description
This PR implements Layer 4 of the Knowledge Graph Query Library for Mellea: Graph Backend Abstraction. This layer provides the foundation for executing graph queries across different database systems, starting with Neo4j support.
What's Included
1. Core Data Structures (
base.py)Pure dataclasses for representing graph data:
Key features:
2. Abstract Backend Interface (
graph_dbs/base.py)GraphBackendABC following Mellea's Backend pattern:Design principles:
Backend(model_id, model_options)pattern3. Neo4j Backend Implementation (
graph_dbs/neo4j.py)Full Neo4j integration:
Features:
Key implementation details:
4. Mock Backend for Testing (
graph_dbs/mock.py)Testing utility:
Features:
Use cases:
5. Minimal Component Stubs
Temporary implementations for testing Layer 4:
components/query.py: Minimal GraphQuery classcomponents/result.py: Minimal GraphResult classcomponents/traversal.py: Minimal GraphTraversal classNote: These will be replaced with full Component implementations in Layer 2.
Testing
Test Structure
Test Coverage
Total: 30 tests
Test Categories
Base Data Structures (9 tests)
Mock Backend (7 tests)
Neo4j Backend (14 tests)
Running Tests
Module Structure
Following the design document requirements:
Design Decisions
1. Data Structures vs Components
GraphNode,GraphEdge,GraphPathare dataclasses, not Componentsformat_for_llm()) come in Layer 22. Backend Pattern
Backendabstraction for LLMsbackend_idandbackend_optionssimilar tomodel_idandmodel_options3. Neo4j Element IDs
element_idinstead of deprecatedidproperty4. Result Deduplication
5. Async-First
API Examples
Basic Usage
Validation
Schema
Documentation
Next Steps
After this PR is merged:
Layer 2 PR: Implement full Graph Query Components
format_for_llm()implementationsLayer 3 PR: Add LLM-Guided Query Construction
@generativefunctionsLayer 1 PR: Application Examples
Commits
This PR contains the following components:
Testing