Skip to main content

TripletRecipe

Struct TripletRecipe 

Source
pub struct TripletRecipe {
    pub name: Cow<'static, str>,
    pub anchor: Selector,
    pub positive_selector: Selector,
    pub negative_selector: Selector,
    pub negative_strategy: NegativeStrategy,
    pub weight: f32,
    pub instruction: Option<Cow<'static, str>>,
    pub allow_same_anchor_positive: bool,
}
Expand description

Defines a triplet recipe (anchor/positive/negative selection + weighting).

§Split-isolation contract

All three chunk slots (anchor, positive, negative) must resolve to records whose IDs hash to the same split as the request split. The sampler enforces this automatically for Selector::Role, Selector::Paragraph, and Selector::Random — those selectors always read from the record that was already confirmed to be in the correct split.

Selector::TemporalOffset crosses a record boundary (it picks a different record by proximity in time) and the split check is re-applied inside select_temporal_neighbor. No additional care is required on your side, but you should be aware that in pools with few same-split neighbors the selector will return None and fall back to skipping a slot rather than contaminating splits.

§Stable IDs

Record IDs must be stable across runs. Split assignment is derived deterministically from the record ID and the sampler seed; changing an ID changes its split assignment, which invalidates any persisted split state. IDs should also be globally unique — if two records from different sources share the same ID, only one will be kept in the sampler, and the discarded record’s split assignment silently goes with it.

Fields§

§name: Cow<'static, str>

Unique name for this recipe.

§anchor: Selector

Selector used for anchor chunks.

§positive_selector: Selector

Selector used for positive chunks (same record).

§negative_selector: Selector

Selector used for negative chunks (different record).

§negative_strategy: NegativeStrategy

Strategy used to pick negatives.

§weight: f32

Relative weight controlling how often this recipe is selected versus other recipes.

Each recipe with a positive weight receives a number of slots in the shuffled selection order proportional to weight / min_positive_weight across all active recipes, so a recipe with weight = 2.0 is drawn approximately twice as often as one with weight = 1.0. The weight also scales the weight field on every crate::SampleTriplet returned by this recipe, which the caller’s training loop can use for loss weighting.

Recipes with weight <= 0.0 are excluded from selection entirely and no samples are produced for them.

§instruction: Option<Cow<'static, str>>

Optional instruction text attached to samples from this recipe.

§allow_same_anchor_positive: bool

Allow anchor and positive to carry identical text (SimCSE / dropout-trick mode).

When true, the sampler will emit triplets even when the anchor and positive sections resolve to the same text. This enables the unsupervised SimCSE training pattern: the same text string feeds both slots, and the model’s dropout layers produce two slightly different embeddings at training time.

Negatives are still required to differ from both anchor and positive.

Defaults to false; set true only for recipes whose anchor and positive selectors intentionally resolve to the same content (e.g. text-only sources).

Trait Implementations§

Source§

impl Clone for TripletRecipe

Source§

fn clone(&self) -> TripletRecipe

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TripletRecipe

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TripletRecipe

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more