sfa_embed: Embed Item Text with a Language Model

View source: R/embed.R

sfa_embedR Documentation

Embed Item Text with a Language Model

Description

Computes embeddings for a vector of item text using a sentence-transformer or other embedding backend.

Usage

sfa_embed(items, embed = "sbert", model = NULL, cache = TRUE, ...)

Arguments

items

Character vector of item text, or a data frame with an item/text column (and optionally a code column, used as rownames so short codes flow through to plots such as sfa_corplot).

embed

Embedding backend: "sbert" (default, via reticulate), "openai" (via httr2), or a function taking a character vector and returning a numeric matrix.

model

Model name passed to the backend. If NULL (default), a backend-appropriate default is used: "Qwen/Qwen3-Embedding-0.6B" for "sbert" and "text-embedding-3-small" for "openai". Larger embedding models recover factor structure more accurately; see sfa.

cache

Logical: cache embeddings in tools::R_user_dir("semanticfa", "cache")? Default TRUE.

...

Additional arguments passed to the embedding backend function.

Value

A numeric matrix (n_items x embedding_dim). Rownames are the item codes when items is a data frame with a code column, otherwise the item text.


semanticfa documentation built on Sept. 2, 2026, 1:07 a.m.