mirror of
https://github.com/perstarkse/minne.git
synced 2026-05-13 19:30:42 +02:00
refactoring: completed storage, now using new fn to construct
This commit is contained in:
55
src/storage/types/knowledge_entity.rs
Normal file
55
src/storage/types/knowledge_entity.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use crate::stored_object;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub enum KnowledgeEntityType {
|
||||
Idea,
|
||||
Project,
|
||||
Document,
|
||||
Page,
|
||||
TextSnippet,
|
||||
// Add more types as needed
|
||||
}
|
||||
|
||||
impl From<String> for KnowledgeEntityType {
|
||||
fn from(s: String) -> Self {
|
||||
match s.to_lowercase().as_str() {
|
||||
"idea" => KnowledgeEntityType::Idea,
|
||||
"project" => KnowledgeEntityType::Project,
|
||||
"document" => KnowledgeEntityType::Document,
|
||||
"page" => KnowledgeEntityType::Page,
|
||||
"textsnippet" => KnowledgeEntityType::TextSnippet,
|
||||
_ => KnowledgeEntityType::Document, // Default case
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stored_object!(KnowledgeEntity, "knowledge_entity", {
|
||||
source_id: String,
|
||||
name: String,
|
||||
description: String,
|
||||
entity_type: KnowledgeEntityType,
|
||||
metadata: Option<serde_json::Value>,
|
||||
embedding: Vec<f32>
|
||||
});
|
||||
|
||||
impl KnowledgeEntity {
|
||||
pub fn new(
|
||||
source_id: String,
|
||||
name: String,
|
||||
description: String,
|
||||
entity_type: KnowledgeEntityType,
|
||||
metadata: Option<serde_json::Value>,
|
||||
embedding: Vec<f32>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: Uuid::new_v4().to_string(),
|
||||
source_id,
|
||||
name,
|
||||
description,
|
||||
entity_type,
|
||||
metadata,
|
||||
embedding,
|
||||
}
|
||||
}
|
||||
}
|
||||
26
src/storage/types/knowledge_relationship.rs
Normal file
26
src/storage/types/knowledge_relationship.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use crate::stored_object;
|
||||
use uuid::Uuid;
|
||||
|
||||
stored_object!(KnowledgeRelationship, "knowledge_relationship", {
|
||||
in_: String,
|
||||
out: String,
|
||||
relationship_type: String,
|
||||
metadata: Option<serde_json::Value>
|
||||
});
|
||||
|
||||
impl KnowledgeRelationship {
|
||||
pub fn new(
|
||||
in_: String,
|
||||
out: String,
|
||||
relationship_type: String,
|
||||
metadata: Option<serde_json::Value>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: Uuid::new_v4().to_string(),
|
||||
in_,
|
||||
out,
|
||||
relationship_type,
|
||||
metadata,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
use axum::async_trait;
|
||||
use serde::{Deserialize, Serialize};
|
||||
pub mod knowledge_entity;
|
||||
pub mod knowledge_relationship;
|
||||
pub mod text_chunk;
|
||||
pub mod text_content;
|
||||
|
||||
@@ -11,7 +13,7 @@ pub trait StoredObject: Serialize + for<'de> Deserialize<'de> {
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! stored_object {
|
||||
($name:ident, $table:expr, {$($field:ident: $ty:ty),*}) => {
|
||||
($name:ident, $table:expr, {$($(#[$attr:meta])* $field:ident: $ty:ty),*}) => {
|
||||
use axum::async_trait;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use surrealdb::sql::Thing;
|
||||
|
||||
@@ -11,15 +11,18 @@ stored_object!(TextContent, "text_content", {
|
||||
});
|
||||
|
||||
impl TextContent {
|
||||
pub fn new(text: String, instructions: String, category: String) -> Self {
|
||||
pub fn new(
|
||||
text: String,
|
||||
instructions: String,
|
||||
category: String,
|
||||
file_info: Option<FileInfo>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: Uuid::new_v4().to_string(),
|
||||
text,
|
||||
file_info: None,
|
||||
file_info,
|
||||
instructions,
|
||||
category,
|
||||
}
|
||||
}
|
||||
|
||||
// Other methods...
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user