Skip to content

search_skills fails with Pydantic validation error when using OpenAI embeddings (negative cosine scores) #80

Description

@kaalph

Bug

search_skills() fails with a Pydantic validation error when using --embedding-provider openai:

1 validation error for SkillSummary
score
  Input should be greater than or equal to 0
  [type=greater_than_equal, input_value=-0.594804584980011, input_type=float]

Root Cause

In search_service.py, _normalize_score() computes return -float(row["_distance"]). LanceDB cosine distance can exceed 1.0 for certain OpenAI embedding models (e.g. text-embedding-3-large), making the negated score negative.

types.py defines score: float = Field(ge=0.0) which rejects these negative values.

Reproduction

uvx skillport-mcp --embedding-provider openai --openai-embedding-model text-embedding-3-large
# Then call search_skills("any text query") via MCP

With 123+ skills indexed, almost every text query triggers the error. Only search_skills("*") (list-all code path) works because it skips vector search.

Suggested Fix

One-line change in search.py and list.py:

# Before (search.py line 33):
score = float(row.get("_score", 0.0))

# After:
score = max(0.0, float(row.get("_score", 0.0)))

Same pattern in list.py.

Environment

  • skillport-mcp v1.1.0
  • Python 3.14.3
  • LanceDB (via uv)
  • Embedding model: OpenAI text-embedding-3-large

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions