purge embeddings older than a week
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
use super::*;
|
||||
use time::OffsetDateTime;
|
||||
use time::Duration;
|
||||
|
||||
impl Database {
|
||||
pub async fn get_embeddings(
|
||||
@@ -31,11 +33,14 @@ impl Database {
|
||||
) -> Result<()> {
|
||||
self.weak_transaction(|tx| async move {
|
||||
embedding::Entity::insert_many(embeddings.iter().map(|(digest, dimensions)| {
|
||||
let now_offset_datetime = OffsetDateTime::now_utc();
|
||||
let retrieved_at = PrimitiveDateTime::new(now_offset_datetime.date(), now_offset_datetime.time());
|
||||
|
||||
embedding::ActiveModel {
|
||||
provider: ActiveValue::set(provider.to_string()),
|
||||
digest: ActiveValue::set(digest.clone()),
|
||||
dimensions: ActiveValue::set(dimensions.clone()),
|
||||
retrieved_at: ActiveValue::set(OffsetDateTime::now()),
|
||||
retrieved_at: ActiveValue::set(retrieved_at),
|
||||
}
|
||||
}))
|
||||
.on_conflict(
|
||||
@@ -52,7 +57,11 @@ impl Database {
|
||||
|
||||
pub async fn purge_old_embeddings(&self) -> Result<()> {
|
||||
self.weak_transaction(|tx| async move {
|
||||
embedding::Entity::delete_many().filter(embedding::Column::RetrievedAt.lte())
|
||||
embedding::Entity::delete_many().filter(embedding::Column::RetrievedAt.lte(
|
||||
OffsetDateTime::now_utc() - Duration::days(7)
|
||||
)).exec(&*tx).await?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user