run-llama/llama_index · error · ValueError
No embeddings to aggregate
Error message
No embeddings to aggregate
What it means
Raised by mean_agg when it is called with an empty list of embeddings. Mean aggregation over zero vectors is undefined, so the function fails fast instead of returning NaN or a zero vector. This helper backs similarity averaging in BaseEmbedding.
Source
Thrown at llama-index-core/llama_index/core/base/embeddings/base.py:50
EmbeddingStartEvent,
)
import llama_index.core.instrumentation as instrument
dispatcher = instrument.get_dispatcher(__name__)
class SimilarityMode(str, Enum):
"""Modes for similarity/distance."""
DEFAULT = "cosine"
DOT_PRODUCT = "dot_product"
EUCLIDEAN = "euclidean"
def mean_agg(embeddings: List[Embedding]) -> Embedding:
"""Mean aggregation for embeddings."""
if not embeddings:
raise ValueError("No embeddings to aggregate")
return np.array(embeddings).mean(axis=0).tolist()
def similarity(
embedding1: Embedding,
embedding2: Embedding,
mode: SimilarityMode = SimilarityMode.DEFAULT,
) -> float:
"""Get embedding similarity."""
if mode == SimilarityMode.EUCLIDEAN:
# Using -euclidean distance as similarity to achieve same ranking order
return -float(np.linalg.norm(np.array(embedding1) - np.array(embedding2)))
elif mode == SimilarityMode.DOT_PRODUCT:
return np.dot(embedding1, embedding2)
else:
product = np.dot(embedding1, embedding2)
norm = np.linalg.norm(embedding1) * np.linalg.norm(embedding2)View on GitHub (pinned to afd0fef371)
Solutions
- Skip aggregation when the embedding list is empty: `if embeddings: ... else: continue`.
- Fix upstream node construction so empty-text nodes are dropped (e.g. filter nodes with not node.get_content().strip()).
- If an empty aggregate must exist for your schema, decide an explicit policy (skip node, or raise a clearer domain error) rather than relying on this generic one.
Example fix
# before
emb = mean_agg(get_text_embeddings_for_node_batch(node_batch))
# after
embs = get_text_embeddings_for_node_batch(node_batch)
if embs:
emb = mean_agg(embs)
else:
node_batch = [n for n in node_batch if n.get_content().strip()] Defensive patterns
Strategy: validation
Validate before calling
texts = [t for t in texts if t and t.strip()]
if not texts:
return # nothing to aggregate Type guard
def has_embeddings(embs: list) -> bool:
return len(embs) > 0 Try / catch
try:
agg = mean_agg(embs)
except ValueError:
logger.warning("empty embedding batch, skipping node") Prevention
- Filter empty/whitespace text before embedding.
- Drop empty nodes at node-parser time rather than at aggregation time.
When it happens
Trigger: Aggregating embeddings for a node whose text is empty, or calling get_text_embedding over a chunk list that filtered down to zero items before aggregation; passing [] to mean_agg directly.
Common situations: Indexing documents that produce empty text nodes (blank pages, whitespace-only extraction); pipelines that batch texts and pass an exhausted/filtered batch; splitting logic yielding zero chunks for a document.
Related errors
- LLM must be a FunctionCallingLLM
- embeddings_cache must be of type BaseKVStore
- embeddings_cache must be defined
- resolve_image returned zero bytes
- resolve_audio returned zero bytes
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/8377c8622cd70ce7.
Report an issue: GitHub.