Skip to main content

context_forge/
entry.rs

1use serde::{Deserialize, Serialize};
2
3/// A single context entry stored in the memory engine.
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct ContextEntry {
6    /// Unique identifier (`UUIDv7`, time-ordered).
7    pub id: String,
8    /// The text content of the entry.
9    pub content: String,
10    /// Unix timestamp (seconds) when the entry was created.
11    pub timestamp: i64,
12    /// Caller-defined classification. See the [`kind`] module for well-known values.
13    pub kind: String,
14    /// Namespace partition, e.g. "discord:thread:123", "project:homelab-rs".
15    ///
16    /// `None` means global scope.
17    pub scope: Option<String>,
18    /// Optional caller session identifier.
19    pub session_id: Option<String>,
20    /// Optional pre-computed token count.
21    pub token_count: Option<usize>,
22    /// Arbitrary caller metadata, stored as JSON.
23    pub metadata: Option<serde_json::Value>,
24}
25
26/// Well-known `kind` values. Callers may define their own.
27pub mod kind {
28    /// User-inserted entry.
29    pub const MANUAL: &str = "manual";
30    /// Raw conversation capture.
31    pub const SNAPSHOT: &str = "snapshot";
32    /// Distilled thread/session summary.
33    pub const SUMMARY: &str = "summary";
34    /// Single distilled fact (Phase 5).
35    pub const FACT: &str = "fact";
36}
37
38impl Default for ContextEntry {
39    fn default() -> Self {
40        Self {
41            id: String::new(),
42            content: String::new(),
43            timestamp: 0,
44            kind: kind::MANUAL.to_owned(),
45            scope: None,
46            session_id: None,
47            token_count: None,
48            metadata: None,
49        }
50    }
51}
52
53/// A search result with relevance score.
54#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct ScoredEntry {
56    /// The matched entry.
57    pub entry: ContextEntry,
58    /// Relevance score (higher is more relevant).
59    pub score: f64,
60}