Skip to main content

llm_kernel/embedding/
mod.rs

1//! Embedding provider abstraction.
2//!
3//! Defines a trait for text embedding and provides common utilities.
4//! Concrete backends (local ONNX, candle, OpenAI) are feature-gated.
5//!
6//! ```
7//! use llm_kernel::embedding::{EmbeddingProvider, EmbeddingResult};
8//! ```
9
10pub mod catalog;
11pub mod types;
12
13#[cfg(feature = "embedding-openai")]
14pub mod openai;
15
16#[cfg(any(
17    feature = "embedding-fastembed",
18    feature = "embedding-fastembed-dynamic-linking"
19))]
20pub mod fastembed;
21
22#[cfg(any(
23    feature = "embedding-fastembed",
24    feature = "embedding-fastembed-dynamic-linking"
25))]
26pub mod lazy;
27
28/// BGE-M3 joint dense + sparse embedding (feature `embedding-fastembed`).
29#[cfg(any(
30    feature = "embedding-fastembed",
31    feature = "embedding-fastembed-dynamic-linking"
32))]
33pub mod bgem3;
34
35#[cfg(feature = "embedding-fastembed-qwen3")]
36pub mod qwen3;
37
38#[cfg(feature = "embedding-fastembed-nomic-moe")]
39pub mod nomic_moe;
40
41/// Vector index trait and types (zero dependencies).
42pub mod vector_index;
43
44/// Sparse (lexical) vectors for hybrid retrieval (zero dependencies).
45pub mod sparse;
46
47/// Async vector index trait for remote/shared backends (needs `async_trait`).
48pub mod async_vector_index;
49
50/// Qdrant `AsyncVectorIndex` (feature `qdrant`).
51#[cfg(feature = "qdrant")]
52pub mod qdrant;
53
54/// Elasticsearch `AsyncVectorIndex` (feature `elastic`).
55#[cfg(feature = "elastic")]
56pub mod elastic;
57
58/// pgvector `AsyncVectorIndex` (feature `pgvector`) — PostgreSQL + pgvector ext.
59#[cfg(feature = "pgvector")]
60pub mod pgvector;
61
62#[cfg(feature = "vector-index")]
63pub mod turbovec;
64
65pub use catalog::EmbeddingModel;
66pub use types::{EmbeddingProvider, EmbeddingResult, chunk_batch, cosine_similarity};
67
68#[cfg(feature = "embedding-openai")]
69pub use openai::OpenAIEmbeddingClient;
70
71#[cfg(any(
72    feature = "embedding-fastembed",
73    feature = "embedding-fastembed-dynamic-linking"
74))]
75pub use fastembed::FastembedProvider;
76
77#[cfg(any(
78    feature = "embedding-fastembed",
79    feature = "embedding-fastembed-dynamic-linking"
80))]
81pub use bgem3::{BGEM3_DENSE_DIM, BGEM3_VOCAB_SIZE, Bgem3Provider, JointEmbedding};
82
83#[cfg(any(
84    feature = "embedding-fastembed",
85    feature = "embedding-fastembed-dynamic-linking"
86))]
87pub use lazy::{EmbeddingCache, LazyFastembedProvider, LazyOpts, ModelState, is_model_cached};
88
89#[cfg(feature = "embedding-fastembed-qwen3")]
90pub use qwen3::Qwen3Provider;
91
92#[cfg(feature = "embedding-fastembed-nomic-moe")]
93pub use nomic_moe::NomicMoeProvider;
94
95/// Re-export `ort` for DirectML execution provider configuration.
96///
97/// Consumers that need `DirectMLExecutionProvider` (e.g. to pass it to
98/// `fastembed::TextInitOptions::with_execution_providers`) should use this
99/// re-export rather than depending on `ort` directly — this ensures the
100/// pinned version stays compatible with fastembed's ONNX Runtime.
101#[cfg(feature = "embedding-fastembed-directml")]
102pub use ort;
103
104pub use async_vector_index::AsyncVectorIndex;
105pub use sparse::SparseVector;
106pub use vector_index::{Fusion, SearchHit, VectorIndex};
107
108#[cfg(feature = "qdrant")]
109pub use qdrant::QdrantVectorIndex;
110
111#[cfg(feature = "elastic")]
112pub use elastic::ElasticsearchVectorIndex;
113
114#[cfg(feature = "pgvector")]
115pub use pgvector::{PgSparseVectorIndex, PgVectorIndex, PgVectorOpts};
116
117#[cfg(feature = "vector-index")]
118pub use turbovec::{IndexMeta, TurbovecIndex};