microsoft/semantic-kernel · error · ServiceInvalidRequestError
Limit must be less than or equal to {MAX_QUERY_WITHOUT_METAD
Error message
Limit must be less than or equal to {MAX_QUERY_WITHOUT_METADATA_BATCH_SIZE} What it means
Raised in PineconeMemoryStore.get_nearest_matches() when limit exceeds MAX_QUERY_WITHOUT_METADATA_BATCH_SIZE (10000). ServiceInvalidRequestError (a subclass of ServiceResponseException) fires after the collection-existence check but before the query. This enforces Pinecone's documented top_k ceiling for queries without metadata.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/pinecone/pinecone_memory_store.py:354
"""Gets the nearest matches to an embedding using cosine similarity.
Args:
collection_name (str): The name of the collection to get the nearest matches from.
embedding (ndarray): The embedding to find the nearest matches to.
limit (int): The maximum number of matches to return.
min_relevance_score (float): The minimum relevance score of the matches. (default: {0.0})
with_embeddings (bool): Whether to include the embeddings in the results. (default: {False})
Returns:
List[Tuple[MemoryRecord, float]]: The records and their relevance scores.
"""
if not await self.does_collection_exist(collection_name):
raise ServiceResourceNotFoundError(f"Collection '{collection_name}' does not exist")
collection = self.pinecone.Index(collection_name)
if limit > MAX_QUERY_WITHOUT_METADATA_BATCH_SIZE:
raise ServiceInvalidRequestError(
"Limit must be less than or equal to " + f"{MAX_QUERY_WITHOUT_METADATA_BATCH_SIZE}"
)
if limit > MAX_QUERY_WITH_METADATA_BATCH_SIZE:
query_response = collection.query(
vector=embedding.tolist(),
top_k=limit,
include_values=False,
include_metadata=False,
)
keys = [match.id for match in query_response.matches]
fetch_response = await self.__get_batch(collection_name, keys, with_embeddings)
vectors = fetch_response.vectors
for match in query_response.matches:
vectors[match.id].update(match)
matches = [vectors[key] for key in vectors]
else:
query_response = collection.query(
vector=embedding.tolist(),View on GitHub (pinned to c028a0c7dc)
Solutions
- Reduce limit to <= 10000 (and <= 1000 when metadata is requested).
- Cap user-supplied limit at the boundary before calling.
- Paginate via multiple smaller queries if more results are needed.
- Migrate to PineconeStore + Collection.
Example fix
// before
matches = await store.get_nearest_matches("my_col", emb, limit=50000, with_embeddings=False)
// after
limit = min(user_limit, 10000)
matches = await store.get_nearest_matches("my_col", emb, limit=limit, with_embeddings=False) Defensive patterns
Strategy: validation
Validate before calling
from semantic_kernel.connectors.memory_stores.pinecone.pinecone_memory_store import MAX_QUERY_WITHOUT_METADATA_BATCH_SIZE limit = min(limit, MAX_QUERY_WITHOUT_METADATA_BATCH_SIZE) return await store.get_nearest_matches(collection_name, embedding, limit, with_embeddings)
Type guard
def is_valid_query_limit(limit: int, with_metadata: bool) -> bool:
return limit <= (1000 if with_metadata else 10000) Try / catch
from semantic_kernel.exceptions import ServiceInvalidRequestError
try:
return await store.get_nearest_matches(collection_name, embedding, limit, with_embeddings)
except ServiceInvalidRequestError as e:
raise ValueError(f"limit too large for Pinecone: {e}") from e Prevention
- Cap user-supplied limit at the Pinecone ceiling before calling.
- Paginate instead of requesting huge top_k in one call.
- Remember the metadata path has a lower ceiling (1000).
When it happens
Trigger: Calling get_nearest_matches(..., limit=N) with N > 10000. Note the code checks the no-metadata ceiling first even when with_embeddings/with_metadata is requested; a higher ceiling (MAX_QUERY_WITH_METADATA_BATCH_SIZE=1000) is checked next.
Common situations: Caller passes an unbounded 'top N' from user input; pagination limit copied from a different backend; desire to retrieve the whole index in one call.
Related errors
- Dimensionality of {default_dimensionality} exceeds the maxim
- Failed to create Pinecone settings.
- Dimensionality of {dimension_num} exceeds the maximum allowe
- Collection '{collection_name}' does not exist
- Error upserting record: {upsert_response.message}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/14aa44235c2a4028.
Report an issue: GitHub.