Trait llm_weaver::storage::TapestryChestHandler
source · pub trait TapestryChestHandler<T: Config> {
type Error: Display + Debug;
// Required methods
fn save_tapestry_fragment<'async_trait, TID>(
tapestry_id: TID,
tapestry_fragment: TapestryFragment<T>,
increment: bool
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId;
fn save_tapestry_metadata<'async_trait, TID, M>(
tapestry_id: TID,
metadata: M
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId,
M: 'async_trait + ToRedisArgs + Send + Sync;
fn get_tapestry_fragment<'async_trait, TID>(
tapestry_id: TID,
instance: Option<u64>
) -> Pin<Box<dyn Future<Output = Result<Option<TapestryFragment<T>>>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId;
fn get_tapestry_metadata<'async_trait, TID, M>(
tapestry_id: TID,
instance: Option<u64>
) -> Pin<Box<dyn Future<Output = Result<Option<M>>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId,
M: 'async_trait + DeserializeOwned + Default;
}
Expand description
A storage handler trait designed for saving and retrieving fragments of a tapestry.
The TapestryChestHandler
trait provides an asynchronous interface for implementing various
storage handlers to manage tapestry fragments.
Usage
Implementations of TapestryChestHandler
should provide the storage and retrieval mechanisms
tailored to specific use-cases or storage backends, such as databases, file systems, or
in-memory stores.
Checkout the out of the box implementation TapestryChest
whichs uses Redis as the storage
backend.
Required Associated Types§
Required Methods§
sourcefn save_tapestry_fragment<'async_trait, TID>(
tapestry_id: TID,
tapestry_fragment: TapestryFragment<T>,
increment: bool
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
fn save_tapestry_fragment<'async_trait, TID>( tapestry_id: TID, tapestry_fragment: TapestryFragment<T>, increment: bool ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where TID: 'async_trait + TapestryId,
Saves a tapestry fragment.
Parameters
tapestry_id
: Identifies the tapestry.tapestry_fragment
: An instance ofTapestryFragment
to be stored.increment
:- A boolean flag indicating whether the tapestry instance should be incremented.
- This should typically be
true
when saving a new instance ofTapestryFragment
, andfalse
when updating an existing one.
Returns
Returns Result<(), Self::Error>
. On successful storage, it returns Ok(())
. If the
storage operation fails, it should return an Err
variant containing an error of type
Self::Error
.
sourcefn save_tapestry_metadata<'async_trait, TID, M>(
tapestry_id: TID,
metadata: M
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
M: 'async_trait + ToRedisArgs + Send + Sync,
fn save_tapestry_metadata<'async_trait, TID, M>( tapestry_id: TID, metadata: M ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where TID: 'async_trait + TapestryId, M: 'async_trait + ToRedisArgs + Send + Sync,
Save tapestry metadata.
Based on application use cases, you can add aditional data for a given TapestryId
sourcefn get_tapestry_fragment<'async_trait, TID>(
tapestry_id: TID,
instance: Option<u64>
) -> Pin<Box<dyn Future<Output = Result<Option<TapestryFragment<T>>>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
fn get_tapestry_fragment<'async_trait, TID>( tapestry_id: TID, instance: Option<u64> ) -> Pin<Box<dyn Future<Output = Result<Option<TapestryFragment<T>>>> + Send + 'async_trait>>where TID: 'async_trait + TapestryId,
Retrieves the last tapestry fragment, or a fragment at a specified instance.
Parameters
tapestry_id
: Identifies the tapestry.instance
: The instance of the fragment to retrieve. IfNone
, the method should retrieve the last fragment.
Returns
On successful retrieval, it returns Ok(Some(TapestryFragment))
or Ok(None)
if no
fragment was found. If the retrieval operation fails, it should return an Err
variant
containing an error of type Self::Error
.
sourcefn get_tapestry_metadata<'async_trait, TID, M>(
tapestry_id: TID,
instance: Option<u64>
) -> Pin<Box<dyn Future<Output = Result<Option<M>>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
M: 'async_trait + DeserializeOwned + Default,
fn get_tapestry_metadata<'async_trait, TID, M>( tapestry_id: TID, instance: Option<u64> ) -> Pin<Box<dyn Future<Output = Result<Option<M>>> + Send + 'async_trait>>where TID: 'async_trait + TapestryId, M: 'async_trait + DeserializeOwned + Default,
Retrieves the last tapestry metadata, or a metadata at a specified instance.