Database Plugin System - Implementation Summary
✅ What Has Been Completed
Section titled “✅ What Has Been Completed”A complete plugin-based architecture for database backends has been implemented, allowing Bamboo to support multiple database implementations and make it easy to add new ones.
🏗️ Architecture Overview
Section titled “🏗️ Architecture Overview”Core Components
Section titled “Core Components”flowchart TD
APP["Application Code (CLI, Agents)"]
WRAP["Client Wrappers<br/>• GraphDatabaseClient<br/>• VectorDatabaseClient"]
FAC["Factory & Registry (factory.py)<br/>• get_graph_backend()<br/>• get_vector_backend()<br/>• register_*_backend()<br/>• list_*_backends()"]
GDB["Graph DB Backend"]
VDB["Vector DB Backend"]
LIB["External Libraries<br/>• neo4j driver<br/>• qdrant-client"]
APP --> WRAP --> FAC
FAC --> GDB
FAC --> VDB
GDB --> LIB
VDB --> LIB
Files Created/Modified
Section titled “Files Created/Modified”New Files Created
Section titled “New Files Created”-
bamboo/database/base.py- Abstract base classes for backends
GraphDatabaseBackendinterfaceVectorDatabaseBackendinterface- 17 and 9 abstract methods respectively
-
bamboo/database/factory.py- Backend registry system
register_graph_backend()/register_vector_backend()get_graph_backend()/get_vector_backend()list_graph_backends()/list_vector_backends()- Auto-registration of built-in backends
-
bamboo/database/backends/neo4j_backend.py- Graph database implementation of
GraphDatabaseBackend - All graph database operations
- Migrated from original
graph_database_client.py
- Graph database implementation of
-
bamboo/database/backends/qdrant_backend.py- Vector database implementation of
VectorDatabaseBackend - All vector database operations
- Migrated from original
vector_database_client.py
- Vector database implementation of
-
bamboo/database/backends/__init__.py- Exports graph database and vector database backend classes
-
bamboo/database/backends/examples/in_memory_backend.py- Example in-memory implementation for testing/development
- Full reference implementation
- Useful for unit tests and development
-
bamboo/database/backends/examples/__init__.py- Exports example backends
-
DATABASE_PLUGINS.md- Comprehensive plugin documentation
- Architecture explanation
- Implementation guide
- Migration guide
-
DATABASE_PLUGINS_QUICK_REFERENCE.md- Quick start guide
- Common usage patterns
- Troubleshooting
Modified Files
Section titled “Modified Files”-
bamboo/config.py- Added
graph_database_backendconfig option - Added
vector_database_backendconfig option - Supports environment-based backend selection
- Added
-
bamboo/database/graph_database_client.py- Refactored to use factory pattern
- Delegates to backend implementations
- Maintains backward-compatible interface
-
bamboo/database/vector_database_client.py- Refactored to use factory pattern
- Delegates to backend implementations
- Maintains backward-compatible interface
-
bamboo/database/__init__.py- Exports client classes and factory functions
- Clean public API
🎯 Key Features
Section titled “🎯 Key Features”1. Plugin Architecture
Section titled “1. Plugin Architecture”- ✅ Abstract base classes define backend contracts
- ✅ Factory pattern for dynamic backend selection
- ✅ Registry system for easy backend registration
- ✅ No hardcoded dependencies
2. Configuration-Based Selection
Section titled “2. Configuration-Based Selection”GRAPH_DATABASE_BACKEND=neo4jVECTOR_DATABASE_BACKEND=qdrant3. Graceful Dependency Handling
Section titled “3. Graceful Dependency Handling”- ✅ Backends only require their dependencies
- ✅ Missing dependencies are handled gracefully
- ✅ Clear error messages if backend not available
- ✅ Supports testing without all dependencies
4. Easy Backend Development
Section titled “4. Easy Backend Development”from bamboo.database.base import GraphDatabaseBackend
class MyBackend(GraphDatabaseBackend): async def connect(self): ... async def create_node(self, node): ... # ... implement all required methods5. Auto-Registration
Section titled “5. Auto-Registration”- Built-in backends are registered automatically
- Custom backends can be registered programmatically
- Optional auto-registration in factory
📊 Current Supported Backends
Section titled “📊 Current Supported Backends”Graph Database
Section titled “Graph Database”- Neo4j (default) - Full property graph database support
- In-Memory (example) - For testing and development
Vector Database
Section titled “Vector Database”- Qdrant (default) - Vector similarity search
🚀 Usage
Section titled “🚀 Usage”Simple Usage (Default Backends)
Section titled “Simple Usage (Default Backends)”from bamboo.database import GraphDatabaseClient, VectorDatabaseClient
graph_db = GraphDatabaseClient()vector_db = VectorDatabaseClient()
await graph_db.connect()# Use normally...await graph_db.close()Check Available Backends
Section titled “Check Available Backends”from bamboo.database import list_graph_backends, list_vector_backends
print(list_graph_backends()) # ['neo4j', ...]print(list_vector_backends()) # ['qdrant', ...]Testing with In-Memory Backend
Section titled “Testing with In-Memory Backend”GRAPH_DATABASE_BACKEND=in_memory🔧 Adding New Backends
Section titled “🔧 Adding New Backends”Step 1: Implement
Section titled “Step 1: Implement”from bamboo.database.base import GraphDatabaseBackend
class MyBackend(GraphDatabaseBackend): # Implement all required methods passStep 2: Register
Section titled “Step 2: Register”from bamboo.database.factory import register_graph_backendregister_graph_backend("my_backend", MyBackend)Step 3: Configure
Section titled “Step 3: Configure”GRAPH_DATABASE_BACKEND=my_backend📋 Environment Variables
Section titled “📋 Environment Variables”# Backend SelectionGRAPH_DATABASE_BACKEND=neo4jVECTOR_DATABASE_BACKEND=qdrant
# Graph DatabaseNEO4J_URI=bolt://localhost:7687NEO4J_USERNAME=neo4jNEO4J_PASSWORD=passwordNEO4J_DATABASE=neo4j
# Vector DatabaseQDRANT_URL=http://localhost:6333QDRANT_API_KEY=QDRANT_COLLECTION_NAME=bamboo_knowledge
# EmbeddingsEMBEDDING_MODEL=text-embedding-3-smallEMBEDDING_DIMENSION=1536🧪 Testing
Section titled “🧪 Testing”With graph database backend (external)
Section titled “With graph database backend (external)”GRAPH_DATABASE_BACKEND=neo4j pytest tests/With In-Memory (no external DB needed)
Section titled “With In-Memory (no external DB needed)”GRAPH_DATABASE_BACKEND=in_memory pytest tests/📚 Interfaces
Section titled “📚 Interfaces”Every method below is abstract, so a backend that omits one cannot be
instantiated at all. The lists are checked against the code by
tests/test_docs.py — they were short for months, which is worse than useless:
a contributor implementing exactly what was listed got a TypeError.
GraphDatabaseBackend (17 methods)
Section titled “GraphDatabaseBackend (17 methods)”Lifecycle:
connect()- Open the database connection and create any required indexesclose()- Close the database connection and release resources
Writing:
create_node(node)- Unconditionally create a new node and return its assigned IDget_or_create_canonical_node(node, canonical_name)- Return the ID of an existing node with that name, or create itcreate_relationship(relationship)- Create a directed relationship between two nodesupdate_node_description(node_type, name, description)- Set the description field on an existing nodeincrement_cause_frequency(cause_id)- Increment thefrequencycounter on a cause nodeupdate_resolution_success_rate(resolution_id, success)- Update the running success-rate statisticset_procedure_auto_run(procedure_name, value)- Set/clear the durable per-procedure auto-run grant
Reading:
find_causes(symptoms, task_features, environment_factors, components, limit)- Candidate causes ranked by evidence breadthfind_procedures_for_causes(cause_names, include_tentative)- Procedures linked to those causes viainvestigated_byfind_all_procedures(limit, include_tentative)- Procedures cause-agnostically, by total reuse frequencyfind_common_pattern(graph_ids, min_occurrences)- Edges shared across at least that many of the given graphsget_node_description(node_type, name)- The description of an existing node, orNonesummary()- Per-type counts of nodes and relationships
Deleting:
clear_all()- Delete every node and relationship in the databaseremove_graph_id(graph_id)- Remove one graph’s contribution and clean up what it leaves isolated
The Code Map is not kept in a backend: it is read from
its dump (build-map --dump), so a backend implements nothing for it.
VectorDatabaseBackend (9 methods)
Section titled “VectorDatabaseBackend (9 methods)”connect()- Open the database connection and ensure the collection existsclose()- Close the database connectioncollection_exists()- Whether the backing collection/index exists and is readyupsert_section_vector(vector_id, embedding, content, section, metadata)- Insert or update a vector pointsearch_similar(query_embedding, limit, score_threshold, filter_conditions)- The most similar points above the thresholdget_document(doc_id)- Retrieve a single point by IDget_summaries_by_graph_ids(graph_ids)- FetchSummarysection entries for those graphsdelete_document(doc_id)- Delete the point with the given IDclear_all()- Drop and recreate the entire collection
✨ Benefits
Section titled “✨ Benefits”- Easy Testing - Use in-memory backend without external dependencies
- Multiple Backends - Switch between implementations without code changes
- Extensible - Add new backends easily
- Configuration-Driven - Backend selection via environment variables
- Backward Compatible - Existing code continues to work
- Clear Separation - Backend logic isolated from application code
- Type Safe - Abstract base classes with type hints
- Error Handling - Graceful handling of missing dependencies
🔄 Migration Path
Section titled “🔄 Migration Path”Before
Section titled “Before”# Direct dependency on graph database driverfrom neo4j import AsyncGraphDatabasedriver = AsyncGraphDatabase.driver(...)# Abstracted backendfrom bamboo.database import GraphDatabaseClientgraph_db = GraphDatabaseClient()📖 Documentation
Section titled “📖 Documentation”DATABASE_PLUGINS.md- Comprehensive technical documentationDATABASE_PLUGINS_QUICK_REFERENCE.md- Quick start and common patterns
🎓 Example: Adding PostgreSQL with pgvector
Section titled “🎓 Example: Adding PostgreSQL with pgvector”from bamboo.database.base import VectorDatabaseBackend
class PostgresVectorBackend(VectorDatabaseBackend): async def connect(self): # Connect to PostgreSQL with pgvector pass
# ... implement all required methods
# Register in factory.pyregister_vector_backend("postgres", PostgresVectorBackend)Then configure:
VECTOR_DATABASE_BACKEND=postgres⚙️ How It Works
Section titled “⚙️ How It Works”- Configuration Load:
SettingsreadsGRAPH_DATABASE_BACKENDfrom.env - Client Creation:
GraphDatabaseClient()instantiated - Factory Call: Client calls
get_graph_backend() - Backend Lookup: Factory looks up backend by name
- Instantiation: Backend class instantiated and returned
- Delegation: Client methods delegate to backend methods
🔍 Verification
Section titled “🔍 Verification”All files compile successfully:
✓ bamboo/database/base.py✓ bamboo/database/factory.py✓ bamboo/database/graph_database_client.py✓ bamboo/database/vector_database_client.py✓ bamboo/database/backends/neo4j_backend.py✓ bamboo/database/backends/qdrant_backend.py✓ bamboo/database/backends/examples/in_memory_backend.py✓ bamboo/config.pyPlugin system initializes successfully:
✓ Plugin system initialized successfully!🚦 Next Steps
Section titled “🚦 Next Steps”- Install Dependencies:
pip install . - Start Using: The plugin system is ready to use
- Add Custom Backends: Follow the guide in
DATABASE_PLUGINS.md - Test: Use in-memory backend for testing
- Deploy: Configure backend via environment variables
📞 Support
Section titled “📞 Support”See DATABASE_PLUGINS_QUICK_REFERENCE.md for:
- Common issues and solutions
- Usage examples
- Debugging tips
- Troubleshooting guide