Skip to main content

clawdesk-sochdb

SochDB adapter that provides concrete implementations of all clawdesk-storage traits. SochDB is the embedded database engine used by ClawDesk for persistent session, conversation, configuration, and vector storage.

Dependencies

Internal: clawdesk-types, clawdesk-storage

External: sochdb-core, sochdb-vector, serde, tokio, tracing

Modules

ModuleDescription
session_storeSochSessionStore — session persistence
conversation_storeSochConversationStore — message history
config_storeSochConfigStore — runtime configuration
vector_storeSochVectorStore — vector embeddings for RAG
connectionConnection pool and database lifecycle

Key Types

/// SochDB-backed session storage
pub struct SochSessionStore {
db: Arc<SochDb>,
}

#[async_trait]
impl SessionStore for SochSessionStore {
async fn get(&self, id: &SessionId) -> Result<Option<Session>, StorageError> {
self.db
.get_document("sessions", id.as_str())
.await
.map_err(|e| StorageError::ConnectionFailed(e.to_string()))
}

async fn save(&self, session: &Session) -> Result<(), StorageError> {
self.db
.upsert_document("sessions", session.id.as_str(), session)
.await
.map_err(|e| StorageError::ConnectionFailed(e.to_string()))
}

// ...
}

/// SochDB-backed vector storage for semantic search
pub struct SochVectorStore {
db: Arc<SochDb>,
collection: String,
}

#[async_trait]
impl VectorStore for SochVectorStore {
async fn search(
&self,
query: &[f32],
top_k: usize,
) -> Result<Vec<VectorResult>, StorageError> {
self.db
.vector_search(&self.collection, query, top_k)
.await
.map_err(|e| StorageError::ConnectionFailed(e.to_string()))
}
}

Configuration

[storage]
engine = "sochdb"
path = "./data/clawdesk.sochdb"

[storage.sochdb]
cache_size_mb = 256
wal_enabled = true
compaction_interval_secs = 3600

Example Usage

use clawdesk_sochdb::{SochSessionStore, SochVectorStore};
use clawdesk_storage::SessionStore;

let db = SochDb::open("./data/clawdesk.sochdb").await?;
let session_store = SochSessionStore::new(Arc::new(db));

// Use through the trait interface
let sessions = session_store.list(10, 0).await?;

// Vector search
let vector_store = SochVectorStore::new(db.clone(), "embeddings");
let results = vector_store.search(&query_embedding, 5).await?;
tip

SochDB is an embedded database — no external server needed. Data is stored on the local filesystem at the configured path.