% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/semantic_analysis.R
\name{calculate_cross_similarity}
\alias{calculate_cross_similarity}
\title{Calculate Cross-Matrix Cosine Similarity}
\usage{
calculate_cross_similarity(
  embeddings1,
  embeddings2,
  labels1 = NULL,
  labels2 = NULL,
  normalize = TRUE
)
}
\arguments{
\item{embeddings1}{A numeric matrix where rows are items and columns are embedding dimensions.}

\item{embeddings2}{A numeric matrix where rows are items and columns are embedding dimensions.
Must have the same number of columns as embeddings1.}

\item{labels1}{Optional character vector of labels for items in embeddings1.}

\item{labels2}{Optional character vector of labels for items in embeddings2.}

\item{normalize}{Logical, whether to L2-normalize embeddings before computing similarity (default: TRUE).}
}
\value{
A list containing:
\item{similarity_matrix}{Matrix of cosine similarities (nrow(embeddings1) x nrow(embeddings2))}
\item{similarity_df}{Long-format data frame with columns: row_idx, col_idx, similarity, and optionally label1, label2}
}
\description{
Calculates cosine similarity between two different embedding matrices,
useful for comparing documents/topics across different categories or groups.
}
\examples{
\donttest{
abstracts <- TextAnalysisR::SpecialEduTech$abstract[1:6]
term_matrix <- as.matrix(quanteda::dfm(quanteda::tokens(abstracts)))
similarity_result <- calculate_cross_similarity(
  term_matrix[1:3, ], term_matrix[4:6, ],
  labels1 = paste("Doc", 1:3),
  labels2 = paste("Doc", 4:6)
)
similarity_result$similarity_matrix
}
}
\concept{semantic}
