Skip to content

Commit

Permalink
feat(uni): init for embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 14, 2023
1 parent 50b2ce1 commit ab4355e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
14 changes: 12 additions & 2 deletions inference_core/src/embedding/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,19 @@ impl Drop for Semantic {
}
}

pub fn init_semantic(model: Vec<u8>, tokenizer_data: Vec<u8>) -> Result<Arc<Semantic>, SemanticError> {
let result = Semantic::init_semantic(model, tokenizer_data)?;
Ok(Arc::new(result))
}

impl Semantic {
pub async fn initialize(model: Vec<u8>, tokenizer_data: Vec<u8>) -> Result<Pin<Box<Semantic>>, SemanticError> {
let semantic = Self::init_semantic(model, tokenizer_data)?;

Ok(Box::pin(semantic))
}

pub fn init_semantic(model: Vec<u8>, tokenizer_data: Vec<u8>) -> Result<Semantic, SemanticError> {
let environment = Arc::new(
Environment::builder()
.with_name("Encode")
Expand Down Expand Up @@ -53,8 +64,7 @@ impl Semantic {
.unwrap()
.into(),
};

Ok(Box::pin(semantic))
Ok(semantic)
}

pub fn embed(&self, sequence: &str) -> Result<Embedding, SemanticError> {
Expand Down
5 changes: 4 additions & 1 deletion inference_core/src/inference.udl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace inference { };
namespace inference {
[Throws=SemanticError]
Semantic init_semantic(sequence<u8> model, sequence<u8> tokenizer_data);
};

[Custom]
typedef sequence<f32> Embedding;
Expand Down
2 changes: 1 addition & 1 deletion inference_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use document::Metadata;
pub use embedding::Embedding;
pub use embedding::Semantic;
pub use embedding::semantic::SemanticError;
// pub use embedding::semantic::init_semantic;
pub use embedding::semantic::init_semantic;

pub use similarity::EmbeddingMatch;
pub use similarity::CosineSimilarity;
Expand Down

0 comments on commit ab4355e

Please sign in to comment.