Skip to main content

dejadb_context/
presets.rs

1//! Pre-built `FormatPolicy` configurations for common LLM targets.
2//!
3//! Each preset configures format, metadata, and ordering for a model family.
4//! Presets do not set `token_budget` — the caller always knows their budget
5//! better than a preset.
6
7use super::policy::{FormatPolicy, MetadataLevel, Ordering, OutputFormat};
8
9impl FormatPolicy {
10    /// SML format, minimal metadata, relevance-ordered, grouped by type.
11    /// Optimized for Claude models which handle SML context natively.
12    pub fn claude() -> Self {
13        Self::new(OutputFormat::Sml)
14            .metadata(MetadataLevel::Minimal)
15            .ordering(Ordering::ByRelevance)
16            .group_by_type()
17    }
18
19    /// Markdown format, minimal metadata, relevance-ordered.
20    /// Good for GPT-4, GPT-4o, and similar models.
21    pub fn gpt4() -> Self {
22        Self::new(OutputFormat::Markdown)
23            .metadata(MetadataLevel::Minimal)
24            .ordering(Ordering::ByRelevance)
25    }
26
27    /// Markdown format, minimal metadata, relevance-ordered.
28    /// Alias for `gpt4()` — Gemini also handles markdown well.
29    pub fn gemini() -> Self {
30        Self::gpt4()
31    }
32
33    /// Plain text, no metadata, relevance-ordered.
34    /// For small local models with tight context windows.
35    pub fn local_small() -> Self {
36        Self::new(OutputFormat::PlainText)
37            .metadata(MetadataLevel::None)
38            .ordering(Ordering::ByRelevance)
39    }
40
41    /// JSON format, full metadata, relevance-ordered.
42    /// For programmatic consumers, A2A, and API responses.
43    pub fn json_api() -> Self {
44        Self::new(OutputFormat::Json)
45            .metadata(MetadataLevel::Full)
46            .ordering(Ordering::ByRelevance)
47    }
48}
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_claude_preset() {
56        let p = FormatPolicy::claude();
57        assert_eq!(p.format, OutputFormat::Sml);
58        assert_eq!(p.metadata, MetadataLevel::Minimal);
59        assert_eq!(p.ordering, Ordering::ByRelevance);
60        assert!(p.sections.group_by_type);
61        assert!(p.token_budget.is_none());
62    }
63
64    #[test]
65    fn test_gpt4_preset() {
66        let p = FormatPolicy::gpt4();
67        assert_eq!(p.format, OutputFormat::Markdown);
68        assert_eq!(p.metadata, MetadataLevel::Minimal);
69        assert!(!p.sections.group_by_type);
70    }
71
72    #[test]
73    fn test_gemini_matches_gpt4() {
74        let g = FormatPolicy::gemini();
75        let gpt = FormatPolicy::gpt4();
76        assert_eq!(g.format, gpt.format);
77        assert_eq!(g.metadata, gpt.metadata);
78        assert_eq!(g.ordering, gpt.ordering);
79    }
80
81    #[test]
82    fn test_local_small_preset() {
83        let p = FormatPolicy::local_small();
84        assert_eq!(p.format, OutputFormat::PlainText);
85        assert_eq!(p.metadata, MetadataLevel::None);
86    }
87
88    #[test]
89    fn test_json_api_preset() {
90        let p = FormatPolicy::json_api();
91        assert_eq!(p.format, OutputFormat::Json);
92        assert_eq!(p.metadata, MetadataLevel::Full);
93    }
94
95    #[test]
96    fn test_preset_with_budget_override() {
97        let p = FormatPolicy::claude().token_budget(4096);
98        assert_eq!(p.format, OutputFormat::Sml);
99        assert_eq!(p.token_budget, Some(4096));
100    }
101}