Add KG Library Layer 4: Graph Backend Abstraction #20
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.
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