pub struct WriteBuffer { /* private fields */ }Expand description
Write buffer for batched operations.
Provides durability through WAL and performance through batching.
§Example
ⓘ
use rag_plusplus_core::buffer::{WriteBuffer, WriteBufferConfig};
let wal = WalWriter::new(wal_config)?;
let mut store = InMemoryStore::new();
let mut index = FlatIndex::new(IndexConfig::new(128));
let mut buffer = WriteBuffer::new(
WriteBufferConfig::new(),
Arc::new(wal),
);
buffer.insert(record)?;
buffer.update_stats(&id, 0.9)?;
// Flush to store and index
buffer.flush(&mut store, &mut index)?;Implementations§
Source§impl WriteBuffer
impl WriteBuffer
Sourcepub fn new(config: WriteBufferConfig, wal: Arc<WalWriter>) -> Self
pub fn new(config: WriteBufferConfig, wal: Arc<WalWriter>) -> Self
Create a new write buffer with WAL.
Sourcepub fn without_wal(config: WriteBufferConfig) -> Self
pub fn without_wal(config: WriteBufferConfig) -> Self
Create a write buffer without WAL (testing/in-memory only).
Sourcepub fn insert(&self, record: MemoryRecord) -> Result<()>
pub fn insert(&self, record: MemoryRecord) -> Result<()>
Insert a record.
The record is logged to WAL (if enabled) and buffered.
Sourcepub fn update_stats(&self, id: &RecordId, outcome: f64) -> Result<()>
pub fn update_stats(&self, id: &RecordId, outcome: f64) -> Result<()>
Update record statistics.
Sourcepub fn flush<S: RecordStore, I: VectorIndex>(
&self,
store: &mut S,
index: &mut I,
) -> Result<FlushResult>
pub fn flush<S: RecordStore, I: VectorIndex>( &self, store: &mut S, index: &mut I, ) -> Result<FlushResult>
Flush buffer to store and index.
All buffered operations are applied atomically.
Sourcepub fn flush_to_store<S: RecordStore>(
&self,
store: &mut S,
) -> Result<FlushResult>
pub fn flush_to_store<S: RecordStore>( &self, store: &mut S, ) -> Result<FlushResult>
Flush only to store (no index update).
Sourcepub fn maybe_flush<S: RecordStore, I: VectorIndex>(
&self,
store: &mut S,
index: &mut I,
) -> Result<bool>
pub fn maybe_flush<S: RecordStore, I: VectorIndex>( &self, store: &mut S, index: &mut I, ) -> Result<bool>
Auto-flush if buffer thresholds are exceeded.
Returns true if flush occurred.
Sourcepub fn stats(&self) -> BufferStats
pub fn stats(&self) -> BufferStats
Get buffer statistics.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WriteBuffer
impl !RefUnwindSafe for WriteBuffer
impl Send for WriteBuffer
impl Sync for WriteBuffer
impl Unpin for WriteBuffer
impl !UnwindSafe for WriteBuffer
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Gets the layout of the type.