gitdataai/lib/ai/rag/document.rs
2026-05-30 01:38:40 +08:00

45 lines
1.0 KiB
Rust

use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RagDocument {
pub id: String,
pub content: String,
pub metadata: HashMap<String, Value>,
}
impl RagDocument {
pub fn new(id: impl Into<String>, content: impl Into<String>) -> Self {
Self {
id: id.into(),
content: content.into(),
metadata: HashMap::new(),
}
}
pub fn with_metadata(mut self, metadata: HashMap<String, Value>) -> Self {
self.metadata = metadata;
self
}
pub fn metadata_value(
mut self,
key: impl Into<String>,
value: impl Into<Value>,
) -> Self {
self.metadata.insert(key.into(), value.into());
self
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RagSearchHit {
pub id: String,
pub session_id: String,
pub score: f32,
pub content: String,
pub metadata: HashMap<String, Value>,
}