Skip to content

Frequency Moments Beyond Equality: Streaming Cosine Density Moments

Qin Zhang

cs.DS

Abstract

For a stream of nonzero vectors x1,…,xn∈Rdx_1,\ldots,x_n\in\mathbb{R}^d, let ui=xi/∥xi∥2u_i=x_i/\|x_i\|_2. We define the cosine density of the ii-th stream element by Di:=∑j∈[n]⟨ui,uj⟩D_i:=\sum_{j\in[n]}\langle u_i,u_j\rangle and study the density moments Mp:=∑i∈[n]DipM_p:=\sum_{i\in[n]}D_i^p in both the signed- and nonnegative-cosine regimes. These quantities are similarity-aware analogues of classical frequency moments: replacing cosine similarity by equality (that is, Di=∑j∈[n]1{uj=ui}D_i = \sum_{j\in[n]} \mathbf{1}\{u_j = u_i\}) gives Mp=Fp+1M_p=F_{p+1} and, in particular, M−1=F0M_{-1}=F_0, the number of distinct elements. We give one-pass streaming algorithms and lower bounds whose dependence on dd is tight up to logarithmic factors for p=−1p=-1, p=1p=1, and even p≥2p \ge 2 (the latter under signed cosine), and whose exponents differ by less than 1/21/2 for odd p≥3p \ge 3 under nonnegative cosine. Our results thus extend several fundamental statistics from the classical data stream literature to cosine similarity, a widely used measure for comparing vector embeddings in modern AI systems. The main challenge in proving a space lower bound for nonnegative cosine is to eliminate unwanted contributions without relying on pairs of opposite vectors. We address this through a construction that we call \emph{equal-sum moment isolation}: two insertion-only prefixes have the same cardinality and vector sum, and a finite-difference comparison cancels the baseline shared by all their vectors while isolating the desired higher-order signal. This proof framework may be useful for other insertion-only streaming lower bounds, where direct cancellation is not possible.

Create a lesson

Metadata

Comments
44 pages