flowchart LR A[Large corpus] --> B[Deterministic preprocessing] B --> C[Backend-neutral embedding] C --> D[Reproducible storage] D --> E[Distance and classification] E --> F[Threshold calibration] F --> G[Operational decisions]
This vignette provides a full package-level overview of openalexVectorComp:
It is intended as the orientation document before using the technical vignettes.
The package follows five core principles:
id + text_hash to skip unchanged rows safely.flowchart LR A[Large corpus] --> B[Deterministic preprocessing] B --> C[Backend-neutral embedding] C --> D[Reproducible storage] D --> E[Distance and classification] E --> F[Threshold calibration] F --> G[Operational decisions]
The package API is organized into these groups.
backend_config()backend_info()backend_embed_texts()backend_read()backend_save()embed_texts()These functions isolate provider-specific details and expose a stable interface.
embed_corpus()This is the main batch pipeline driver for production embedding runs.
clean_abstract_for_embedding()Default implementation for title/abstract cleaning and canonical text creation.
similarity_cosine()distance_cosine()distance_reference_cosine()score_reference_cosine()These functions quantify embedding-space relevance from geometric perspectives.
Internal helper note:
distances() exists as a non-exported helper for joining distance datasets.fit_ridge()distance_ridge()score_ridge()calibrate_threshold()These functions produce calibrated decision-ready scores.
plot_embeddings_pca()plot_embeddings_umap()These functions support diagnostics and qualitative checks.
flowchart TB A[Backend Abstraction] --> B[embed_corpus] C[Text Preparation] --> B B --> D[Stored embeddings] D --> E[Similarity and distance] D --> F[Ridge scoring] E --> G[Threshold calibration] F --> G D --> H[PCA/UMAP diagnostics]
Typical workflow for one project:
backend_config()).embed_corpus()).distance_reference_cosine() and/or distance_ridge()), then score (e.g. score_reference_cosine(), score_ridge()).calibrate_threshold()).plot_embeddings_pca() / plot_embeddings_umap()).sequenceDiagram participant U as User participant BC as backend_config participant EC as embed_corpus participant ES as embedding_store participant DP as distance_reference_cosine participant SCP as score_reference_cosine participant DR as distance_ridge participant SR as score_ridge participant CT as calibrate_threshold U->>BC: backend_config(...) U->>EC: embed_corpus(project_dir, backend) EC->>ES: write embeddings parquet U->>DP: distance_reference_cosine(...) U->>SCP: score_reference_cosine(...) U->>DR: distance_ridge(...) U->>SR: score_ridge(...) U->>CT: calibrate_threshold(...)
embed_corpus() expects:
project_dir/corpus as Arrow datasetid, title, abstractEmbeddings are written under:
project_dir/embeddings/model_id=<model>/label=<label>/batch=*/embeddings-*.parquetproject_dir/embeddings/model_id=<model>/embed_model.yamlWhen dry_run = TRUE, no embeddings are written. Instead:
project_dir/<corpus_name>_dryrun.parquetThis file supports auditing preprocessing behavior (including custom cleaners).
flowchart TB A[project_dir/corpus] --> B[embed_corpus] B --> C[model_id=.../embed_model.yaml] B --> D[model_id=.../label=.../batch=*/embeddings-*.parquet] B --> E[<corpus_name>_dryrun.parquet]
embed_corpus() accepts:
text_preprocessor (function)cleaner_args (named list)The preprocessor must return a data frame with:
idtexttext_hashOptional columns are preserved and can be persisted (e.g., quality flags).
The package supports two complementary relevance styles:
distance_ridge + score_ridge)
area_distance)relevance_score.Use one or both, then calibrate threshold for target operating behavior.
flowchart LR A[Embeddings] --> B[Prototype distance] A --> C[Reference-area score] B --> D[Ranked candidates] C --> D D --> E[calibrate_threshold] E --> F[Precision/recall operating point]
library(openalexVectorComp)
backend <- backend_config(
provider = "hf",
model = "BAAI/bge-small-en-v1.5",
max_batch_size = 64
)
model_dir <- embed_corpus(
project_dir = "my_project",
backend = backend,
batch_size = 5000,
delete_existing = FALSE,
label = "corpus",
save_text = TRUE
)
embed_corpus(
project_dir = "my_project",
backend = backend,
batch_size = 5000,
delete_existing = FALSE,
label = "reference",
save_text = TRUE
)
pairwise_dir <- distance_reference_cosine(
project_dir = "my_project",
embeddings_dir = basename(model_dir),
corpus_label = "corpus",
reference_label = "reference"
)
pairwise_score_dir <- score_reference_cosine(
distance_parquet = pairwise_dir,
method = "linear"
)
# Optional supervised scoring path
scores_dir <- distance_ridge(
project_dir = "my_project",
reference_label = "reference",
corpus_label = "corpus"
)
scores_dir <- score_ridge(scores_dir)
best <- calibrate_threshold(
scores_parquet = scores_dir,
score_col = "relevance_score",
labels_parquet = "labels.parquet"
)save_text = TRUE in alpha/review phases for auditability.dry_run = TRUE to validate custom cleaners before API spend.mode = "balanced" in clean_abstract_for_embedding() unless you have measured reasons to go stricter.backend-architecture: provider/dispatch implementation details.abstract-cleaning: cleaning rules and examples in depth.tei-server-operations: local TEI operational handling.simplestart: quick start usage path.openalexVectorComp is a composable embedding-and-scoring pipeline package:
Use this overview as the map, then dive into the specialized vignettes for implementation-level details.