Skip to content

Commit 1889a8c

Browse files
authored
fix(documents): name documents.batch_upsert in the over-1000 upsert error (#704) (#757)
1 parent db75d6d commit 1889a8c

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎pinecone/_internal/documents_helpers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _validate_documents(
8989
if max_documents is not None and len(docs) > max_documents:
9090
raise ValidationError(
9191
f"Number of documents ({len(docs)}) exceeds the maximum limit of "
92-
f"{max_documents} documents per request. Use batch_upsert_documents "
92+
f"{max_documents} documents per request. Use index.documents.batch_upsert "
9393
"to split a larger list into multiple requests."
9494
)
9595
normalized: list[dict[str, Any]] = []

‎tests/unit/test_async_documents_operations.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import asyncio
1616
import json
17+
import re
1718
from collections.abc import AsyncIterator
1819
from typing import Any
1920

@@ -133,6 +134,14 @@ async def test_over_1000_documents_rejected(self, index: AsyncIndex) -> None:
133134
with pytest.raises(PineconeValueError, match="1000"):
134135
await index.documents.upsert(namespace=NS, documents=docs)
135136

137+
async def test_over_1000_error_names_a_method_that_exists(self, index: AsyncIndex) -> None:
138+
docs = [{"_id": f"doc-{i}"} for i in range(1001)]
139+
with pytest.raises(PineconeValueError) as excinfo:
140+
await index.documents.upsert(namespace=NS, documents=docs)
141+
hint = re.search(r"Use index\.documents\.(\w+)", str(excinfo.value))
142+
assert hint is not None, str(excinfo.value)
143+
assert callable(getattr(index.documents, hint.group(1), None))
144+
136145
@pytest.mark.parametrize(
137146
("bad_doc", "fragment"),
138147
[

‎tests/unit/test_documents_operations.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from __future__ import annotations
1414

1515
import json
16+
import re
1617
from collections.abc import Iterator
1718
from typing import Any
1819

@@ -132,6 +133,14 @@ def test_over_1000_documents_rejected(self, index: Index) -> None:
132133
with pytest.raises(PineconeValueError, match="1000"):
133134
index.documents.upsert(namespace=NS, documents=docs)
134135

136+
def test_over_1000_error_names_a_method_that_exists(self, index: Index) -> None:
137+
docs = [{"_id": f"doc-{i}"} for i in range(1001)]
138+
with pytest.raises(PineconeValueError) as excinfo:
139+
index.documents.upsert(namespace=NS, documents=docs)
140+
hint = re.search(r"Use index\.documents\.(\w+)", str(excinfo.value))
141+
assert hint is not None, str(excinfo.value)
142+
assert callable(getattr(index.documents, hint.group(1), None))
143+
135144
@pytest.mark.parametrize(
136145
("bad_doc", "fragment"),
137146
[

0 commit comments

Comments
 (0)