-
Notifications
You must be signed in to change notification settings - Fork 115
feat: extract IndexModel spec resolution to adapter layer (SDK-276) #606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add formal Protocol interfaces that define the contract between OpenAPI models and SDK adapters. This improves type safety, documentation, and maintainability without any breaking changes. - Created pinecone/adapters/protocols.py with 5 Protocol definitions - Updated adapter functions to use protocol type annotations - Added 13 unit tests verifying protocol compliance - All tests pass, mypy validates protocol usage Related: SDK-275 Co-authored-by: Cursor <cursoragent@cursor.com>
Changed FetchResponseAdapter.namespace from `str` to `str | None` to correctly reflect that the OpenAPI FetchResponse model marks namespace as optional. Updated the adapter function to handle None namespace by converting it to empty string, consistent with QueryResponse adapter. - Updated protocol type annotation - Added null-coalescing in adapter function - Added test for None namespace case Fixes Cursor Bugbot issue Co-authored-by: Cursor <cursoragent@cursor.com>
Create adapter infrastructure for IndexModel spec handling, isolating SDK code from OpenAPI model internals and preparing for future API format changes. Changes: - Add pinecone/adapters/index_adapter.py with adapt_index_spec() function - Extract 150+ lines of complex oneOf resolution logic from IndexModel - Handle serverless/pod/byoc specs with proper optional field support - Simplify IndexModel from 176 to 40 lines by delegating to adapter - Add comprehensive unit tests for all spec types and edge cases - Maintain 100% backward compatibility with existing behavior The adapter properly handles: - Optional fields (read_capacity, source_collection, schema) - Nested oneOf types (ReadCapacity with OnDemand/Dedicated modes) - Type compatibility between request and response models - Caching behavior in IndexModel wrapper Closes SDK-276 Co-authored-by: Cursor <cursoragent@cursor.com>
…port Address Cursor Bugbot feedback: - Fix: preserve already-deserialized read_capacity values instead of replacing with None - Refactor: remove IndexStatusAdapter from public exports (still used in tests for protocol compliance) Co-authored-by: Cursor <cursoragent@cursor.com>
|
Fixed both issues in commit 543743a: Issue 1 (Medium): Changed read_capacity initialization to preserve already-deserialized values: # Before: read_capacity_spec = None
# After:
read_capacity_spec = serverless_dict.get("read_capacity")Issue 2 (Low): Removed IndexStatusAdapter from public |
jhamon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed both Bugbot issues in commit 543743a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| _path_to_item=spec_path + ["serverless"], | ||
| _configuration=config, | ||
| _spec_property_naming=False, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nested schema field not deserialized when passed as dict
Medium Severity
The _adapt_serverless_spec function explicitly deserializes read_capacity when it's a dict, but passes schema directly to ServerlessSpecResponse._from_openapi_data() without deserialization. The original code used deserialize_model() on the entire serverless_dict, which recursively converted all nested dicts to their proper types. If the spec comes as a raw dict (the scenario this adapter handles), the nested schema field would also be a raw dict that won't be converted to a BackupModelSchema instance.


Phase 2C: Index Model Adapter
Problem
The
IndexModelwrapper class directly accessed internal OpenAPI model properties (_data_store,_configuration,_path_to_item) and contained complex spec resolution logic (150+ lines) for handling oneOf schemas (serverless/pod/byoc). This tight coupling made the code fragile and difficult to extend for future API format changes.Solution
Created an adapter layer that extracts the complex spec resolution logic from the
IndexModelwrapper, isolating SDK code from OpenAPI model internals.Changes Made
New Files:
pinecone/adapters/index_adapter.py- Adapter functions for IndexModel spec resolutionadapt_index_spec()- Main adapter function that handles oneOf resolution_adapt_serverless_spec()- Handles serverless spec with optional ReadCapacity_adapt_pod_spec()- Handles pod-based spec_adapt_byoc_spec()- Handles BYOC spectests/unit/adapters/test_index_adapter.py- Comprehensive unit testsModified Files:
pinecone/db_control/models/index_model.py- Simplified from 176 to 40 linesadapt_index_spec()adapterpinecone/adapters/__init__.py- Added exports for new adapter functionImplementation Details
Spec Resolution
The adapter handles OpenAPI oneOf schema resolution for three index spec types:
read_capacityfield (OnDemand/Dedicated modes)The adapter properly handles:
read_capacity,source_collection,schema)Design Decisions
Anyfor return types to handle oneOf variants that don't share a common accessible base type_check_typewhen constructing oneOf wrappers due to response/request model differencesschema.fields.embedding) when it becomes availableTesting
mypy pineconeExample test coverage:
User-Facing Impact
No breaking changes. This is an internal refactoring that:
Related
Made with Cursor
Note
Medium Risk
Medium risk because it changes how
IndexModel.specand response fields are deserialized/defaulted; incorrect oneOf detection or defaults could subtly alter returned SDK objects, though coverage is added via new unit tests.Overview
Moves
IndexModel.speconeOf deserialization (serverless/pod/BYOC, including nestedread_capacity) out of theIndexModelwrapper into a new adapteradapt_index_spec, and exports it viapinecone.adapters.Introduces formal adapter
Protocols for OpenAPI models and updates query/upsert/fetch response adapters to use these types and to gracefully default optional/None fields (matches/namespace/vectors/upserted_count) to empty values. Adds/updates unit tests and fixtures to validate protocol compliance and None-handling behavior.Written by Cursor Bugbot for commit 543743a. This will update automatically on new commits. Configure here.