-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update file_processor/mod.rs, file_processor/pdf_processor.rs, Cargo.…
…toml, test.py, examples/web_embed.rs, and embedding_model/jina.rs
- Loading branch information
1 parent
f6340f0
commit ae429b8
Showing
14 changed files
with
833 additions
and
70 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use embed_anything::file_processor::website_processor; | ||
use candle_core::Tensor; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let url = "https://en.wikipedia.org/wiki/Long_short-term_memory"; | ||
|
||
let website_processor = website_processor::WebsiteProcesor; | ||
let webpage = website_processor.process_website(url).await.unwrap(); | ||
let embeder = embed_anything::embedding_model::bert::BertEmbeder::default(); | ||
let embed_data = webpage.embed_webpage(&embeder).await.unwrap(); | ||
let embeddings: Vec<Vec<f32>> = embed_data.iter().map(|data| data.embedding.clone()).collect(); | ||
|
||
let embeddings = Tensor::from_vec( | ||
embeddings.iter().flatten().cloned().collect::<Vec<f32>>(), | ||
(embeddings.len(), embeddings[0].len()), | ||
&candle_core::Device::Cpu, | ||
).unwrap(); | ||
|
||
let query = vec!["how to use lstm for nlp".to_string()]; | ||
let query_embedding: Vec<f32> = embeder.embed(&query, None).await.unwrap().iter().map(|data| data.embedding.clone()).flatten().collect(); | ||
|
||
let query_embedding_tensor = Tensor::from_vec( | ||
query_embedding.clone(), | ||
(1, query_embedding.len()), | ||
&candle_core::Device::Cpu, | ||
).unwrap(); | ||
|
||
|
||
let similarities = embeddings | ||
.matmul(&query_embedding_tensor.transpose(0, 1).unwrap()) | ||
.unwrap() | ||
.detach() | ||
.squeeze(1) | ||
.unwrap() | ||
.to_vec1::<f32>() | ||
.unwrap(); | ||
|
||
let max_similarity_index = similarities.iter().enumerate().max_by(|a, b| a.1.partial_cmp(b.1).unwrap()).unwrap().0; | ||
let data = &embed_data[max_similarity_index]; | ||
|
||
println!("{:?}", data); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.