pub struct CsvSource { /* private fields */ }Expand description
Column-mapped CSV data source.
Reads all rows from a CSV file at construction and exposes them as
DataRecords. Suitable for small-to-medium datasets that fit comfortably
in memory.
§Modes
Configure the source with either anchor/positive columns (role mode) or a single text column (text mode):
use triplets_core::source::{CsvSource, CsvSourceConfig};
// Role mode: explicit anchor + positive columns.
let config = CsvSourceConfig::new("my_qna", "data/qna.csv")
.with_anchor_column("question")
.with_positive_column("answer")
.with_trust(0.9);
let source = CsvSource::new(config).unwrap();
// Text mode: single text column.
let config2 = CsvSourceConfig::new("my_corpus", "data/corpus.csv")
.with_text_column("text");
let source2 = CsvSource::new(config2).unwrap();Implementations§
Source§impl CsvSource
impl CsvSource
Sourcepub fn new(config: CsvSourceConfig) -> Result<Self, SamplerError>
pub fn new(config: CsvSourceConfig) -> Result<Self, SamplerError>
Load a CSV source from the given configuration.
Returns a SamplerError::Configuration error if the config is invalid,
or a SamplerError::SourceUnavailable error if the CSV file cannot be
opened or parsed.
Trait Implementations§
Source§impl DataSource for CsvSource
impl DataSource for CsvSource
Source§fn id(&self) -> &str
fn id(&self) -> &str
Stable source identifier used in records, metrics, and persistence state.
Source§fn refresh(
&self,
_config: &SamplerConfig,
cursor: Option<&SourceCursor>,
limit: Option<usize>,
) -> Result<SourceSnapshot, SamplerError>
fn refresh( &self, _config: &SamplerConfig, cursor: Option<&SourceCursor>, limit: Option<usize>, ) -> Result<SourceSnapshot, SamplerError>
Source§fn reported_record_count(
&self,
_config: &SamplerConfig,
) -> Result<u128, SamplerError>
fn reported_record_count( &self, _config: &SamplerConfig, ) -> Result<u128, SamplerError>
Exact metadata record count reported by the source. Read more
Source§fn default_triplet_recipes(&self) -> Vec<TripletRecipe>
fn default_triplet_recipes(&self) -> Vec<TripletRecipe>
Optional source-provided default triplet recipes. Read more
Source§impl IndexableSource for CsvSource
impl IndexableSource for CsvSource
Source§fn record_at(&self, idx: usize) -> Result<Option<DataRecord>, SamplerError>
fn record_at(&self, idx: usize) -> Result<Option<DataRecord>, SamplerError>
Return the record at index
idx, or None for sparse/missing positions.Auto Trait Implementations§
impl Freeze for CsvSource
impl RefUnwindSafe for CsvSource
impl Send for CsvSource
impl Sync for CsvSource
impl Unpin for CsvSource
impl UnsafeUnpin for CsvSource
impl UnwindSafe for CsvSource
Blanket Implementations§
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<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 more