Skip to main content

erio_context_store/
config.rs

1//! Configuration for the context store.
2
3use std::path::PathBuf;
4
5/// HNSW index parameters.
6pub struct HnswConfig {
7    pub m: usize,
8    pub ef_construction: usize,
9    pub ef_search: usize,
10}
11
12impl Default for HnswConfig {
13    fn default() -> Self {
14        Self {
15            m: 16,
16            ef_construction: 100,
17            ef_search: 50,
18        }
19    }
20}
21
22/// Configuration for creating a [`crate::store::ContextStore`].
23pub struct ContextConfig {
24    pub path: PathBuf,
25    pub index: HnswConfig,
26}
27
28/// A single result from a semantic search.
29pub struct SearchResult {
30    pub content: String,
31    pub score: f32,
32    pub metadata: serde_json::Value,
33}
34
35/// Statistics about the context store.
36pub struct StorageStats {
37    pub document_count: usize,
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn hnsw_config_has_sensible_defaults() {
46        let config = HnswConfig::default();
47        assert_eq!(config.m, 16);
48        assert_eq!(config.ef_construction, 100);
49        assert_eq!(config.ef_search, 50);
50    }
51
52    #[test]
53    fn context_config_stores_path() {
54        let config = ContextConfig {
55            path: PathBuf::from("/tmp/store"),
56            index: HnswConfig::default(),
57        };
58        assert_eq!(config.path, PathBuf::from("/tmp/store"));
59    }
60
61    #[test]
62    fn context_config_uses_default_hnsw() {
63        let config = ContextConfig {
64            path: PathBuf::from("/tmp/test"),
65            index: HnswConfig::default(),
66        };
67        assert_eq!(config.index.m, 16);
68    }
69
70    #[test]
71    fn search_result_holds_content_and_score() {
72        let result = SearchResult {
73            content: "hello world".into(),
74            score: 0.95,
75            metadata: serde_json::json!({"source": "test"}),
76        };
77        assert_eq!(result.content, "hello world");
78        assert!((result.score - 0.95).abs() < f32::EPSILON);
79        assert_eq!(result.metadata["source"], "test");
80    }
81
82    #[test]
83    fn storage_stats_reports_document_count() {
84        let stats = StorageStats { document_count: 42 };
85        assert_eq!(stats.document_count, 42);
86    }
87}