1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use bon::Builder;
use chrono::{DateTime, Utc};
use diesel::{Insertable, Queryable, Selectable};
use pgvector::Vector;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use crate::utils;
#[derive(Debug, Deserialize, PartialEq, Queryable, Selectable, Serialize, ToSchema)]
#[diesel(table_name = crate::schema::notes)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Note {
/// Unique note ID.
pub id: i32,
/// Note content.
pub content: String,
/// Datetime the note was created in ISO format.
pub created_at: DateTime<Utc>,
}
#[derive(Insertable)]
#[diesel(table_name = crate::schema::notes)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct NewNote {
pub content: String,
pub embedding: Vector,
}
#[derive(Builder, Deserialize, JsonSchema, Serialize, ToSchema)]
pub struct NewNoteRequest {
/// Note content to add.
pub content: String,
}
#[derive(Builder, Deserialize, JsonSchema, Serialize, ToSchema)]
pub struct NoteSearchParams {
/// Select notes using their database-generated IDs rather than searching
/// for them.
pub ids: Option<Vec<i32>>,
/// User query string to compare embeddings against. Basically,
/// if the user is asking something like "what color is my jacket?",
/// then the query string should be something like "jacket color" or
/// the user's original question. This can be left empty to ignore
/// similarity search in cases where the user wants to filter by
/// other means or get all items.
pub query: Option<String>,
/// Whether to match the query string more closely using a reranking -based
/// approach. `true` is useful for cases where the user is looking to match
/// to specific words or phrases, whereas `false` is useful for more broad
/// matching.
pub use_reranking_filter: Option<bool>,
/// Filter on notes created after this ISO formatted datetime.
pub created_from: Option<DateTime<Utc>>,
/// Filter on notes created before this ISO formatted datetime.
pub created_to: Option<DateTime<Utc>>,
/// How to order results for retrieved notes.
pub order_by: Option<utils::OrderBy>,
/// Limit the max number of notes to return from the search.
pub limit: Option<i64>,
}