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/// BGE-small-en-v1.5 via Rust-native MLX (feature `embedding-mlx`, macOS only).
42#[cfg(all(feature = "embedding-mlx", target_os = "macos"))]
43pub mod mlx;
44
45/// Vector index trait and types (zero dependencies).
46pub mod vector_index;
47
48/// Sparse (lexical) vectors for hybrid retrieval (zero dependencies).
49pub mod sparse;
50
51/// Async vector index trait for remote/shared backends (needs `async_trait`).
52pub mod async_vector_index;
53
54/// Qdrant `AsyncVectorIndex` (feature `qdrant`).
55#[cfg(feature = "qdrant")]
56pub mod qdrant;
57
58/// Elasticsearch `AsyncVectorIndex` (feature `elastic`).
59#[cfg(feature = "elastic")]
60pub mod elastic;
61
62/// pgvector `AsyncVectorIndex` (feature `pgvector`) — PostgreSQL + pgvector ext.
63#[cfg(feature = "pgvector")]
64pub mod pgvector;
65
66#[cfg(feature = "vector-index")]
67pub mod turbovec;
68
69pub use catalog::EmbeddingModel;
70pub use types::{EmbeddingProvider, EmbeddingResult, chunk_batch, cosine_similarity};
71
72#[cfg(feature = "embedding-openai")]
73pub use openai::OpenAIEmbeddingClient;
74
75#[cfg(any(
76    feature = "embedding-fastembed",
77    feature = "embedding-fastembed-dynamic-linking"
78))]
79pub use fastembed::FastembedProvider;
80
81#[cfg(any(
82    feature = "embedding-fastembed",
83    feature = "embedding-fastembed-dynamic-linking"
84))]
85pub use bgem3::{BGEM3_DENSE_DIM, BGEM3_VOCAB_SIZE, Bgem3Provider, JointEmbedding};
86
87#[cfg(any(
88    feature = "embedding-fastembed",
89    feature = "embedding-fastembed-dynamic-linking"
90))]
91pub use lazy::{EmbeddingCache, LazyFastembedProvider, LazyOpts, ModelState, is_model_cached};
92
93#[cfg(feature = "embedding-fastembed-qwen3")]
94pub use qwen3::Qwen3Provider;
95
96#[cfg(feature = "embedding-fastembed-nomic-moe")]
97pub use nomic_moe::NomicMoeProvider;
98
99#[cfg(all(feature = "embedding-mlx", target_os = "macos"))]
100pub use mlx::MlxEmbeddingProvider;
101
102/// Re-export `ort` for DirectML execution provider configuration.
103///
104/// Consumers that need `DirectMLExecutionProvider` (e.g. to pass it to
105/// `fastembed::TextInitOptions::with_execution_providers`) should use this
106/// re-export rather than depending on `ort` directly — this ensures the
107/// pinned version stays compatible with fastembed's ONNX Runtime.
108#[cfg(feature = "embedding-fastembed-directml")]
109pub use ort;
110
111pub use async_vector_index::AsyncVectorIndex;
112pub use sparse::SparseVector;
113pub use vector_index::{Fusion, SearchHit, VectorIndex};
114
115#[cfg(feature = "qdrant")]
116pub use qdrant::QdrantVectorIndex;
117
118#[cfg(feature = "elastic")]
119pub use elastic::ElasticsearchVectorIndex;
120
121#[cfg(feature = "pgvector")]
122pub use pgvector::{PgSparseVectorIndex, PgVectorIndex, PgVectorOpts};
123
124#[cfg(feature = "vector-index")]
125pub use turbovec::{IndexMeta, TurbovecIndex};