Skip to content

Update docstrings and type hints for Index and IndexAsyncio#535

Closed
jhamon wants to merge 1 commit intorelease-candidate/2025-10from
jhamon/index-improvements
Closed

Update docstrings and type hints for Index and IndexAsyncio#535
jhamon wants to merge 1 commit intorelease-candidate/2025-10from
jhamon/index-improvements

Conversation

@jhamon
Copy link
Collaborator

@jhamon jhamon commented Nov 4, 2025

Improve Index and IndexAsyncio classes: code quality and consistency

Summary

Improvements to the Index and IndexAsyncio classes for code quality, type safety, error handling, and documentation. Changes are non-breaking and maintain backward compatibility.

Changes Made

1. Fixed Mutable Default Argument

  • Files: pinecone/db_data/index.py, pinecone/db_data/index_asyncio.py
  • Changed additional_headers: Optional[Dict[str, str]] = {} to = None with initialization inside the method
  • Prevents shared mutable state issues

2. Fixed Outdated Comment

  • File: pinecone/db_data/index.py
  • Updated comment from "ImportFeatureMixin" to "PluginAware" to accurately reflect the parent class

3. Added Missing Documentation

  • Files: pinecone/db_data/index.py, pinecone/db_data/index_asyncio.py
  • Added RST-formatted docstring to upsert_records method with Args, Examples, and usage details

4. Added Validation Decorator

  • Files: pinecone/db_data/index.py, pinecone/db_data/index_asyncio.py
  • Added @validate_and_convert_errors decorator to upsert_records method for consistent error handling

5. Improved Type Hints

  • Files: pinecone/db_data/index.py, pinecone/db_data/index_asyncio.py
  • Changed records: List[Dict] to List[Dict[str, Any]] in upsert_records method for better type safety

6. Improved Exception Handling

  • Files: pinecone/db_data/index.py, pinecone/db_data/index_asyncio.py
  • Replaced generic raise Exception(...) with raise ValueError(...) in search methods for more appropriate exception types

Testing

  • ✅ No linting errors
  • ✅ Code compiles successfully
  • ✅ All changes maintain backward compatibility

Impact

  • Code Quality: Fixes mutable default argument anti-pattern
  • Type Safety: More specific type hints improve IDE support and type checking
  • Documentation: Complete API documentation for upsert_records method
  • Consistency: Both sync and async implementations now aligned
  • Error Handling: Consistent use of @validate_and_convert_errors decorator and appropriate exception types

Files Changed

  • pinecone/db_data/index.py
  • pinecone/db_data/index_asyncio.py

@jhamon jhamon closed this Nov 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant