#39052·langchain

QdrantVectorStore.as_retriever(search_type="mmr") inverts lambda_mult semantics

Author: het-patel-9104Created Jul 24, 2026Updated Sep 28, 2026
Labelsbugqdrantexternal

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)

python
from dotenv import load_dotenv
import os
import numpy as np

from langchain_groq import ChatGroq
from langchain_core.documents import Document
from langchain_core.output_parsers import StrOutputParser
from langchain_qdrant import QdrantVectorStore
from langchain_huggingface import HuggingFaceEmbeddings
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams

load_dotenv()

api_key = os.getenv("GROQ_API_KEY")

model = ChatGroq(
    model="llama-3.3-70b-versatile",
    temperature=0.5,
    api_key=api_key,
)

parser = StrOutputParser()

embedding_model = HuggingFaceEmbeddings(model_name="BAAI/bge-small-en-v1.5")

docs = [
    # LangChain / RAG cluster (tight, on-topic)
    Document(page_content="LangChain makes it easy to work with LLMs."),
    Document(page_content="LangChain is used to build LLM based applications."),
    Document(page_content="LangChain supports Chroma, FAISS, Pinecone, and more."),
    Document(page_content="Chroma is used to store and search document embeddings."),
    Document(page_content="Embeddings are vector representations of text."),
    Document(page_content="MMR helps you get diverse results when doing similarity search."),
    # Genuinely unrelated topics — real diversity candidates
    Document(page_content="The Eiffel Tower was completed in Paris in 1889."),
    Document(page_content="A balanced diet includes proteins, carbohydrates, and healthy fats."),
    Document(page_content="The stock market fluctuates based on investor sentiment and economic data."),
    Document(page_content="Photosynthesis converts sunlight into chemical energy in plants."),
    Document(page_content="The FIFA World Cup is held every four years."),
    Document(page_content="Jazz music originated in New Orleans in the early 20th century."),
    Document(page_content="Mount Everest is the tallest mountain above sea level on Earth."),
    Document(page_content="Regular exercise improves cardiovascular health and mood."),
]

# --- Qdrant: explicit collection creation ---
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
    collection_name="my_collection",
    vectors_config=VectorParams(size=384, distance=Distance.COSINE),
)

vector_store = QdrantVectorStore(
    client=client,
    collection_name="my_collection",
    embedding=embedding_model,
)
vector_store.add_documents(docs)

retriever = vector_store.as_retriever(
    search_type="mmr",
    search_kwargs={"k": 3, "fetch_k": len(docs), "lambda_mult": 0.0},
)

query = "What is LangChain?"
results = retriever.invoke(query)

print(f"\nRetrieved {len(results)} documents (retriever, lambda_mult=0.0)\n")
for i, doc in enumerate(results, start=1):
    print(f"{i}. {doc.page_content}")

# --- Manual MMR trace for cross-verification ---
def cos(a, b):
    a, b = np.array(a), np.array(b)
    return a.dot(b) / (np.linalg.norm(a) * np.linalg.norm(b))

# Use a list of tuples (content, metadata) or just compare page_content
# to avoid issues with Document object equality if metadata changes
doc_contents = [d.page_content for d in docs]
doc_vecs = embedding_model.embed_documents(doc_contents)
query_vec = embedding_model.embed_query(query)

def mmr_trace(query_vec, doc_vecs, docs, k=3, lambda_mult=0.0):
    sim_to_query = [cos(query_vec, v) for v in doc_vecs]
    selected = [int(np.argmax(sim_to_query))]
    print(f"\nPick 1 -> [{selected[0]}] {docs[selected[0]].page_content}  (query_sim={sim_to_query[selected[0]]:.4f})")

    while len(selected) < k:
        best_score, best_i = -1e9, -1
        for i in range(len(doc_vecs)):
            if i in selected:
                continue
            redundancy = max(cos(doc_vecs[i], doc_vecs[j]) for j in selected)
            score = lambda_mult * sim_to_query[i] - (1 - lambda_mult) * redundancy
            if score > best_score:
                best_score, best_i = score, i
        selected.append(best_i)
        print(f"Pick {len(selected)} -> [{best_i}] {docs[best_i].page_content}")

    return selected

manual_result = mmr_trace(query_vec, doc_vecs, docs, k=3, lambda_mult=0.0)
retriever_result_idx = [doc_contents.index(d.page_content) for d in results]

print(f"\nManual MMR picks:    {manual_result}")
print(f"Retriever MMR picks: {retriever_result_idx}")
print("MATCH" if manual_result == retriever_result_idx else "MISMATCH — library not honoring lambda_mult as expected")

Error Message and Stack Trace (if applicable)

bash

Description

Retrieved 3 documents (retriever, lambda_mult=0.0)

  1. LangChain is used to build LLM based applications.
  2. LangChain supports Chroma, FAISS, Pinecone, and more.
  3. LangChain makes it easy to work with LLMs.

Pick 1 -> [1] LangChain is used to build LLM based applications. (query_sim=0.8331) Pick 2 -> [6] The Eiffel Tower was completed in Paris in 1889. Pick 3 -> [8] The stock market fluctuates based on investor sentiment and economic data.

Manual MMR picks: [1, 6, 8] Retriever MMR picks: [1, 2, 0] MISMATCH — library not honoring lambda_mult as expected

QdrantVectorStore.as_retriever(search_type="mmr") inverts lambda_mult semantics

When using QdrantVectorStore.as_retriever(search_type="mmr", search_kwargs={"lambda_mult": ...}), the meaning of lambda_mult appears inverted compared with LangChain’s MMR implementation and the documented examples.

Expected behavior

lambda_mult=1.0 should favor relevance and minimum diversity, while lambda_mult=0.0 should favor maximum diversity, consistent with LangChain’s MMR helper and docstrings.

Actual behavior

The Qdrant path appears to invert this behavior because lambda_mult is mapped to Qdrant’s diversity field, and Qdrant converts that internally with 1.0 - diversity.

Evidence

LangChain’s MMR helper uses the expected formula:

python
equation_score = (
    lambda_mult * query_score - (1 - lambda_mult) * redundant_score
)

See langchain_qdrant/_utils.py

QdrantVectorStore passes lambda_mult through as diversity:
mmr=models.Mmr(diversity=lambda_mult, candidates_limit=fetch_k),

See langchain_qdrant/qdrant.py
Qdrant then flips it internally:
diversity = mmr.diversity if mmr.diversity is not None else 0.5
lambda_ = 1.0 - diversity

### System Info

System Information
------------------
> OS:  Linux
> OS Version:  #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC 
> Python Version:  3.12.13 (main, Jul 17 2026, 14:42:25) [GCC 11.4.0]

Package Information
-------------------
> langchain_core: 1.5.1
> langchain: 1.3.14
> langchain_community: 0.4.2
> langsmith: 0.10.10
> langchain_classic: 1.0.8
> langchain_docling: 2.0.0
> langchain_groq: 1.1.3
> langchain_huggingface: 1.2.2
> langchain_protocol: 0.0.18
> langchain_qdrant: 1.1.0
> langchain_text_splitters: 1.1.2
> langgraph_sdk: 0.4.2

Optional packages not installed
-------------------------------
> deepagents
> deepagents-cli

Other Dependencies
------------------
> aiohttp: 3.14.2
> anyio: 4.14.2
> cachetools: 7.1.4
> distro: 1.9.0
> docling: 2.114.0
> groq: 0.37.1
> httpx: 0.28.1
> httpx-sse: 0.4.3
> huggingface-hub: 1.24.0
> jsonpatch: 1.33
> langgraph: 1.2.9
> numpy: 2.5.1
> orjson: 3.11.9
> packaging: 26.2
> pydantic: 2.13.4
> pydantic-settings: 2.14.2
> pyyaml: 6.0.3
> qdrant-client: 1.18.0
> requests: 2.34.2
> requests-toolbelt: 1.0.0
> rich: 15.0.0
> sentence-transformers: 5.6.0
> sniffio: 1.3.1
> sqlalchemy: 2.0.51
> tenacity: 9.1.4
> tokenizers: 0.22.2
> transformers: 5.14.1
> typing-extensions: 4.16.0
> uuid-utils: 0.17.0
> websockets: 16.1.1
> wrapt: 2.2.2
> xxhash: 3.8.1
> zstandard: 0.25.0