Skip to content

Commit bf4c0af

Browse files
committed
Review and update docstrings for Admin class
1 parent db0418b commit bf4c0af

6 files changed

Lines changed: 265 additions & 16 deletions

File tree

pinecone/admin/admin.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,46 @@ def __init__(
5858
dictionary of key-value pairs. This is primarily used for internal testing
5959
purposes.
6060
:type additional_headers: Optional[dict[str, str]]
61+
62+
Examples
63+
--------
64+
65+
.. code-block:: python
66+
:caption: Initialize Admin using environment variables
67+
68+
import os
69+
from pinecone import Admin
70+
71+
# Set environment variables
72+
os.environ["PINECONE_CLIENT_ID"] = "your-client-id"
73+
os.environ["PINECONE_CLIENT_SECRET"] = "your-client-secret"
74+
75+
# Initialize Admin (reads from environment variables)
76+
admin = Admin()
77+
78+
.. code-block:: python
79+
:caption: Initialize Admin with explicit credentials
80+
81+
from pinecone import Admin
82+
83+
# Initialize Admin with explicit credentials
84+
admin = Admin(
85+
client_id="your-client-id",
86+
client_secret="your-client-secret"
87+
)
88+
89+
.. code-block:: python
90+
:caption: Initialize Admin with additional headers
91+
92+
from pinecone import Admin
93+
94+
# Initialize Admin with additional headers for testing
95+
admin = Admin(
96+
client_id="your-client-id",
97+
client_secret="your-client-secret",
98+
additional_headers={"X-Custom-Header": "value"}
99+
)
100+
61101
"""
62102

63103
if client_id is not None:
@@ -149,7 +189,7 @@ def project(self):
149189
150190
# Create a project with no quota for pod indexes
151191
admin.project.create(
152-
name="my-project"
192+
name="my-project",
153193
max_pods=0
154194
)
155195
@@ -169,6 +209,7 @@ def project(self):
169209
admin = Admin()
170210
project = admin.project.get(name="my-project")
171211
admin.project.delete(project_id=project.id)
212+
172213
"""
173214
if self._project is None:
174215
from pinecone.admin.resources import ProjectResource

pinecone/admin/resources/api_key.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def list(self, project_id: str):
6767
print(api_key.name)
6868
print(api_key.description)
6969
print(api_key.roles)
70+
7071
"""
7172
return self._api_keys_api.list_project_api_keys(project_id=project_id)
7273

@@ -108,12 +109,54 @@ def fetch(self, api_key_id: str):
108109

109110
@require_kwargs
110111
def get(self, api_key_id: str):
111-
"""Alias for :func:`fetch`"""
112+
"""Alias for :func:`fetch`
113+
114+
Examples
115+
--------
116+
117+
.. code-block:: python
118+
:caption: Get an API key by api_key_id
119+
120+
from pinecone import Admin
121+
122+
# Credentials read from PINECONE_CLIENT_ID and
123+
# PINECONE_CLIENT_SECRET environment variables
124+
admin = Admin()
125+
126+
api_key = admin.api_key.get(api_key_id='my-api-key-id')
127+
print(api_key.id)
128+
print(api_key.name)
129+
print(api_key.description)
130+
print(api_key.roles)
131+
print(api_key.created_at)
132+
133+
"""
112134
return self.fetch(api_key_id=api_key_id)
113135

114136
@require_kwargs
115137
def describe(self, api_key_id: str):
116-
"""Alias for :func:`fetch`"""
138+
"""Alias for :func:`fetch`
139+
140+
Examples
141+
--------
142+
143+
.. code-block:: python
144+
:caption: Describe an API key by api_key_id
145+
146+
from pinecone import Admin
147+
148+
# Credentials read from PINECONE_CLIENT_ID and
149+
# PINECONE_CLIENT_SECRET environment variables
150+
admin = Admin()
151+
152+
api_key = admin.api_key.describe(api_key_id='my-api-key-id')
153+
print(api_key.id)
154+
print(api_key.name)
155+
print(api_key.description)
156+
print(api_key.roles)
157+
print(api_key.created_at)
158+
159+
"""
117160
return self.fetch(api_key_id=api_key_id)
118161

119162
@require_kwargs
@@ -204,6 +247,7 @@ def create(
204247
205248
api_key_value = api_key_response.value
206249
print(api_key_value)
250+
207251
"""
208252
args = [("name", name), ("description", description), ("roles", roles)]
209253
create_api_key_request = CreateAPIKeyRequest(**parse_non_empty_args(args))

pinecone/admin/resources/organization.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def list(self):
6464
print(organization.name)
6565
print(organization.plan)
6666
print(organization.payment_status)
67+
6768
"""
6869
return self._organizations_api.list_organizations()
6970

@@ -125,6 +126,7 @@ def get(self, organization_id: str):
125126
)
126127
print(organization.id)
127128
print(organization.name)
129+
128130
"""
129131
return self.fetch(organization_id=organization_id)
130132

@@ -150,6 +152,7 @@ def describe(self, organization_id: str):
150152
)
151153
print(organization.id)
152154
print(organization.name)
155+
153156
"""
154157
return self.fetch(organization_id=organization_id)
155158

pinecone/admin/resources/project.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def list(self):
7474
print(project.name)
7575
print(project.max_pods)
7676
print(project.force_encryption_with_cmek)
77+
7778
"""
7879
return self._projects_api.list_projects()
7980

@@ -129,6 +130,7 @@ def fetch(self, project_id: str | None = None, name: str | None = None):
129130
print(project.force_encryption_with_cmek)
130131
print(project.organization_id)
131132
print(project.created_at)
133+
132134
"""
133135
if project_id is not None and name is not None:
134136
raise ValueError("Either project_id or name must be provided but not both")
@@ -174,6 +176,7 @@ def get(self, project_id: str | None = None, name: str | None = None):
174176
print(project.name)
175177
print(project.max_pods)
176178
print(project.force_encryption_with_cmek)
179+
177180
"""
178181
return self.fetch(project_id=project_id, name=name)
179182

@@ -201,6 +204,7 @@ def describe(self, project_id: str | None = None, name: str | None = None):
201204
print(project.name)
202205
print(project.max_pods)
203206
print(project.force_encryption_with_cmek)
207+
204208
"""
205209
return self.fetch(project_id=project_id, name=name)
206210

@@ -256,6 +260,7 @@ def exists(self, project_id: str | None = None, name: str | None = None):
256260
print(f"Project {project_id} exists")
257261
else:
258262
print(f"Project {project_id} does not exist")
263+
259264
"""
260265
if project_id is not None and name is not None:
261266
raise ValueError("Either project_id or name must be provided but not both")
@@ -453,6 +458,7 @@ def delete(
453458
print("Project deleted successfully")
454459
else:
455460
print("Project deletion failed")
461+
456462
"""
457463
project = self.get(project_id=project_id)
458464

pinecone/inference/inference.py

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,31 @@ def embed(
194194
# usage={'total_tokens': 6}
195195
# )
196196
197+
You can also use a single string input:
198+
199+
.. code-block:: python
200+
201+
from pinecone import Pinecone
202+
203+
pc = Pinecone()
204+
output = pc.inference.embed(
205+
model="text-embedding-3-small",
206+
inputs="Hello, world!"
207+
)
208+
209+
Or use the EmbedModel enum:
210+
211+
.. code-block:: python
212+
213+
from pinecone import Pinecone
214+
from pinecone.inference import EmbedModel
215+
216+
pc = Pinecone()
217+
outputs = pc.inference.embed(
218+
model=EmbedModel.TEXT_EMBEDDING_3_SMALL,
219+
inputs=["Document 1", "Document 2"]
220+
)
221+
197222
"""
198223
request_body = InferenceRequestBuilder.embed_request(
199224
model=model, inputs=inputs, parameters=parameters
@@ -235,8 +260,7 @@ def rerank(
235260
relevance, with the first being the most relevant. The ``index`` field can be used to locate the document
236261
relative to the list of documents specified in the request. Each document contains a ``score`` key
237262
representing how close the document relates to the query.
238-
239-
Example:
263+
:rtype: RerankResult
240264
241265
.. code-block:: python
242266
@@ -275,6 +299,38 @@ def rerank(
275299
# usage={'rerank_units': 1}
276300
# )
277301
302+
You can also use document dictionaries with custom fields:
303+
304+
.. code-block:: python
305+
306+
from pinecone import Pinecone
307+
308+
pc = Pinecone()
309+
result = pc.inference.rerank(
310+
model="pinecone-rerank-v0",
311+
query="What is machine learning?",
312+
documents=[
313+
{"text": "Machine learning is a subset of AI.", "category": "tech"},
314+
{"text": "Cooking recipes for pasta.", "category": "food"},
315+
],
316+
rank_fields=["text"],
317+
top_n=1
318+
)
319+
320+
Or use the RerankModel enum:
321+
322+
.. code-block:: python
323+
324+
from pinecone import Pinecone
325+
from pinecone.inference import RerankModel
326+
327+
pc = Pinecone()
328+
result = pc.inference.rerank(
329+
model=RerankModel.PINECONE_RERANK_V0,
330+
query="Your query here",
331+
documents=["doc1", "doc2", "doc3"]
332+
)
333+
278334
"""
279335
rerank_request = InferenceRequestBuilder.rerank(
280336
model=model,
@@ -302,8 +358,7 @@ def list_models(
302358
:type vector_type: str, optional
303359
304360
:return: A list of models.
305-
306-
Example:
361+
:rtype: ModelInfoList
307362
308363
.. code-block:: python
309364
@@ -339,8 +394,6 @@ def get_model(self, model_name: str) -> "ModelInfo":
339394
:return: A ModelInfo object.
340395
:rtype: ModelInfo
341396
342-
Example:
343-
344397
.. code-block:: python
345398
346399
from pinecone import Pinecone
@@ -371,5 +424,6 @@ def get_model(self, model_name: str) -> "ModelInfo":
371424
# "provider_name": "Pinecone",
372425
# "supported_metrics": []
373426
# }
427+
374428
"""
375429
return self.model.get(model_name=model_name)

0 commit comments

Comments
 (0)