1#![deny(unsafe_code)]
35
36pub mod cache;
37pub(crate) mod cache_dir;
38pub mod cancellation;
39pub mod core;
40pub mod engine;
41pub mod error;
42pub mod extraction;
44pub mod extractors;
45#[cfg(all(
46 feature = "layout-detection",
47 any(feature = "pdf", feature = "ocr", feature = "ocr-wasm")
48))]
49pub mod model_cache;
50pub mod plugins;
51pub mod rendering;
52pub mod telemetry;
53pub mod text;
55pub mod types;
56pub mod utils;
57
58#[cfg(any(feature = "ocr", feature = "pdf", feature = "paddle-ocr"))]
59pub mod table_core;
60
61#[cfg(feature = "tower-service")]
62pub mod service;
63
64#[cfg(feature = "api")]
65pub mod api;
66
67#[cfg(feature = "mcp")]
68pub mod mcp;
69
70#[cfg(feature = "chunking")]
71pub mod chunking;
72
73#[cfg(feature = "diff")]
74pub mod diff;
75
76#[cfg(all(feature = "liter-llm", not(target_arch = "wasm32")))]
77pub mod llm;
78
79#[cfg(feature = "embedding-presets")]
80pub mod embeddings;
81
82#[cfg(any(feature = "reranker-presets", feature = "reranker"))]
83pub mod reranking;
84
85#[cfg(feature = "onnx-runtime")]
87pub(crate) mod onnx;
88
89#[cfg(any(feature = "sparse-embedding-presets", feature = "sparse-embeddings"))]
91pub mod sparse_embeddings;
92
93#[cfg(any(feature = "late-interaction-presets", feature = "late-interaction"))]
95pub mod late_interaction;
96
97#[cfg(feature = "ocr")]
98pub mod image;
100
101#[cfg(feature = "language-detection")]
102pub mod language_detection;
103
104#[cfg(feature = "stopwords")]
105pub mod stopwords;
106
107#[cfg(any(feature = "keywords-yake", feature = "keywords-rake"))]
108pub mod keywords;
109
110#[cfg(feature = "enrichment")]
111pub mod enrichment;
112
113#[cfg(feature = "heuristics")]
114pub mod heuristics;
115
116#[cfg(feature = "heuristics")]
117pub use heuristics::{
118 BoundaryReason, ChunkInfo, ChunkPlan, ChunkingDecision, ChunkingReason, ConfidenceSignals, ConfidenceWeights,
119 DocumentBoundary, DocumentMetadata, HeuristicsConfig, HeuristicsError, MultidocInput, MultidocThresholds,
120 NoChunkingReason, PageRange, PageSignals, SchemaCompliance, StructuredCallMode, StructuredInput,
121 StructuredThresholds, UserChunkConfig, analyze_document, analyze_with_user_chunks,
122 boundaries_from_extraction_result, calculate_chunk_plan, calculate_plan_from_overrides, check_format_limits,
123 choose_call_mode, detect_boundaries, score_confidence,
124};
125
126#[cfg(feature = "presets")]
127pub mod presets;
128
129#[cfg(any(feature = "ocr", feature = "ocr-wasm"))]
130pub mod ocr;
131
132#[cfg(any(
133 feature = "paddle-ocr",
134 feature = "embeddings",
135 feature = "reranker",
136 feature = "onnx-runtime",
137 feature = "layout-detection",
138 feature = "auto-rotate",
139 feature = "transcription"
140))]
141pub mod ort_discovery;
142
143#[cfg(not(target_arch = "wasm32"))]
144pub(crate) mod model_download;
145
146#[cfg(any(layout_detection, auto_rotate))]
152pub(crate) mod inference;
153
154#[cfg(any(feature = "paddle-ocr", feature = "paddle-ocr-types"))]
155pub mod paddle_ocr;
156
157#[cfg(feature = "candle-ocr")]
158pub mod candle_ocr;
159
160#[cfg(feature = "auto-rotate-types")]
161pub mod doc_orientation;
162
163#[cfg(feature = "layout-types")]
164pub mod layout;
165
166#[cfg(feature = "pdf")]
167pub mod pdf;
168
169#[cfg(feature = "transcription")]
170pub mod transcription;
171
172#[cfg(feature = "captioning")]
173pub mod captioning;
174
175pub use error::{Result, XbergError};
177pub use types::*;
178
179#[cfg(feature = "office")]
181pub use extraction::office_metadata::{CoreProperties, DocxAppProperties};
182
183#[cfg(feature = "url-ingestion")]
184pub use core::extract::map_url;
185pub use core::extract::{extract, extract_batch};
186#[cfg(feature = "pdf")]
187pub use core::split::{SplitConfig, SplitSegment, SplitStrategy, split_and_extract};
188
189pub use core::config::{
190 AccelerationConfig, CallMode, CaptioningConfig, ChunkClassificationConfig, ChunkClassificationDefinition,
191 ChunkSizing, ChunkerType, ChunkingConfig, ContentFilterConfig, EmailConfig, EmbeddingConfig, EmbeddingModelType,
192 ExecutionProviderType, ExtractInput, ExtractInputKind, ExtractionConfig, ExtractionErrorItem, ExtractionResult,
193 ExtractionSummary, FileExtractionConfig, ImageExtractionConfig, JupyterCellRendering, LanguageDetectionConfig,
194 LlmConfig, MergeMode, NerBackendKind, NerConfig, OcrConfig, OutputFormat, PageClassificationConfig, PageConfig,
195 PostProcessorConfig, RedactionConfig, RedactionPattern, RedactionTerm, RerankerConfig, RerankerHead,
196 RerankerModelType, StructuredExtractionConfig, SummarizationConfig, TableChunkingMode, TokenReductionOptions,
197 TranslationConfig, UrlExtractionConfig, UrlExtractionMode,
198};
199pub use core::config::{
200 LateInteractionConfig, LateInteractionModelType, SparseEmbeddingConfig, SparseEmbeddingModelType,
201};
202#[cfg(feature = "transcription-types")]
203pub use core::config::{TranscriptionConfig, WhisperModel};
204#[cfg(any(feature = "url-ingestion", feature = "url-config-types"))]
205pub use crawlberg::{
206 AssetCategory, AuthConfig, BrowserBackend, BrowserConfig, BrowserMode, BrowserWait, ContentConfig, CrawlConfig,
207 ProxyConfig, SsrfPolicy,
208};
209#[cfg(feature = "url-ingestion")]
210pub use crawlberg::{MapResult, SitemapUrl};
211pub use extractors::security::SecurityLimits;
212
213#[cfg(feature = "presets")]
214pub use presets::{
215 LoadError, MetaSchema, Preset, PresetCategory, PresetSample, PresetSummary, Registry, ResolveError, ResolvedPreset,
216 resolve,
217};
218
219#[cfg(feature = "quality")]
220pub use text::{ReductionLevel, TokenReductionConfig};
221
222#[cfg(all(
223 feature = "ner-llm",
224 not(target_arch = "wasm32"),
225 not(all(target_os = "android", target_arch = "x86_64"))
226))]
227#[cfg_attr(alef, alef(skip))]
228pub use text::ner::llm::LlmBackend;
229
230#[cfg(feature = "ner-llm")]
231pub use text::ner::NerBackend;
232
233#[cfg(any(not(feature = "ner-llm"), all(target_os = "android", target_arch = "x86_64")))]
234#[derive(Clone, Debug)]
235#[cfg_attr(alef, alef(skip))]
236pub struct LlmBackend {
237 _config: LlmConfig,
238}
239
240#[cfg(any(not(feature = "ner-llm"), all(target_os = "android", target_arch = "x86_64")))]
241impl LlmBackend {
242 pub fn new(config: LlmConfig) -> Self {
243 Self { _config: config }
244 }
245
246 pub async fn detect(&self, _text: &str, _categories: &[crate::EntityCategory]) -> Result<Vec<crate::Entity>> {
247 Err(crate::XbergError::Other(
248 "ner-llm feature not available on this target".into(),
249 ))
250 }
251
252 pub async fn detect_with_custom(
253 &self,
254 _text: &str,
255 _categories: &[crate::EntityCategory],
256 _custom_labels: &[String],
257 ) -> Result<Vec<crate::Entity>> {
258 Err(crate::XbergError::Other(
259 "ner-llm feature not available on this target".into(),
260 ))
261 }
262}
263
264#[cfg(feature = "ner-onnx")]
265pub use text::ner::gline::GlineBackend;
266
267#[cfg(not(feature = "ner-onnx"))]
268#[derive(Clone, Debug)]
269pub struct GlineBackend {
270 pub repo_id: String,
271 pub model_path: std::path::PathBuf,
272 pub tokenizer_path: std::path::PathBuf,
273}
274
275#[cfg(not(feature = "ner-onnx"))]
276impl GlineBackend {
277 pub fn new(_repo_id: Option<&str>) -> Result<Self> {
278 Err(crate::XbergError::Other(
279 "ner-onnx feature not available on this target".into(),
280 ))
281 }
282
283 pub async fn detect(&self, _text: &str, _categories: &[crate::EntityCategory]) -> Result<Vec<crate::Entity>> {
284 Err(crate::XbergError::Other(
285 "ner-onnx feature not available on this target".into(),
286 ))
287 }
288
289 pub async fn detect_with_custom(
290 &self,
291 _text: &str,
292 _categories: &[crate::EntityCategory],
293 _custom_labels: &[String],
294 ) -> Result<Vec<crate::Entity>> {
295 Err(crate::XbergError::Other(
296 "ner-onnx feature not available on this target".into(),
297 ))
298 }
299}
300
301#[cfg(all(feature = "liter-llm", not(target_arch = "wasm32")))]
302pub use llm::region_extractor::RegionKind;
303
304#[cfg(not(all(feature = "liter-llm", not(target_arch = "wasm32"))))]
305#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
311pub enum RegionKind {
312 Figure,
314 DenseTable,
316 ComplexLayout,
318 Caption,
320}
321
322#[cfg(not(all(feature = "liter-llm", not(target_arch = "wasm32"))))]
323impl RegionKind {
324 pub fn default_prompt(self) -> &'static str {
326 ""
327 }
328}
329
330#[cfg(feature = "ner")]
331#[cfg_attr(alef, alef(skip))]
332pub use text::ner::detect_entities;
333
334#[cfg(feature = "classification")]
335#[cfg_attr(alef, alef(skip))]
336pub use text::classification::classify_document;
337
338#[cfg(feature = "redaction")]
339pub use text::redaction::strategy::TokenCounter;
340
341#[cfg(feature = "api-types")]
342pub use core::server_config::ServerConfig;
343
344#[cfg(feature = "pdf")]
345pub use core::config::{HierarchyConfig, PdfConfig};
346
347#[cfg(feature = "html")]
348pub use core::config::{HtmlOutputConfig, HtmlTheme};
349#[cfg(feature = "html")]
350pub use rendering::StyledHtmlRenderer;
351
352#[cfg(feature = "paddle-ocr-types")]
353pub use paddle_ocr::{ModelPaths, PaddleLanguage, PaddleOcrConfig};
354
355#[cfg(feature = "paddle-ocr")]
356pub use paddle_ocr::{ModelCacheStats, ModelManager, ModelManifestEntry, PaddleOcrBackend};
357
358pub use cache::CacheStats;
359
360#[cfg(feature = "layout-types")]
361pub use core::config::{LayoutDetectionConfig, LayoutStrategy, TableModel};
362
363#[cfg(feature = "layout-types")]
364pub use layout::types::{BBox, DetectionResult, LayoutClass, LayoutDetection};
365
366#[cfg(feature = "layout-types")]
367pub use layout::types::RecognizedTable;
368#[cfg(any(feature = "ocr", feature = "ocr-wasm"))]
369pub use ocr::types::PSMMode;
370
371pub use core::config::{OcrPipelineConfig, OcrPipelineStage, OcrQualityThresholds, OcrStrategy, VlmFallbackPolicy};
372
373#[cfg(feature = "auto-rotate-types")]
374pub use doc_orientation::OrientationResult;
375
376#[cfg(any(feature = "keywords-yake", feature = "keywords-rake"))]
377pub use keywords::{Keyword, KeywordAlgorithm, KeywordConfig};
378
379#[cfg(feature = "keywords-rake")]
380pub use keywords::RakeParams;
381
382#[cfg(feature = "keywords-yake")]
383pub use keywords::YakeParams;
384
385#[cfg(feature = "markdown-footnotes")]
386pub use text::markdown_footnotes::{
387 Citation, FootnoteAnchor, FootnoteConfig, FootnoteDefinition, find_footnote_anchors, find_inference_markers,
388 find_unmarked_claims, parse_citations, parse_footnote_definitions, verify_excerpt,
389};
390
391#[cfg(feature = "diff")]
392pub use diff::{DiffHunk, DiffOptions, EmbeddedChanges, EmbeddedDiff, ExtractionDiff, TableDiff, compare};
393
394#[cfg(feature = "tree-sitter")]
395pub use core::config::{CodeContentMode, TreeSitterConfig, TreeSitterProcessConfig};
396#[cfg(feature = "tree-sitter")]
397pub use tree_sitter_language_pack::{
398 ChunkContext, CodeChunk, CommentInfo, CommentKind, Diagnostic, DiagnosticSeverity, DocstringFormat, DocstringInfo,
399 ExportInfo, ExportKind, FileMetrics, ImportInfo, ProcessConfig, ProcessResult, Span, StructureItem, StructureKind,
400 SymbolInfo, SymbolKind, process as process_code,
401};
402
403pub use core::mime::{SupportedFormat, detect_mime_type_from_bytes, get_extensions_for_mime, list_supported_formats};
404
405pub fn detect_mime_type(path: String, check_exists: bool) -> crate::Result<String> {
410 core::mime::detect_mime_type(path, check_exists)
411}
412
413#[cfg(feature = "pdf")]
414pub use pdf::render::{pdf_page_count, render_pdf_page_to_png};
415
416#[cfg_attr(alef, alef(skip))]
417pub use plugins::{
418 clear_document_extractors, clear_embedding_backends, clear_ocr_backends, clear_post_processors, clear_renderers,
419 clear_reranker_backends, clear_tokenizer_backends, clear_validators, list_document_extractors,
420 list_embedding_backends, list_ocr_backends, list_post_processors, list_renderers, list_reranker_backends,
421 list_tokenizer_backends, list_validators, register_document_extractor, register_embedding_backend,
422 register_ocr_backend, register_post_processor, register_renderer, register_reranker_backend,
423 register_tokenizer_backend, register_validator, unregister_document_extractor, unregister_embedding_backend,
424 unregister_ocr_backend, unregister_post_processor, unregister_renderer, unregister_reranker_backend,
425 unregister_tokenizer_backend, unregister_validator,
426};
427
428#[cfg_attr(alef, alef(skip))]
429pub use plugins::{
430 DocumentExtractor, EmbeddingBackend, OcrBackend, OcrBackendType, PostProcessor, ProcessingStage, Renderer,
431 RerankerBackend, TokenizerBackend, Validator,
432};
433
434#[cfg(feature = "embedding-presets")]
435pub use embeddings::EmbeddingPreset;
436
437#[cfg(any(feature = "embeddings", feature = "static-embeddings"))]
441#[cfg_attr(alef, alef(skip))]
442pub fn embed_texts(texts: Vec<String>, config: &core::config::EmbeddingConfig) -> crate::Result<Vec<Vec<f32>>> {
443 embeddings::embed_texts(&texts, config)
444}
445
446#[cfg(all(
450 feature = "embedding-presets",
451 not(feature = "embeddings"),
452 not(feature = "static-embeddings")
453))]
454#[cfg_attr(alef, alef(skip))]
455pub fn embed_texts(_texts: Vec<String>, _config: &core::config::EmbeddingConfig) -> crate::Result<Vec<Vec<f32>>> {
456 Err(XbergError::validation(
457 "embed_texts requires the `embeddings` (ONNX Runtime) or `static-embeddings` (pure-Rust) feature; \
458 neither is enabled on this build",
459 ))
460}
461
462#[cfg(all(
463 feature = "tokio-runtime",
464 any(feature = "embeddings", feature = "static-embeddings")
465))]
466#[cfg_attr(alef, alef(skip))]
467pub use embeddings::embed_texts_async;
468
469#[cfg(all(
470 feature = "embedding-presets",
471 not(feature = "embeddings"),
472 not(feature = "static-embeddings"),
473 feature = "tokio-runtime"
474))]
475#[cfg_attr(alef, alef(skip))]
476pub async fn embed_texts_async(
477 _texts: Vec<String>,
478 _config: &core::config::EmbeddingConfig,
479) -> crate::Result<Vec<Vec<f32>>> {
480 Err(XbergError::validation(
481 "embed_texts_async requires the `embeddings` (ONNX Runtime) or `static-embeddings` (pure-Rust) feature; \
482 neither is enabled on this build",
483 ))
484}
485
486#[cfg(feature = "embedding-presets")]
491#[cfg_attr(alef, alef(skip))]
492pub fn get_embedding_preset(name: &str) -> Option<embeddings::EmbeddingPreset> {
493 embeddings::get_preset(name)
494}
495
496#[cfg(feature = "embedding-presets")]
500#[cfg_attr(alef, alef(skip))]
501pub fn list_embedding_presets() -> Vec<String> {
502 embeddings::list_presets()
503}
504
505#[cfg(feature = "embedding-presets")]
510#[cfg_attr(alef, alef(skip))]
511pub fn embedding_query_prefix(config: &EmbeddingConfig) -> Option<String> {
512 embeddings::embedding_query_prefix(config)
513}
514
515#[cfg(not(feature = "embedding-presets"))]
522#[cfg_attr(alef, alef(skip))]
523#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
524pub struct EmbeddingPreset {
525 pub name: String,
527 pub chunk_size: usize,
529 pub overlap: usize,
531 pub model_repo: String,
533 pub pooling: String,
535 pub model_file: String,
537 pub dimensions: usize,
539 pub description: String,
541}
542
543#[cfg(not(feature = "embedding-presets"))]
545#[cfg_attr(alef, alef(skip))]
546pub fn get_embedding_preset(_name: &str) -> Option<EmbeddingPreset> {
547 None
548}
549
550#[cfg(not(feature = "embedding-presets"))]
552#[cfg_attr(alef, alef(skip))]
553pub fn list_embedding_presets() -> Vec<String> {
554 Vec::new()
555}
556
557#[cfg(feature = "reranker-presets")]
561pub use reranking::RerankerPreset;
562
563#[cfg(any(feature = "reranker-presets", feature = "reranker"))]
567pub use reranking::RerankedDocument;
568
569#[cfg(feature = "reranker")]
582#[cfg_attr(alef, alef(skip))]
583pub fn rerank(
584 query: String,
585 documents: Vec<String>,
586 config: &core::config::RerankerConfig,
587) -> crate::Result<Vec<reranking::RerankedDocument>> {
588 reranking::rerank(query, documents, config)
589}
590
591#[cfg(all(feature = "reranker-presets", not(feature = "reranker")))]
596#[cfg_attr(alef, alef(skip))]
597pub fn rerank(
598 _query: String,
599 _documents: Vec<String>,
600 _config: &core::config::RerankerConfig,
601) -> crate::Result<Vec<reranking::RerankedDocument>> {
602 Err(XbergError::validation(
603 "rerank requires the `reranker` feature, which depends on ONNX Runtime; \
604 not available on this target (Android x86_64 emulator or WASM)",
605 ))
606}
607
608#[cfg(all(feature = "reranker", feature = "tokio-runtime"))]
609#[cfg_attr(alef, alef(skip))]
610pub use reranking::rerank_async;
611
612#[doc(alias = "rerank")]
616#[cfg(all(feature = "reranker-presets", not(feature = "reranker"), feature = "tokio-runtime"))]
617#[cfg_attr(alef, alef(skip))]
618pub async fn rerank_async(
619 _query: String,
620 _documents: Vec<String>,
621 _config: &core::config::RerankerConfig,
622) -> crate::Result<Vec<reranking::RerankedDocument>> {
623 Err(XbergError::validation(
624 "rerank_async requires the `reranker` feature, which depends on ONNX Runtime; \
625 not available on this target (Android x86_64 emulator or WASM)",
626 ))
627}
628
629#[cfg(feature = "reranker-presets")]
636#[cfg_attr(alef, alef(skip))]
637pub fn get_reranker_preset(name: &str) -> Option<reranking::RerankerPreset> {
638 reranking::get_preset(name)
639}
640
641#[cfg(feature = "reranker-presets")]
647#[cfg_attr(alef, alef(skip))]
648pub fn list_reranker_presets() -> Vec<String> {
649 reranking::list_presets()
650}
651
652#[cfg(not(feature = "reranker-presets"))]
660#[cfg_attr(alef, alef(skip))]
661#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
662pub struct RerankerPreset {
663 pub name: String,
665 pub model_repo: String,
667 pub model_file: String,
669 pub max_length: usize,
671 pub description: String,
673}
674
675#[cfg(not(feature = "reranker-presets"))]
679#[cfg_attr(alef, alef(skip))]
680#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
681#[cfg_attr(feature = "api", derive(utoipa::ToSchema))]
682pub struct RerankedDocument {
683 pub index: usize,
685 pub score: f32,
687 pub document: String,
689}
690
691#[cfg(not(feature = "reranker-presets"))]
695#[cfg_attr(alef, alef(skip))]
696pub fn get_reranker_preset(_name: &str) -> Option<RerankerPreset> {
697 None
698}
699
700#[cfg(not(feature = "reranker-presets"))]
704#[cfg_attr(alef, alef(skip))]
705pub fn list_reranker_presets() -> Vec<String> {
706 Vec::new()
707}
708
709#[cfg(feature = "sparse-embedding-presets")]
714pub use sparse_embeddings::{SparseEmbedding, SparseEmbeddingPreset};
715
716#[cfg(feature = "sparse-embeddings")]
722#[cfg_attr(alef, alef(skip))]
723pub fn embed_sparse(
724 texts: Vec<String>,
725 config: &core::config::SparseEmbeddingConfig,
726) -> crate::Result<Vec<SparseEmbedding>> {
727 sparse_embeddings::embed_sparse(&texts, config)
728}
729
730#[cfg(all(feature = "sparse-embedding-presets", not(feature = "sparse-embeddings")))]
736#[cfg_attr(alef, alef(skip))]
737pub fn embed_sparse(
738 _texts: Vec<String>,
739 _config: &core::config::SparseEmbeddingConfig,
740) -> crate::Result<Vec<SparseEmbedding>> {
741 Err(XbergError::validation(
742 "embed_sparse requires the `sparse-embeddings` feature, which depends on ONNX Runtime; \
743 not available on this target (Android x86_64 emulator or WASM)",
744 ))
745}
746
747#[cfg(all(feature = "sparse-embeddings", feature = "tokio-runtime"))]
748#[cfg_attr(alef, alef(skip))]
749pub use sparse_embeddings::embed_sparse_async;
750
751#[cfg(all(
755 feature = "sparse-embedding-presets",
756 not(feature = "sparse-embeddings"),
757 feature = "tokio-runtime"
758))]
759#[cfg_attr(alef, alef(skip))]
760pub async fn embed_sparse_async(
761 _texts: Vec<String>,
762 _config: &core::config::SparseEmbeddingConfig,
763) -> crate::Result<Vec<SparseEmbedding>> {
764 Err(XbergError::validation(
765 "embed_sparse_async requires the `sparse-embeddings` feature, which depends on ONNX Runtime; \
766 not available on this target (Android x86_64 emulator or WASM)",
767 ))
768}
769
770#[cfg(feature = "sparse-embedding-presets")]
774#[cfg_attr(alef, alef(skip))]
775pub fn get_sparse_embedding_preset(name: &str) -> Option<sparse_embeddings::SparseEmbeddingPreset> {
776 sparse_embeddings::get_preset(name)
777}
778
779#[cfg(feature = "sparse-embedding-presets")]
783#[cfg_attr(alef, alef(skip))]
784pub fn list_sparse_embedding_presets() -> Vec<String> {
785 sparse_embeddings::list_presets()
786}
787
788#[cfg(not(feature = "sparse-embedding-presets"))]
794#[cfg_attr(alef, alef(skip))]
795#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
796#[cfg_attr(feature = "api", derive(utoipa::ToSchema))]
797pub struct SparseEmbedding {
798 pub indices: Vec<u32>,
800 pub values: Vec<f32>,
802}
803
804#[cfg(not(feature = "sparse-embedding-presets"))]
808#[cfg_attr(alef, alef(skip))]
809#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
810pub struct SparseEmbeddingPreset {
811 pub name: String,
813 pub model_repo: String,
815 pub model_file: String,
817 pub additional_files: Vec<String>,
819 pub max_length: usize,
821 pub description: String,
823}
824
825#[cfg(not(feature = "sparse-embedding-presets"))]
829#[cfg_attr(alef, alef(skip))]
830pub fn get_sparse_embedding_preset(_name: &str) -> Option<SparseEmbeddingPreset> {
831 None
832}
833
834#[cfg(not(feature = "sparse-embedding-presets"))]
838#[cfg_attr(alef, alef(skip))]
839pub fn list_sparse_embedding_presets() -> Vec<String> {
840 Vec::new()
841}
842
843#[cfg(feature = "late-interaction-presets")]
848pub use late_interaction::{
849 LateInteractionMatch, LateInteractionPreset, MultiVectorEmbedding, max_sim_rank, max_sim_score,
850};
851
852#[cfg(feature = "late-interaction")]
859#[cfg_attr(alef, alef(skip))]
860pub fn embed_multi_vector(
861 texts: Vec<String>,
862 config: &core::config::LateInteractionConfig,
863 is_query: bool,
864) -> crate::Result<Vec<MultiVectorEmbedding>> {
865 late_interaction::embed_multi_vector(&texts, config, is_query)
866}
867
868#[cfg(all(feature = "late-interaction-presets", not(feature = "late-interaction")))]
873#[cfg_attr(alef, alef(skip))]
874pub fn embed_multi_vector(
875 _texts: Vec<String>,
876 _config: &core::config::LateInteractionConfig,
877 _is_query: bool,
878) -> crate::Result<Vec<MultiVectorEmbedding>> {
879 Err(XbergError::validation(
880 "embed_multi_vector requires the `late-interaction` feature, which depends on ONNX Runtime; \
881 not available on this target (Android x86_64 emulator or WASM)",
882 ))
883}
884
885#[cfg(all(feature = "late-interaction", feature = "tokio-runtime"))]
886#[cfg_attr(alef, alef(skip))]
887pub use late_interaction::embed_multi_vector_async;
888
889#[cfg(all(
893 feature = "late-interaction-presets",
894 not(feature = "late-interaction"),
895 feature = "tokio-runtime"
896))]
897#[cfg_attr(alef, alef(skip))]
898pub async fn embed_multi_vector_async(
899 _texts: Vec<String>,
900 _config: &core::config::LateInteractionConfig,
901 _is_query: bool,
902) -> crate::Result<Vec<MultiVectorEmbedding>> {
903 Err(XbergError::validation(
904 "embed_multi_vector_async requires the `late-interaction` feature, which depends on ONNX Runtime; \
905 not available on this target (Android x86_64 emulator or WASM)",
906 ))
907}
908
909#[cfg(feature = "late-interaction-presets")]
913#[cfg_attr(alef, alef(skip))]
914pub fn get_late_interaction_preset(name: &str) -> Option<late_interaction::LateInteractionPreset> {
915 late_interaction::get_preset(name)
916}
917
918#[cfg(feature = "late-interaction-presets")]
922#[cfg_attr(alef, alef(skip))]
923pub fn list_late_interaction_presets() -> Vec<String> {
924 late_interaction::list_presets()
925}
926
927#[cfg(not(feature = "late-interaction-presets"))]
931#[cfg_attr(alef, alef(skip))]
932#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
933#[cfg_attr(feature = "api", derive(utoipa::ToSchema))]
934pub struct MultiVectorEmbedding {
935 pub num_tokens: u32,
937 pub dim: u32,
939 pub data: Vec<f32>,
941}
942
943#[cfg(not(feature = "late-interaction-presets"))]
947#[cfg_attr(alef, alef(skip))]
948#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
949#[cfg_attr(feature = "api", derive(utoipa::ToSchema))]
950pub struct LateInteractionMatch {
951 pub index: usize,
953 pub score: f32,
955}
956
957#[cfg(not(feature = "late-interaction-presets"))]
961#[cfg_attr(alef, alef(skip))]
962#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
963pub struct LateInteractionPreset {
964 pub name: String,
966 pub model_repo: String,
968 pub model_file: String,
970 pub additional_files: Vec<String>,
972 pub max_length: usize,
974 pub query_max_length: usize,
976 pub dim: usize,
978 pub description: String,
980}
981
982#[cfg(not(feature = "late-interaction-presets"))]
986#[cfg_attr(alef, alef(skip))]
987pub fn get_late_interaction_preset(_name: &str) -> Option<LateInteractionPreset> {
988 None
989}
990
991#[cfg(not(feature = "late-interaction-presets"))]
995#[cfg_attr(alef, alef(skip))]
996pub fn list_late_interaction_presets() -> Vec<String> {
997 Vec::new()
998}
999
1000#[cfg(all(feature = "captioning", feature = "tokio-runtime"))]
1035#[cfg_attr(alef, alef(skip))]
1036pub use captioning::caption_image;
1037
1038#[cfg(all(feature = "captioning", feature = "tokio-runtime"))]
1072#[cfg_attr(alef, alef(skip))]
1073pub use captioning::caption_image_file;
1074
1075#[cfg(all(feature = "captioning", feature = "tokio-runtime"))]
1116#[cfg_attr(alef, alef(skip))]
1117pub use captioning::caption_images;
1118
1119pub mod enrich;
1122#[cfg_attr(alef, alef(skip))]
1123pub use enrich::enrich;
1124pub use enrich::{EnrichedResult, EnrichmentConfig};
1125
1126#[cfg(feature = "ner")]
1127pub use enrich::NerEnrichmentConfig;
1128
1129#[cfg(feature = "classification")]
1130pub use enrich::ClassificationEnrichmentConfig;
1131
1132#[cfg(feature = "captioning")]
1133pub use enrich::CaptioningEnrichmentConfig;