lumen_rag/
types.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents a chunk of text processed by the RAG pipeline.
4#[derive(Deserialize, Serialize, Clone, Debug)]
5pub struct Passage {
6    /// Unique identifier for the passage.
7    /// If using MongoDB, this maps to the ObjectId string.
8    #[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
9    pub id: Option<String>,
10
11    /// The content of the passage.
12    pub text: String,
13
14    /// The computed vector embedding.
15    pub embedding: Vec<f32>,
16
17    /// Optional metadata associated with the passage.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub metadata: Option<Metadata>,
20
21    /// A hash of the text content, used for deduplication.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub hash: Option<i64>,
24}
25
26/// Metadata associated with a source document.
27#[derive(Deserialize, Serialize, Clone, Debug, Default)]
28pub struct Metadata {
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub title: Option<String>,
31
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub source: Option<String>,
34
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub date: Option<String>,
37
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub url: Option<String>,
40}
41
42/// Request payload for ingesting text.
43#[derive(Deserialize, Debug)]
44pub struct IngestRequest {
45    pub text: String,
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub metadata: Option<Metadata>,
48}
49
50#[derive(Serialize, Deserialize, Debug)]
51pub struct IngestResponse {
52    pub passage_ids: Vec<String>,
53    pub count: usize,
54}
55
56/// Request payload for asking a question.
57#[derive(Deserialize, Debug)]
58pub struct QuestionRequest {
59    pub question: String,
60}
61
62// Internal structures for LLM communication
63#[derive(Serialize, Clone, Debug)]
64pub struct LLMRequest {
65    pub model: String,
66    pub messages: Vec<LLMMessage>,
67    pub stream: bool,
68}
69
70#[derive(Serialize, Deserialize, Clone, Debug)]
71pub struct LLMMessage {
72    pub role: String,
73    pub content: String,
74}
75
76#[derive(Debug, Deserialize)]
77pub struct LLMStreamResponse {
78    pub choices: Vec<LLMChoice>,
79}
80
81#[derive(Deserialize, Debug)]
82pub struct LLMChoice {
83    pub delta: LLMStreamMessage,
84}
85
86#[derive(Serialize, Deserialize, Clone, Debug)]
87pub struct LLMStreamMessage {
88    pub content: String,
89}