mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-24 17:58:31 +02:00
helper functions
This commit is contained in:
@@ -5,6 +5,8 @@ use surrealdb::{
|
|||||||
Error, Surreal,
|
Error, Surreal,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::storage::types::StoredObject;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SurrealDbClient {
|
pub struct SurrealDbClient {
|
||||||
pub client: Surreal<Client>,
|
pub client: Surreal<Client>,
|
||||||
@@ -32,6 +34,24 @@ impl SurrealDbClient {
|
|||||||
|
|
||||||
Ok(SurrealDbClient { client: db })
|
Ok(SurrealDbClient { client: db })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn rebuild_indexes(&self) -> Result<(), Error> {
|
||||||
|
self.client
|
||||||
|
.query("REBUILD INDEX IF EXISTS idx_embedding ON text_chunk")
|
||||||
|
.await?;
|
||||||
|
self.client
|
||||||
|
.query("REBUILD INDEX IF EXISTS embeddings ON knowledge_entity")
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn drop_table<T>(&self) -> Result<(), Error>
|
||||||
|
where
|
||||||
|
T: StoredObject + Send + Sync + 'static,
|
||||||
|
{
|
||||||
|
let _deleted: Vec<T> = self.client.delete(T::table_name()).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for SurrealDbClient {
|
impl Deref for SurrealDbClient {
|
||||||
|
|||||||
Reference in New Issue
Block a user