run-llama/llama_index · error · ValueError

embedding not set.

Error message

embedding not set.

What it means

BaseNode.get_embedding() raises ValueError when the node's embedding field is None. The API intentionally errors instead of returning None because callers (vector stores, similarity rerankers) require an actual vector; nodes created by parsers start with embedding=None until an embedding model runs on them.

Source

Thrown at llama-index-core/llama_index/core/schema.py:491

    def __str__(self) -> str:
        source_text_truncated = truncate_text(
            self.get_content().strip(), TRUNCATE_LENGTH
        )
        source_text_wrapped = textwrap.fill(
            f"Text: {source_text_truncated}\n", width=WRAP_WIDTH
        )
        return f"Node ID: {self.node_id}\n{source_text_wrapped}"

    def get_embedding(self) -> List[float]:
        """
        Get embedding.

        Errors if embedding is None.

        """
        if self.embedding is None:
            raise ValueError("embedding not set.")
        return self.embedding

    def as_related_node_info(self) -> RelatedNodeInfo:
        """Get node as RelatedNodeInfo."""
        return RelatedNodeInfo(
            node_id=self.node_id,
            node_type=self.get_type(),
            metadata=self.metadata,
            hash=self.hash,
        )


EmbeddingKind = Literal["sparse", "dense"]


class MediaResource(BaseModel):
    """
    A container class for media content.

View on GitHub (pinned to afd0fef371)

Solutions

  1. Embed first: node.embedding = Settings.embedding_model.get_text_embedding(node.get_content())
  2. Run nodes through an IngestionPipeline with an embedding transform before touching embeddings
  3. If a node may legitimately lack an embedding, check node.embedding is None yourself instead of calling get_embedding()

Example fix

# before
vec = node.get_embedding()  # ValueError if never embedded

# after
if node.embedding is None:
    node.embedding = Settings.embedding_model.get_text_embedding(node.get_content())
vec = node.get_embedding()
Defensive patterns

Strategy: validation

Validate before calling

if node.embedding is None:
    node.embedding = Settings.embedding_model.get_text_embedding(node.get_content())

Type guard

def is_embedded(node) -> bool:
    return node.embedding is not None

Prevention

When it happens

Trigger: Calling node.get_embedding() on a node that was never embedded — i.e., created via TextNode()/SentenceSplitter but not passed through Settings.embedding_model.get_text_embedding or an ingestion pipeline embedding step.

Common situations: Custom retrieval or reranking code that inspects node embeddings after loading un-embedded nodes from a docstore; building a vector index but reading nodes from the wrong (non-embedded) copy.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/7fad7faf288a1493. Report an issue: GitHub.