mirror of
https://github.com/perstarkse/minne.git
synced 2026-05-28 02:19:34 +02:00
chore: add must_use to 27 non-Result public functions
- constructors: KnowledgeEntity, TextChunk, Scratchpad, IngestionTask, Conversation, KnowledgeRelationship, Message, TextContent, KnowledgeEntityEmbedding, TextChunkEmbedding - accessors: Theme::as_str, Theme::initial_theme, TaskState::as_str, TaskState::display_label, StorageManager::backend_kind, StorageManager::local_base_path, EmbeddingProvider::backend_label, EmbeddingProvider::dimension, EmbeddingProvider::model_code - queries: TaskState::is_terminal, IngestionTask::can_retry, KnowledgeEntityType::variants, StorageManager::resolve_local_path, resolve_base_dir, IngestionTask::lease_duration - helpers: Message::format_history - builders: StorageManager::with_backend
This commit is contained in:
@@ -46,6 +46,7 @@ impl StorageManager {
|
|||||||
///
|
///
|
||||||
/// This method is useful for testing scenarios where you want to inject
|
/// This method is useful for testing scenarios where you want to inject
|
||||||
/// a specific storage backend.
|
/// a specific storage backend.
|
||||||
|
#[must_use]
|
||||||
pub fn with_backend(store: DynStorage, backend_kind: StorageKind) -> Self {
|
pub fn with_backend(store: DynStorage, backend_kind: StorageKind) -> Self {
|
||||||
Self {
|
Self {
|
||||||
store,
|
store,
|
||||||
@@ -55,11 +56,13 @@ impl StorageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the storage backend kind.
|
/// Get the storage backend kind.
|
||||||
|
#[must_use]
|
||||||
pub fn backend_kind(&self) -> &StorageKind {
|
pub fn backend_kind(&self) -> &StorageKind {
|
||||||
&self.backend_kind
|
&self.backend_kind
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access the resolved local base directory when using the local backend.
|
/// Access the resolved local base directory when using the local backend.
|
||||||
|
#[must_use]
|
||||||
pub fn local_base_path(&self) -> Option<&Path> {
|
pub fn local_base_path(&self) -> Option<&Path> {
|
||||||
self.local_base.as_deref()
|
self.local_base.as_deref()
|
||||||
}
|
}
|
||||||
@@ -68,6 +71,7 @@ impl StorageManager {
|
|||||||
///
|
///
|
||||||
/// Returns `None` when the backend is not local or when the provided location includes
|
/// Returns `None` when the backend is not local or when the provided location includes
|
||||||
/// unsupported components (absolute paths or parent traversals).
|
/// unsupported components (absolute paths or parent traversals).
|
||||||
|
#[must_use]
|
||||||
pub fn resolve_local_path(&self, location: &str) -> Option<PathBuf> {
|
pub fn resolve_local_path(&self, location: &str) -> Option<PathBuf> {
|
||||||
let base = self.local_base_path()?;
|
let base = self.local_base_path()?;
|
||||||
let relative = Path::new(location);
|
let relative = Path::new(location);
|
||||||
@@ -544,6 +548,7 @@ pub mod testing {
|
|||||||
/// Resolve the absolute base directory used for local storage from config.
|
/// Resolve the absolute base directory used for local storage from config.
|
||||||
///
|
///
|
||||||
/// If `data_dir` is relative, it is resolved against the current working directory.
|
/// If `data_dir` is relative, it is resolved against the current working directory.
|
||||||
|
#[must_use]
|
||||||
pub fn resolve_base_dir(cfg: &AppConfig) -> PathBuf {
|
pub fn resolve_base_dir(cfg: &AppConfig) -> PathBuf {
|
||||||
if cfg.data_dir.starts_with('/') {
|
if cfg.data_dir.starts_with('/') {
|
||||||
PathBuf::from(&cfg.data_dir)
|
PathBuf::from(&cfg.data_dir)
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Conversation {
|
impl Conversation {
|
||||||
|
#[must_use]
|
||||||
pub fn new(user_id: String, title: String) -> Self {
|
pub fn new(user_id: String, title: String) -> Self {
|
||||||
let now = Utc::now();
|
let now = Utc::now();
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ pub enum TaskState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TaskState {
|
impl TaskState {
|
||||||
|
#[must_use]
|
||||||
pub fn as_str(&self) -> &'static str {
|
pub fn as_str(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
TaskState::Pending => "Pending",
|
TaskState::Pending => "Pending",
|
||||||
@@ -45,6 +46,7 @@ impl TaskState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn is_terminal(&self) -> bool {
|
pub fn is_terminal(&self) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
self,
|
self,
|
||||||
@@ -52,6 +54,7 @@ impl TaskState {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn display_label(&self) -> &'static str {
|
pub fn display_label(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
TaskState::Pending => "Pending",
|
TaskState::Pending => "Pending",
|
||||||
@@ -170,6 +173,7 @@ stored_object!(IngestionTask, "ingestion_task", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
impl IngestionTask {
|
impl IngestionTask {
|
||||||
|
#[must_use]
|
||||||
pub fn new(content: IngestionPayload, user_id: String) -> Self {
|
pub fn new(content: IngestionPayload, user_id: String) -> Self {
|
||||||
let now = chrono::Utc::now();
|
let now = chrono::Utc::now();
|
||||||
|
|
||||||
@@ -193,10 +197,12 @@ impl IngestionTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn can_retry(&self) -> bool {
|
pub fn can_retry(&self) -> bool {
|
||||||
self.attempts < self.max_attempts
|
self.attempts < self.max_attempts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn lease_duration(&self) -> Duration {
|
pub fn lease_duration(&self) -> Duration {
|
||||||
Duration::from_secs(u64::try_from(self.lease_duration_secs.max(0)).unwrap_or(0))
|
Duration::from_secs(u64::try_from(self.lease_duration_secs.max(0)).unwrap_or(0))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ pub enum KnowledgeEntityType {
|
|||||||
// Add more types as needed
|
// Add more types as needed
|
||||||
}
|
}
|
||||||
impl KnowledgeEntityType {
|
impl KnowledgeEntityType {
|
||||||
|
#[must_use]
|
||||||
pub fn variants() -> &'static [&'static str] {
|
pub fn variants() -> &'static [&'static str] {
|
||||||
&["Idea", "Project", "Document", "Page", "TextSnippet"]
|
&["Idea", "Project", "Document", "Page", "TextSnippet"]
|
||||||
}
|
}
|
||||||
@@ -101,6 +102,7 @@ pub struct KnowledgeEntityVectorResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl KnowledgeEntity {
|
impl KnowledgeEntity {
|
||||||
|
#[must_use]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
source_id: String,
|
source_id: String,
|
||||||
name: String,
|
name: String,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ impl KnowledgeEntityEmbedding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new knowledge entity embedding
|
/// Create a new knowledge entity embedding
|
||||||
|
#[must_use]
|
||||||
pub fn new(entity_id: &str, embedding: Vec<f32>, user_id: String) -> Self {
|
pub fn new(entity_id: &str, embedding: Vec<f32>, user_id: String) -> Self {
|
||||||
let now = Utc::now();
|
let now = Utc::now();
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ pub struct KnowledgeRelationship {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl KnowledgeRelationship {
|
impl KnowledgeRelationship {
|
||||||
|
#[must_use]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
in_: String,
|
in_: String,
|
||||||
out: String,
|
out: String,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ stored_object!(Message, "message", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
|
#[must_use]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
conversation_id: String,
|
conversation_id: String,
|
||||||
role: MessageRole,
|
role: MessageRole,
|
||||||
@@ -57,6 +58,7 @@ impl fmt::Display for Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// helper function to format a vector of messages
|
// helper function to format a vector of messages
|
||||||
|
#[must_use]
|
||||||
pub fn format_history(history: &[Message]) -> String {
|
pub fn format_history(history: &[Message]) -> String {
|
||||||
let mut out = String::new();
|
let mut out = String::new();
|
||||||
for (i, msg) in history.iter().enumerate() {
|
for (i, msg) in history.iter().enumerate() {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ stored_object!(Scratchpad, "scratchpad", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
impl Scratchpad {
|
impl Scratchpad {
|
||||||
|
#[must_use]
|
||||||
pub fn new(user_id: String, title: String) -> Self {
|
pub fn new(user_id: String, title: String) -> Self {
|
||||||
let now = ChronoUtc::now();
|
let now = ChronoUtc::now();
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ pub struct TextChunkSearchResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TextChunk {
|
impl TextChunk {
|
||||||
|
#[must_use]
|
||||||
pub fn new(source_id: String, chunk: String, user_id: String) -> Self {
|
pub fn new(source_id: String, chunk: String, user_id: String) -> Self {
|
||||||
let now = Utc::now();
|
let now = Utc::now();
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ impl TextChunkEmbedding {
|
|||||||
///
|
///
|
||||||
/// `chunk_id` is the **key** part of the text_chunk id (e.g. the UUID),
|
/// `chunk_id` is the **key** part of the text_chunk id (e.g. the UUID),
|
||||||
/// not "text_chunk:uuid".
|
/// not "text_chunk:uuid".
|
||||||
|
#[must_use]
|
||||||
pub fn new(chunk_id: &str, source_id: String, embedding: Vec<f32>, user_id: String) -> Self {
|
pub fn new(chunk_id: &str, source_id: String, embedding: Vec<f32>, user_id: String) -> Self {
|
||||||
let now = Utc::now();
|
let now = Utc::now();
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ stored_object!(TextContent, "text_content", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
impl TextContent {
|
impl TextContent {
|
||||||
|
#[must_use]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
text: String,
|
text: String,
|
||||||
context: Option<String>,
|
context: Option<String>,
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ impl FromStr for Theme {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Theme {
|
impl Theme {
|
||||||
|
#[must_use]
|
||||||
pub fn as_str(&self) -> &'static str {
|
pub fn as_str(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Light => "light",
|
Self::Light => "light",
|
||||||
@@ -67,6 +68,7 @@ impl Theme {
|
|||||||
|
|
||||||
/// Returns the theme that should be initially applied.
|
/// Returns the theme that should be initially applied.
|
||||||
/// For "system", defaults to "light".
|
/// For "system", defaults to "light".
|
||||||
|
#[must_use]
|
||||||
pub fn initial_theme(&self) -> &'static str {
|
pub fn initial_theme(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::System => "light",
|
Self::System => "light",
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ enum EmbeddingInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EmbeddingProvider {
|
impl EmbeddingProvider {
|
||||||
|
#[must_use]
|
||||||
pub fn backend_label(&self) -> &'static str {
|
pub fn backend_label(&self) -> &'static str {
|
||||||
match self.inner {
|
match self.inner {
|
||||||
EmbeddingInner::Hashed { .. } => "hashed",
|
EmbeddingInner::Hashed { .. } => "hashed",
|
||||||
@@ -86,6 +87,7 @@ impl EmbeddingProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn dimension(&self) -> usize {
|
pub fn dimension(&self) -> usize {
|
||||||
match &self.inner {
|
match &self.inner {
|
||||||
EmbeddingInner::Hashed { dimension } | EmbeddingInner::FastEmbed { dimension, .. } => {
|
EmbeddingInner::Hashed { dimension } | EmbeddingInner::FastEmbed { dimension, .. } => {
|
||||||
@@ -95,6 +97,7 @@ impl EmbeddingProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn model_code(&self) -> Option<String> {
|
pub fn model_code(&self) -> Option<String> {
|
||||||
match &self.inner {
|
match &self.inner {
|
||||||
EmbeddingInner::FastEmbed { model_name, .. } => Some(model_name.to_string()),
|
EmbeddingInner::FastEmbed { model_name, .. } => Some(model_name.to_string()),
|
||||||
|
|||||||
Reference in New Issue
Block a user