-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add local embedding and other services
- Loading branch information
1 parent
d89ab0f
commit 0042b93
Showing
7 changed files
with
113 additions
and
26 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,12 +1,28 @@ | ||
# get_transformer_model <- function(model_name = "jinaai/jina-embeddings-v2-base-en") { | ||
# py_pkg_is_available() | ||
# transformer <- reticulate::import("sentence_transformers") | ||
# cli::cli_process_start("Downloading model. This may take a few minutes.") | ||
# model <- transformer$SentenceTransformer(model_name) | ||
# cli::cli_process_done() | ||
# model | ||
# } | ||
|
||
# uses transformers instead of sentence transformers | ||
get_transformer_model <- function(model_name = "jinaai/jina-embeddings-v2-base-en") { | ||
py_pkg_is_available() | ||
transformer <- reticulate::import("sentence_transformers") | ||
py_pkg_is_available("transformers") | ||
transformer <- reticulate::import("transformers") | ||
cli::cli_process_start("Downloading model. This may take a few minutes.") | ||
model <- transformer$SentenceTransformer(model_name) | ||
model <- transformer$AutoModel$from_pretrained(model_name, | ||
trust_remote_code = TRUE | ||
) | ||
cli::cli_process_done() | ||
model | ||
} | ||
|
||
|
||
create_text_embeddings <- function(text, model) { | ||
model$encode(text) |> as.numeric() | ||
tibble::tibble( | ||
usage = "local", | ||
embedding = model$encode(text) |> as.numeric() |> list() | ||
) | ||
} |
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
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