Regression: Retriever passes namespace=None causing default namespace to be ignored in similarity_search_by_vector_with_score (v0.2.11) #27

Closed
opened 2026-02-16 07:16:01 -05:00 by yindo · 0 comments
Owner

Originally created by @hieptran1401 on GitHub (Oct 7, 2025).

Originally assigned to: @theanupllm on GitHub.

Package/version

  • langchain-pinecone: v0.2.11 (regressed)
  • Previously working: v0.2.10

Description

After upgrading to v0.2.11, the retriever path passes namespace=None into PineconeVectorStore.similarity_search_by_vector_with_score. The implementation reads namespace via kwargs:

namespace = kwargs.get("namespace", self._namespace)

Because kwargs contains namespace=None, the fallback to self._namespace is skipped. In v0.2.10, namespace was an explicit parameter with a proper None fallback:

def similarity_search_by_vector_with_score(..., namespace: Optional[str] = None, ...):
    if namespace is None:
        namespace = self._namespace

This regression causes queries that should use the default namespace to instead query the empty namespace.

Steps to reproduce

  1. Create a PineconeVectorStore with a default namespace:
from langchain_openai import OpenAIEmbeddings
from langchain_pinecone import PineconeVectorStore
from pinecone import Pinecone

pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
index = pc.Index("SAMPLE_INDEX")
embedding = OpenAIEmbeddings(api_key=os.environ["OPENAI_API_KEY"], model="text-embedding-ada-002")

namespace = "SAMPLE_NAMESPACE"
vector_store = PineconeVectorStore(index=index, embedding=embedding, namespace=namespace)
retriever = vector_store.as_retriever(
    search_type="similarity_score_threshold",
    search_kwargs={"k": 1, "score_threshold": 0.4},
)
  1. Invoke the retriever without a namespace:
retriever.invoke("SAMPLE_QUERY")
  1. Add debug prints to similarity_search_by_vector_with_score and observe:

Expected behavior

  • If namespace is not provided or is None, it should fall back to self._namespace.

Actual behavior

  • kwargs includes namespace=None, which overrides the fallback and results in querying the empty namespace instead of self._namespace.

Example logs (with clearer order)

Case 1 (no namespace passed to retriever):

similarity_search_by_vector_with_score
self.namespace is SAMPLE_NAMESPACE
kwargs is {'filter': None, 'namespace': None}
namespace is None

No relevant docs were retrieved using the relevance score threshold 0.4
Result_1 are: []

Case 2 (explicit namespace passed to retriever):

similarity_search_by_vector_with_score
self.namespace is SAMPLE_NAMESPACE
kwargs is {'filter': None, 'namespace': 'SAMPLE_NAMESPACE'}
namespace is SAMPLE_NAMESPACE

Result_2 are: [Document(...)]

Regression details

  • v0.2.10: Works due to explicit parameter and if namespace is None: namespace = self._namespace.
  • v0.2.11: Regressed due to kwargs.get(...) where None prevents fallback.

Possible fixes

  • Preserve fallback behavior:
namespace = kwargs.get("namespace")
if namespace is None:
    namespace = self._namespace
  • Alternatively, ensure upstream call sites (retriever) don’t include the namespace key in kwargs when the value is None.

Minimal reproducible example

from pinecone import Pinecone
from langchain_openai import OpenAIEmbeddings
from langchain_pinecone import PineconeVectorStore

pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
index = pc.Index("SAMPLE_INDEX")
emb = OpenAIEmbeddings(api_key=os.environ["OPENAI_API_KEY"], model="text-embedding-ada-002")

ns = "SAMPLE_NAMESPACE"
vs = PineconeVectorStore(index=index, embedding=emb, namespace=ns)
retriever = vs.as_retriever(
    search_type="similarity_score_threshold",
    search_kwargs={"k": 1, "score_threshold": 0.4},
)

print("Case 1 (no namespace passed):")
print(retriever.invoke("SAMPLE_QUERY"))  # expected: use default ns; v0.2.11: queries empty ns

print("Case 2 (explicit namespace):")
print(retriever.invoke("SAMPLE_QUERY", namespace=ns))  # works
Originally created by @hieptran1401 on GitHub (Oct 7, 2025). Originally assigned to: @theanupllm on GitHub. ### Package/version - langchain-pinecone: v0.2.11 (regressed) - Previously working: v0.2.10 ### Description After upgrading to v0.2.11, the retriever path passes `namespace=None` into `PineconeVectorStore.similarity_search_by_vector_with_score`. The implementation reads `namespace` via kwargs: ```python namespace = kwargs.get("namespace", self._namespace) ``` Because `kwargs` contains `namespace=None`, the fallback to `self._namespace` is skipped. In v0.2.10, `namespace` was an explicit parameter with a proper `None` fallback: ```python def similarity_search_by_vector_with_score(..., namespace: Optional[str] = None, ...): if namespace is None: namespace = self._namespace ``` This regression causes queries that should use the default namespace to instead query the empty namespace. ### Steps to reproduce 1. Create a `PineconeVectorStore` with a default namespace: ```python from langchain_openai import OpenAIEmbeddings from langchain_pinecone import PineconeVectorStore from pinecone import Pinecone pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"]) index = pc.Index("SAMPLE_INDEX") embedding = OpenAIEmbeddings(api_key=os.environ["OPENAI_API_KEY"], model="text-embedding-ada-002") namespace = "SAMPLE_NAMESPACE" vector_store = PineconeVectorStore(index=index, embedding=embedding, namespace=namespace) retriever = vector_store.as_retriever( search_type="similarity_score_threshold", search_kwargs={"k": 1, "score_threshold": 0.4}, ) ``` 2. Invoke the retriever without a namespace: ```python retriever.invoke("SAMPLE_QUERY") ``` 3. Add debug prints to `similarity_search_by_vector_with_score` and observe: ### Expected behavior - If `namespace` is not provided or is `None`, it should fall back to `self._namespace`. ### Actual behavior - `kwargs` includes `namespace=None`, which overrides the fallback and results in querying the empty namespace instead of `self._namespace`. ### Example logs (with clearer order) Case 1 (no namespace passed to retriever): ```text similarity_search_by_vector_with_score self.namespace is SAMPLE_NAMESPACE kwargs is {'filter': None, 'namespace': None} namespace is None No relevant docs were retrieved using the relevance score threshold 0.4 Result_1 are: [] ``` Case 2 (explicit namespace passed to retriever): ```text similarity_search_by_vector_with_score self.namespace is SAMPLE_NAMESPACE kwargs is {'filter': None, 'namespace': 'SAMPLE_NAMESPACE'} namespace is SAMPLE_NAMESPACE Result_2 are: [Document(...)] ``` ### Regression details - v0.2.10: Works due to explicit parameter and `if namespace is None: namespace = self._namespace`. - v0.2.11: Regressed due to `kwargs.get(...)` where `None` prevents fallback. ### Possible fixes - Preserve fallback behavior: ```python namespace = kwargs.get("namespace") if namespace is None: namespace = self._namespace ``` - Alternatively, ensure upstream call sites (retriever) don’t include the `namespace` key in kwargs when the value is `None`. ### Minimal reproducible example ```python from pinecone import Pinecone from langchain_openai import OpenAIEmbeddings from langchain_pinecone import PineconeVectorStore pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"]) index = pc.Index("SAMPLE_INDEX") emb = OpenAIEmbeddings(api_key=os.environ["OPENAI_API_KEY"], model="text-embedding-ada-002") ns = "SAMPLE_NAMESPACE" vs = PineconeVectorStore(index=index, embedding=emb, namespace=ns) retriever = vs.as_retriever( search_type="similarity_score_threshold", search_kwargs={"k": 1, "score_threshold": 0.4}, ) print("Case 1 (no namespace passed):") print(retriever.invoke("SAMPLE_QUERY")) # expected: use default ns; v0.2.11: queries empty ns print("Case 2 (explicit namespace):") print(retriever.invoke("SAMPLE_QUERY", namespace=ns)) # works ```
yindo closed this issue 2026-02-16 07:16:01 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchain-pinecone#27