Skip to content

EmbeddingDistance raises NameError for euclidean, manhattan, chebyshev and hamming metrics #23

Open

Description

Tracing Method

  • SDK/Client
  • REST API
  • With LangChain
  • Other

Language

  • Python
  • JavaScript/TypeScript
  • Other

Host

Other System Info

langsmith at f6b73d8374b30b6dd69b703d4c1e3617ed2fb6e6 (main), numpy installed. Python 3.14 was used but the bug is not version-specific. No network access is involved.

Reproduction

numpy is imported only under TYPE_CHECKING in _embedding_distance.py. Only evaluate() and cosine_similarity() import it locally, so the four static methods that use np (lines 141-190) fail with NameError.

Public entry point:

from langsmith import expect

expect.embedding_distance(
    "a", "b",
    config={"metric": "euclidean", "encoder": lambda t: [[1.0, 2.0], [2.0, 4.0]]},
)
# NameError: name 'np' is not defined

Same thing directly on the class, for every metric:

from langsmith._internal._embedding_distance import EmbeddingDistance
enc = lambda t: [[1.0, 2.0], [2.0, 4.0]]
for m in ["cosine", "euclidean", "manhattan", "chebyshev", "hamming"]:
    try: print(m, EmbeddingDistance({"encoder": enc, "metric": m}).evaluate("a", "b"))
    except Exception as e: print(m, type(e).__name__, e)

Output:

cosine 2.220446049250313e-16
euclidean NameError name 'np' is not defined
manhattan NameError name 'np' is not defined
chebyshev NameError name 'np' is not defined
hamming NameError name 'np' is not defined

Expected behavior

Each metric listed in the EmbeddingConfig Literal returns a float, as cosine does.

A possible fix is to import numpy as np inside each of the four static methods (the module already lazy-imports numpy to keep it optional), plus a unit test per metric.

Activity

  1. thibautlehmann commented on Oct 16, 2026

    @thibautlehmann
    Contributor

    Hey Muneeb Ullah (@moneebullah25), langsmith-sdk is archived, so I moved this issue to langchain-ai/langsmith-python, where the SDK now lives 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingsdk

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions