AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Legacy Qdrant Vector Store Returns Raw Distances Instead Of Normalized Relevance Scores

The legacy Qdrant class overrides similarity_search_with_relevance_scores and asimilarity_search_with_relevance_scores to return raw distance scores, bypassing the base VectorStore normalization pipeline. Removing these overrides restores correct [0,1] relevance scores.

mediumConfidence 96%LangchainMemoryChat ModelsAffected V1.1.0

Origin Analysis

In langchain_qdrant/vectorstores.py, the legacy Qdrant class overrides _similarity_search_with_relevance_scores and _asimilarity_search_with_relevance_scores to directly call similarity_search_with_score and asimilarity_search_with_score, thereby bypassing _select_relevance_score_fn which is responsible for converting raw distances (e.g., Euclidean, Cosine) into normalized relevance scores.
```python from langchain_core.embeddings import FakeEmbeddings from langchain_qdrant import Qdrant texts = ["foo", "bar", "baz"] docsearch = Qdrant.from_texts( texts, FakeEmbeddings(size=10), location=":memory:", distance_func="Euclid", ) results = docsearch.similarity_search_with_relevance_scores("foo", k=3) for doc, score in results: print(doc.page_content, score) # Expected: exact match relevance score 1.0, but receives raw distance 0.0 ```

Fixing Code Block

--- a/libs/partners/qdrant/langchain_qdrant/vectorstores.py +++ b/libs/partners/qdrant/langchain_qdrant/vectorstores.py @@ -xxx,xx +xxx,xx @@ - def _similarity_search_with_relevance_scores(self, query, k=4, **kwargs): - return self.similarity_search_with_score(query, k, **kwargs) - - async def _asimilarity_search_with_relevance_scores(self, query, k=4, **kwargs): - return await self.asimilarity_search_with_score(query, k, **kwargs) -
Removing these overridden methods from the legacy Qdrant class allows the inherited VectorStore._similarity_search_with_relevance_scores and _asimilarity_search_with_relevance_scores to run, which call similarity_search_with_score and then apply the distance-specific normalization function returned by _select_relevance_score_fn. This produces scores in the expected [0,1] range.

Edge Case Audit

This change alters the meaning of returned scores for users of the legacy Qdrant class. Any code that previously expected raw distances from similarity_search_with_relevance_scores will now receive normalized scores; to obtain raw distances, use similarity_search_with_score directly. Rollback: re-add the removed methods or pin langchain-qdrant to the previous version. The new QdrantVectorStore class is unaffected.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state