feat(memory): pluggable storage backends#998
Open
erma07 wants to merge 1 commit intoRightNow-AI:mainfrom
Open
Conversation
…t support Redesign the openfang-memory crate for pluggable storage backends. The main backend (sqlite or postgres) and semantic backend (sqlite, postgres, qdrant, http) are independently configurable. Architecture: - substrate.rs is 100% backend-agnostic (zero rusqlite imports) - 9 backend traits: Structured, Semantic, Knowledge, Session, Usage, PairedDevices, TaskQueue, Consolidation, Audit - SessionBackend has 5 default trait impls (create_session, canonical_context, append_canonical, store_llm_summary, etc.) - Shared helpers.rs for serialization/parsing across backends - JSONL session mirror extracted to standalone filesystem utility Backends: - sqlite/ — 11 files, full implementation with sqlite-vec vectors - postgres/ — 11 files, full implementation with pgvector - qdrant/ — semantic-only, gRPC vector similarity search - http/ — semantic-only, remote memory-api gateway with fallback External callers migrated: - kernel uses memory.usage_arc() and memory.audit() (was usage_conn()) - api routes use memory.usage() trait method - runtime AuditLog uses AuditBackend trait (was raw rusqlite Connection) - MeteringEngine accepts Arc<dyn UsageBackend> (was Arc<UsageStore>) Config: [memory] backend = "sqlite" # or "postgres" semantic_backend = "qdrant" # independently: sqlite/postgres/qdrant/http Docker: pgvector/pg18 + qdrant services for integration testing. 65 tests (40 unit + 25 integration) across all backends.
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.
Summary
Redesign the
openfang-memorycrate with pluggable storage backends. The main storage backend (SQLite or PostgreSQL) and the semantic/vector backend (SQLite, PostgreSQL, Qdrant, HTTP) are now independently configurable, allowing mix-and-match deployments like PostgreSQL for structured data with Qdrant for vector search.Architecture
The orchestration layer (
substrate.rs) is now 100% backend-agnostic — zero database-specific imports. All storage is abstracted through 9 backend traits with implementations per database:Each backend lives in its own folder (
sqlite/,postgres/,qdrant/,http/) with identical file structure (11 files each for SQLite and PostgreSQL). Shared serialization and parsing logic is extracted intohelpers.rsto eliminate cross-backend duplication.SessionBackenduses Rust default trait implementations for 5 methods (create_session,create_session_with_label,append_canonical,canonical_context,store_llm_summary) — new backends only need to implement the storage primitives.Changes
PairedDevicesBackend,TaskQueueBackend,ConsolidationBackend,AuditBackend(added to existingStructuredBackend,SemanticBackend,KnowledgeBackend,SessionBackend,UsageBackend)sqlite/, all database-specific code isolated in its backend folderArc<dyn UsageBackend>,AuditBackend) — no more leakedrusqlite::Connectiontypessemantic_backendallows independent vector backend selectionpgvector/pgvector:pg18andqdrant/qdrant:latestservices for integration testingTesting
cargo clippy --workspace --all-targets -- -D warnings passes
cargo test --workspace passes (65 tests: 40 unit + 25 integration)
Integration tested against live PostgreSQL (pgvector/pg18) and Qdrant
All SQLite, PostgreSQL, and Qdrant backends verified with identical test suite
Security
No new unsafe code (existing sqlite-vec FFI registration unchanged)
No secrets or API keys in diff
User input validated at boundaries
usage_conn() removed — no more raw database connection leaks to external crates
Configuration