Ubiquity Database
A comprehensive database abstraction layer for the Ubiquity consciousness-aware system, supporting both SQLite for local development and DataStax Astra DB for cloud/enterprise deployments.
Features
Core Capabilities
- Dual Backend Support: Seamlessly switch between SQLite (local) and Astra DB (cloud)
- Vector Embeddings: Store and search consciousness embeddings using vector similarity
- Hybrid Search: Combine vector search with lexical search for optimal results
- 7-Wide Memory Pools: Parallel memory pools for high-performance data processing
- Pub/Sub Messaging: Integration with Astra Streaming for real-time communication
Astra DB Features
- $vectorize: Automatic embedding generation at the database level
- $hybrid Search: Combined vector and lexical search with reranking
- Astra Streaming: Apache Pulsar-based pub/sub for worker coordination
- Auto-scaling: Leverage Astra's serverless architecture
SQLite Features
- Zero Configuration: Works out of the box for local development
- WAL Mode: Write-Ahead Logging for better concurrency
- File-based Pools: Memory pools stored as separate SQLite databases
- Portable: Easy to backup and migrate
Configuration
Environment Variables
For Astra DB:
# For embeddings
For Astra Streaming:
Configuration File
use ;
let config = DatabaseConfig ;
Usage Examples
Basic Database Operations
use ;
use ConsciousnessState;
// Create database
let db = create_database.await?;
// Initialize schema
db.initialize.await?;
// Store consciousness state
let state = ConsciousnessState ;
db.store_consciousness_state.await?;
// Query history
let history = db.get_consciousness_history.await?;
Vector Search
// Vector similarity search
let embedding = vec!; // Your embedding vector
let results = db.vector_search.await?;
for result in results
Hybrid Search
use HybridSearchQuery;
// Combine vector and text search with reranking
let query = HybridSearchQuery ;
let results = db.hybrid_search.await?;
Memory Pools
use create_memory_pools;
// Create 7-wide memory pools
let pools = create_memory_pools.await?;
// Store data with automatic pool selection
let pool = pools.get_pool_for_key.await?;
pool.store.await?;
// Retrieve data
if let Some = pool.retrieve.await?
// Get pool statistics
let stats = pools.all_stats.await?;
for in stats.iter.enumerate
Architecture
7-Wide Memory Pools
The system implements 7 parallel memory pools for optimal data distribution:
- Pool Distribution: Keys are consistently hashed to one of 7 pools
- Isolation: Each pool operates independently for parallelism
- Eviction: LRU eviction when pools reach capacity
- Statistics: Track hits, misses, and evictions per pool
Consciousness Embeddings
- Text Generation: Consciousness states are converted to text representations
- Embedding Generation: Text is embedded using OpenAI or Astra $vectorize
- Storage: Embeddings stored alongside metadata
- Search: Vector similarity search with cosine distance
Hybrid Search Flow
- Vector Search: Find semantically similar documents
- Lexical Search: Find keyword matches using BM25
- Reranking: NVIDIA NeMo model reranks combined results
- Scoring: Return final scores with highlights
Performance Considerations
SQLite
- Use WAL mode for better concurrency
- Keep database file on SSD for performance
- Regular VACUUM for optimization
- Index frequently queried fields
Astra DB
- Leverage $vectorize for server-side embeddings
- Use appropriate consistency levels
- Batch operations when possible
- Monitor rate limits and quotas
Testing
Run the examples:
# SQLite example
# Astra DB example
ASTRA_DB_ENDPOINT=xxx ASTRA_DB_TOKEN=xxx
Run tests:
Migration Guide
From SQLite to Astra DB
-
Export data from SQLite:
let history = sqlite_db.get_consciousness_history.await?; -
Import to Astra DB:
for state in history -
Update configuration to use Astra backend
Schema Evolution
Both backends support schema evolution:
- SQLite: Use migrations with
sqlx migrate - Astra: Collections are schemaless, add fields as needed
Troubleshooting
Common Issues
-
Vector Dimension Mismatch
- Ensure embedding dimension matches configuration
- Check model output dimensions
-
Astra Connection Failed
- Verify endpoint URL format
- Check token permissions
- Ensure keyspace exists
-
Memory Pool Full
- Increase
max_pool_size_mb - Enable compression
- Adjust eviction policy
- Increase
Debug Logging
Enable debug logging:
set_var;
init;
License
MIT License - see LICENSE file for details