Skip to content

bug: Legacy Qdrant vector store returns raw distances instead of normalized relevance scores #38504

Description

Submission checklist

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

from langchain_core.embeddings import FakeEmbeddings
from langchain_qdrant import Qdrant

texts = ["foo", "bar", "baz"]
# Under Euclid distance strategy:
# Perfect match distance is 0.0, relevance score should normalize to 1.0 (1.0 - distance/sqrt(2))
docsearch = Qdrant.from_texts(
    texts,
    FakeEmbeddings(size=10),
    location=":memory:",
    distance_func="Euclid",
)

results = docsearch.similarity_search_with_relevance_scores("foo", k=3)
print("Returned relevance scores:")
for doc, score in results:
    print(f"Content: '{doc.page_content}', Relevance Score: {score}")

Error Message and Stack Trace (if applicable)

Description

Description

Problem

When calling similarity_search_with_relevance_scores or asimilarity_search_with_relevance_scores on the legacy Qdrant vector store class, the returned scores are raw distances rather than normalized relevance scores in the [0, 1] range. For instance, an exact match with Euclidean distance returns 0.0 (which is the raw distance) instead of 1.0 (which is the normalized relevance score).

Root cause

In libs/partners/qdrant/langchain_qdrant/vectorstores.py, the legacy Qdrant class implements the _select_relevance_score_fn method to return distance-specific normalization functions (e.g., for COSINE, DOT, or EUCLID distance metrics). However, the class overrode _similarity_search_with_relevance_scores and _asimilarity_search_with_relevance_scores to directly call and return similarity_search_with_score and asimilarity_search_with_score outputs. This bypassed the relevance normalization pipeline entirely.

Suggested fix

Remove the overridden _similarity_search_with_relevance_scores and _asimilarity_search_with_relevance_scores methods from the legacy Qdrant class so it correctly inherits the base VectorStore class implementation, which maps raw scores through _select_relevance_score_fn.

(Note: The new QdrantVectorStore already correctly inherits from the base class and is unaffected by this issue.)

System Info

System Information

OS: Linux
OS Version: #1 SMP PREEMPT_DYNAMIC Thu May 21 18:06:59 UTC 2026
Python Version: 3.13.5 | packaged by Anaconda, Inc. | (main, Jun 12 2025, 16:09:02) [GCC 11.2.0]

Package Information

langchain_core: 1.4.8
langsmith: 0.8.18
langchain_protocol: 0.0.18
langchain_qdrant: 1.1.0
langchain_tests: 1.1.9

Optional packages not installed

deepagents
deepagents-cli

Other Dependencies

httpx: 0.28.1
jsonpatch: 1.33
numpy: 2.3.3
orjson: 3.11.6
packaging: 25.0
pydantic: 2.12.1
pytest: 9.0.3
pytest-asyncio: 1.3.0
pytest-benchmark: 5.0.1
pytest-codspeed: 4.0.0
pytest-recording: 0.13.4
pytest-socket: 0.7.0
pyyaml: 6.0.3
qdrant-client: 1.15.1
requests: 2.34.0
requests-toolbelt: 1.0.0
rich: 14.1.0
syrupy: 5.1.0
tenacity: 9.1.2
typing-extensions: 4.15.0
uuid-utils: 0.12.0
vcrpy: 8.2.1
websockets: 16.0
wrapt: 1.17.3
xxhash: 3.6.0
zstandard: 0.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRelated to a bug, vulnerability, unexpected error with an existing featureexternalqdrant`langchain-qdrant` package issues & PRs

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions