Skip to main content

orbok_cache/
namespace.rs

1//! Cache namespaces (Appendix A §7).
2//!
3//! Namespace strings carry an explicit schema version suffix; payload
4//! shape changes bump the version so `purge_stale_versions` can retire
5//! old rows safely.
6
7use orbok_core::DataClass;
8
9/// The orbok cache namespaces. Embedding bundles are parameterized by
10/// model and vector format so different models never collide.
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub enum OrbokCacheNamespace {
13    /// Extracted, normalized segments per source file (RFC-005 output).
14    ExtractSegments,
15    /// Chunk bundles per source file (RFC-006 output).
16    ChunkBundle,
17    /// Embedding bundles per source file for one model+format (RFC-008).
18    EmbeddingBundle {
19        model_id: String,
20        vector_format: String,
21    },
22    /// Rendered preview/snippet payloads (RFC-013 preview pane).
23    PreviewCache,
24}
25
26impl OrbokCacheNamespace {
27    /// The localcache namespace string (Appendix A §7 table).
28    pub fn as_namespace(&self) -> String {
29        match self {
30            Self::ExtractSegments => "extract-segments:v1".to_string(),
31            Self::ChunkBundle => "chunk-bundle:v1".to_string(),
32            Self::EmbeddingBundle {
33                model_id,
34                vector_format,
35            } => format!("embedding-bundle:{model_id}:{vector_format}:v1"),
36            Self::PreviewCache => "preview-cache:v1".to_string(),
37        }
38    }
39
40    /// localcache payload version for `purge_stale_versions`.
41    pub fn payload_version(&self) -> u32 {
42        1
43    }
44
45    /// Lifecycle class of the payloads (RFC-001 §5, Appendix A §6):
46    /// derived pipeline payloads are rebuildable; previews are ephemeral.
47    pub fn data_class(&self) -> DataClass {
48        match self {
49            Self::ExtractSegments | Self::ChunkBundle | Self::EmbeddingBundle { .. } => {
50                DataClass::RebuildableIndex
51            }
52            Self::PreviewCache => DataClass::EphemeralCache,
53        }
54    }
55}