Commit db0418b
authored
Update Pinecone class docstrings (#550)
# Improve Docstring Documentation and Remove Redundant Interface
## Summary
This PR comprehensively reviews and updates all method docstrings in the
`Pinecone` class and underlying interface classes to ensure they use
proper RST syntax, include code-block usage examples, and have correct
whitespace formatting for Sphinx rendering. Additionally, this PR
removes the redundant `LegacyPineconeDBControlInterface` class that was
creating maintenance overhead and sync risks.
## Problem
1. **Incomplete Documentation**: Many methods in the `Pinecone` class
lacked comprehensive docstrings with usage examples, making it difficult
for users to understand how to use the SDK effectively.
2. **Inconsistent Formatting**: Some docstrings used different formats
(e.g., `Args:` vs `:param:`), and code-block examples lacked proper
whitespace formatting required for Sphinx to render correctly.
3. **Redundant Interface**: The `LegacyPineconeDBControlInterface` class
served primarily as a docstring container, creating duplication and the
risk of documentation falling out of sync with implementations.
4. **Unrealistic Examples**: Some code examples (particularly in the
`inference` property) used placeholder content that didn't demonstrate
real-world usage patterns.
## Solution
1. **Added Comprehensive Docstrings**: Added complete RST-formatted
docstrings with code-block examples to all `Pinecone` class methods that
were missing them, including:
- Index management methods (`create_index`, `delete_index`,
`list_indexes`, `describe_index`, `has_index`, `configure_index`)
- Collection methods (`create_collection`, `list_collections`,
`delete_collection`, `describe_collection`)
- Backup and restore job methods (`create_backup`, `list_backups`,
`describe_backup`, `delete_backup`, `list_restore_jobs`,
`describe_restore_job`)
- Index instantiation methods (`Index`, `IndexAsyncio`)
- Properties (`inference`, `db`)
2. **Standardized RST Format**: Converted all docstrings to use
consistent RST syntax with `:param:` and `:type:` directives instead of
mixed formats.
3. **Fixed Code-Block Formatting**: Ensured all code-block examples have
proper whitespace (empty line after code blocks) for correct Sphinx
rendering.
4. **Improved Examples**: Updated examples to be more realistic and
demonstrate actual usage patterns, including:
- Updated the `inference` property example to show realistic embedding
and reranking operations with actual document content
- Fixed syntax errors in import statements within docstring examples
- Added multiple usage patterns where appropriate (e.g., different ways
to create indexes)
5. **Removed Redundant Interface**: Deleted
`LegacyPineconeDBControlInterface` since:
- All docstrings now live in the `Pinecone` class implementation (single
source of truth)
- The interface was only used by `Pinecone` and provided no additional
value
- Eliminates the risk of documentation falling out of sync
6. **Updated Interface Classes**: Enhanced docstrings in
`IndexInterface` with proper RST formatting and added missing code-block
examples (e.g., `upsert_from_dataframe`).
## User-Facing Impact
### Positive Changes
- **Better Documentation**: Users now have comprehensive, well-formatted
documentation with realistic examples for all `Pinecone` class methods
- **Improved IDE Experience**: Better docstrings improve autocomplete
and inline help in IDEs
- **Consistent Formatting**: All documentation follows the same RST
format, making it easier to read and understand
- **Real-World Examples**: Code examples now demonstrate actual usage
patterns that users can directly adapt
### Breaking Changes
**None** - This is a documentation-only change. All method signatures
and behavior remain unchanged.
## Usage Examples
### Before
```python
# Minimal or missing docstrings
pc = Pinecone()
pc.create_index(...) # No clear guidance on usage
```
### After
```python
# Comprehensive documentation with examples
from pinecone import Pinecone, ServerlessSpec, CloudProvider, AwsRegion, Metric
pc = Pinecone()
# Clear examples showing different ways to create indexes
pc.create_index(
name="my_index",
dimension=512,
metric=Metric.COSINE,
spec=ServerlessSpec(
cloud=CloudProvider.AWS,
region=AwsRegion.US_WEST_2
)
)
```
### Improved Inference Example
The `inference` property now shows realistic usage:
```python
from pinecone import Pinecone
pc = Pinecone(api_key="your-api-key")
# Generate embeddings for text
embeddings = pc.inference.embed(
model="multilingual-e5-large",
inputs=["Disease prevention", "Immune system health"]
)
# Rerank documents based on query relevance
reranked = pc.inference.rerank(
model="bge-reranker-v2-m3",
query="Disease prevention",
documents=[
"Rich in vitamin C and other antioxidants, apples contribute to immune health...",
"The high fiber content in apples can also help regulate blood sugar levels...",
# ... more realistic examples
],
top_n=2,
rank_fields=["text"]
)
```
## Technical Details
- All docstrings now use RST syntax consistently
- Code-block examples include proper whitespace formatting (empty line
after code blocks)
- Fixed syntax errors in docstring examples (e.g., import statements)
- Removed `LegacyPineconeDBControlInterface` class and its file
- Updated `Pinecone` class to no longer inherit from the removed
interface
- Enhanced `IndexInterface` docstrings with proper formatting and
examples1 parent b21b9f9 commit db0418b
File tree
3 files changed
+917
-955
lines changed- pinecone
- db_data
3 files changed
+917
-955
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
252 | 279 | | |
253 | 280 | | |
254 | 281 | | |
| |||
276 | 303 | | |
277 | 304 | | |
278 | 305 | | |
279 | | - | |
| 306 | + | |
280 | 307 | | |
281 | 308 | | |
282 | 309 | | |
| |||
382 | 409 | | |
383 | 410 | | |
384 | 411 | | |
385 | | - | |
| 412 | + | |
386 | 413 | | |
387 | 414 | | |
388 | 415 | | |
| |||
0 commit comments