run-llama/llama_index · error · ValueError

Score not set.

Error message

Score not set.

What it means

NodeWithScore.get_score() raises ValueError('Score not set.') only when called with raise_error=True and the node's score is None. Nodes produced by retrievers that do not compute similarity (keyword/BM25-style, list-index linear scan, or manually constructed NodeWithScore) carry score=None.

Source

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

    @classmethod
    def class_name(cls) -> str:
        return "IndexNode"


class NodeWithScore(BaseComponent):
    node: SerializeAsAny[BaseNode]
    score: Optional[float] = None

    def __str__(self) -> str:
        score_str = "None" if self.score is None else f"{self.score: 0.3f}"
        return f"{self.node}\nScore: {score_str}\n"

    def get_score(self, raise_error: bool = False) -> float:
        """Get score."""
        if self.score is None:
            if raise_error:
                raise ValueError("Score not set.")
            else:
                return 0.0
        else:
            return self.score

    @classmethod
    def class_name(cls) -> str:
        return "NodeWithScore"

    ##### pass through methods to BaseNode #####
    @property
    def node_id(self) -> str:
        return self.node.node_id

    @property
    def id_(self) -> str:
        return self.node.id_

View on GitHub (pinned to afd0fef371)

Solutions

  1. Call get_score() without raise_error (defaults to 0.0 for missing scores) when 0 is an acceptable default
  2. Check .score is None explicitly and skip/assign a default before calling with raise_error=True
  3. Use a similarity-based retriever (vector index) if real scores are required downstream

Example fix

# before
score = nws.get_score(raise_error=True)  # ValueError when score is None

# after
score = nws.score if nws.score is not None else 0.0
# or: score = nws.get_score()  # returns 0.0 instead of raising
Defensive patterns

Strategy: validation

Validate before calling

if nws.score is None:
    score = 0.0  # or skip node
else:
    score = nws.score

Type guard

def is_scored(nws) -> bool:
    return nws.score is not None

Prevention

When it happens

Trigger: Calling node_with_score.get_score(raise_error=True) on a node whose score was never assigned — e.g. nodes returned from a no-score retriever or built as NodeWithScore(node=n) without a score argument.

Common situations: Post-processing code that assumes every retrieved node is scored; mixing nodes from BM25/keyword retrieval with rerankers that require scores.

Related errors


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