Skip to main content

EmbeddingConfig

Struct EmbeddingConfig 

Source
pub struct EmbeddingConfig {
    pub provider: EmbeddingProvider,
    pub model: String,
    pub dimensions: usize,
    pub endpoint: Option<String>,
    pub api_key: Option<String>,
    pub api_version: Option<String>,
    pub max_completion_tokens: usize,
    pub batch_size: usize,
    pub mock: bool,
    pub mock_mode: MockVectorMode,
    pub onnx: OnnxEmbeddingConfig,
    pub huggingface_tokenizer: Option<String>,
}
Expand description

Unified embedding configuration.

Provider-agnostic; holds fields for all supported backends. Load from environment variables via EmbeddingConfig::from_env, or construct programmatically and pass to EmbeddingConfig::create_engine.

Environment variables (match Python SDK names):

  • EMBEDDING_PROVIDER — backend selection (default: openai; onnx on Android)
  • MOCK_EMBEDDING — set to true/1/yes to force mock mode
  • EMBEDDING_MODEL — model identifier
  • EMBEDDING_DIMENSIONS — vector size
  • EMBEDDING_ENDPOINT — API endpoint URL
  • EMBEDDING_API_KEY — API key (fallback: LLM_API_KEY)
  • EMBEDDING_API_VERSION — API version string
  • EMBEDDING_MAX_COMPLETION_TOKENS — maximum tokens (default: 8191)
  • EMBEDDING_BATCH_SIZE — texts per embedding request (default: 36)
  • EMBEDDING_ONNX_BATCH_SIZE — ONNX inference batch size (default: 32; onnx feature only)
  • HUGGINGFACE_TOKENIZER — HuggingFace tokenizer identifier

Fields§

§provider: EmbeddingProvider

Which backend to use for embedding generation.

§model: String

Model identifier. For ONNX this is informational; for API providers this is sent in the request body. Default depends on provider (BGE-Small-v1.5 for ONNX, empty for others).

§dimensions: usize

Embedding vector dimensionality. Must match the model output.

§endpoint: Option<String>

API endpoint URL (used by OpenAI-compatible and Ollama providers).

§api_key: Option<String>

API key. Reads EMBEDDING_API_KEY first, falls back to LLM_API_KEY.

§api_version: Option<String>

API version string (e.g. “2023-05-15” for Azure OpenAI).

§max_completion_tokens: usize

Maximum tokens for completion requests (default: 8191).

§batch_size: usize

Number of texts to send in a single embedding request (default: 36).

Matches the Python SDK and stays within the small client-batch limits of the self-hosted servers this adapter targets (e.g. TEI defaults to 32). Raise it via EMBEDDING_BATCH_SIZE for providers that accept larger batches. For the OpenAI-compatible engine, up to MAX_CONCURRENT_BATCHES sub-batches are also dispatched concurrently.

§mock: bool

If true, use mock embeddings regardless of provider. Overrides provider to Mock. Set via MOCK_EMBEDDING=true.

§mock_mode: MockVectorMode

How the mock engine generates vectors when provider is Mock. Defaults to MockVectorMode::Zero. Set via MOCK_EMBEDDING=deterministic to derive content-stable vectors from sha256(text).

§onnx: OnnxEmbeddingConfig

ONNX-specific configuration. Only consulted when provider is Onnx or Fastembed.

§huggingface_tokenizer: Option<String>

HuggingFace tokenizer identifier for chunking token counting. When set, used by HuggingFaceTokenCounter in the chunking crate.

Implementations§

Source§

impl EmbeddingConfig

Source

pub fn from_env() -> Self

Load configuration from environment variables.

Reads the same env var names as the Python SDK so that a shared .env file works across both implementations without modification.

Source

pub fn effective_provider(&self) -> EmbeddingProvider

Returns the effective provider, substituting Mock when self.mock is true.

Source

pub async fn create_engine(&self) -> EmbeddingResult<Arc<dyn EmbeddingEngine>>

Create an embedding engine based on this configuration.

Dispatches to the appropriate engine implementation based on EmbeddingConfig::effective_provider. Providers not yet implemented return [EmbeddingError::NotImplemented].

Trait Implementations§

Source§

impl Clone for EmbeddingConfig

Source§

fn clone(&self) -> EmbeddingConfig

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 EmbeddingConfig

Source§

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

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

impl Default for EmbeddingConfig

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for EmbeddingConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for EmbeddingConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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