oxirs_vec/embeddings/
tfidfembeddinggenerator_traits.rs1use crate::Vector;
13use anyhow::{anyhow, Result};
14
15use super::functions::{AsAny, EmbeddingGenerator};
16use super::types::{EmbeddableContent, EmbeddingConfig, TfIdfEmbeddingGenerator};
17
18impl EmbeddingGenerator for TfIdfEmbeddingGenerator {
19 fn generate(&self, content: &EmbeddableContent) -> Result<Vector> {
20 if self.vocabulary.is_empty() {
21 return Err(anyhow!(
22 "Vocabulary not built. Call build_vocabulary first."
23 ));
24 }
25 let text = content.to_text();
26 Ok(self.calculate_tf_idf(&text))
27 }
28 fn dimensions(&self) -> usize {
29 self.config.dimensions
30 }
31 fn config(&self) -> &EmbeddingConfig {
32 &self.config
33 }
34}
35
36impl AsAny for TfIdfEmbeddingGenerator {
37 fn as_any(&self) -> &dyn std::any::Any {
38 self
39 }
40 fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
41 self
42 }
43}