Skip to main content

elph_core/floppy/
mod.rs

1//! Agent memory store for task-scoped retrieval, scoring, and weight updates.
2//!
3//! Ported from the [memelord](https://github.com/glommer/memelord) SDK
4//! (`packages/sdk`). The original code is licensed under the
5//! [MIT License](https://opensource.org/licenses/MIT).
6//! Copyright (c) 2026 Glauber Costa.
7//!
8//! This Rust port preserves the core design (Turso-backed vector search,
9//! Welford baseline scoring, EMA weight updates) with platform-specific
10//! adaptations for the Turso Rust driver.
11//!
12//! Configuration is explicit: use [`FloppyBuilder`] or [`FloppyConfig`] builder methods.
13//! No environment variables are read inside this module.
14
15mod builder;
16mod embed;
17pub mod migrations;
18mod paths;
19mod query;
20mod report;
21mod scoring;
22mod store;
23mod types;
24mod util;
25
26pub use builder::FloppyBuilder;
27pub use embed::{DEFAULT_EMBED_MODEL, FastEmbedOptions, create_fastembed};
28#[cfg(feature = "fastembed")]
29pub use embed::{embedding_dims, resolve_embedding_model};
30pub use migrations::{FloppyMigration, LAST_VERSION, MIGRATIONS, V1_NAME, V1_UP, V2_NAME, V2_UP, V3_NAME, V3_UP};
31pub use paths::{DB_FILE_NAME, DEFAULT_DATA_DIR, FloppyPaths};
32pub use store::{EmbedFn, MemoryStore, noop_embedder};
33pub use types::{
34    CategoryCount, ContradictResult, DecayResult, EmbeddingStatus, EndTaskWithDecayResult, FloppyConfig, Memory,
35    MemoryCategory, MemoryRecord, MemoryReportInput, MemoryReportType, MemoryStats, ReportCorrectionInput,
36    ReportUserInput, SelfReportEntry, StartTaskResult, StoreStatus, TaskBaseline, TaskCreatedMemory, TaskEndInput,
37    TaskRecord, TaskRetrieval, TaskStatus, TimelineEvent, TimelineEventKind, TopMemory, UserInputSource, VectorType,
38};
39pub use util::{DEFAULT_EMBEDDING_DIMS, VALID_EMBEDDING_BYTES, category_str};
40
41pub fn create_memory_store(config: FloppyConfig, embed: EmbedFn) -> MemoryStore {
42    MemoryStore::new(config, embed)
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn factory_delegates_to_memory_store_new() {
51        let dir = tempfile::tempdir().expect("tempdir");
52        let db_path = dir.path().join("factory.db").to_string_lossy().into_owned();
53        let config = FloppyConfig {
54            db_path,
55            session_id: "s".to_string(),
56            vector_type: None,
57            dimensions: None,
58            top_k: None,
59            learning_rate: None,
60            decay_rate: None,
61            apply_migrations: None,
62        };
63        let embed: EmbedFn = std::sync::Arc::new(|_| Box::pin(async { Ok(vec![1.0, 0.0, 0.0, 0.0]) }));
64        let _store = create_memory_store(config, embed);
65    }
66}