Commit 79a4281
authored
feat: add IndexModel compatibility shims for alpha API (#590)
## Summary
This PR adds backward compatibility properties to `IndexModel` that map
old-style accessor patterns to the new alpha API structure, ensuring
existing code continues to work with the new API.
## Problem
The alpha API (2026-01.alpha) has a different response structure than
the previous API (2025-10):
- **Old structure**: `spec` (with `serverless`/`pod`/`byoc` nested),
`dimension`, `metric`, `vector_type` at the top level
- **New structure**: `deployment` (with `deployment_type`, `cloud`,
`region`, etc.), `schema` (with `fields` containing vector field
configurations)
Existing user code that accesses `index.spec.serverless.cloud` or
`index.dimension` would break with the new API.
## Solution
Add compatibility shims to `IndexModel` that provide the old-style
access patterns:
1. **`spec` property**: Returns a `CompatibilitySpec` that builds the
old `.spec.serverless`/`.spec.pod`/`.spec.byoc` access patterns from the
new `deployment` data
2. **`dimension` property**: Extracts dimension from `schema.fields`
(finds dense vector field)
3. **`metric` property**: Extracts metric from `schema.fields` (finds
vector field with metric)
4. **`vector_type` property**: Returns "dense" or "sparse" based on
vector field type, or None for FTS-only indexes
## Usage Examples
```python
# New alpha API format with schema and deployment
index = pc.describe_index("my-index")
# Old-style access still works via compatibility shims
print(index.spec.serverless.cloud) # "aws" - via CompatibilitySpec
print(index.spec.serverless.region) # "us-east-1"
print(index.dimension) # 1536 - extracted from schema.fields
print(index.metric) # "cosine" - extracted from schema.fields
print(index.vector_type) # "dense" - derived from field type
# New-style access also works directly
print(index.deployment.cloud) # "aws"
print(index.schema.fields) # Field configurations
```
## Handling FTS-Only Indexes
Indexes with only text fields (no vectors) return `None` for vector
properties:
```python
fts_index = pc.describe_index("fts-only-index")
print(fts_index.dimension) # None
print(fts_index.metric) # None
print(fts_index.vector_type) # None
print(fts_index.spec.serverless.cloud) # "aws" - spec still works
```
## Test Plan
- [x] Unit tests for `CompatibilitySpec` with serverless/pod/byoc
deployments
- [x] Unit tests for `IndexModel` dimension/metric/vector_type
extraction
- [x] Unit tests for FTS-only indexes returning None for vector
properties
- [x] Unit tests for dict-style access (`index["dimension"]`)
- [x] Mypy type checking passes
## Related Issues
- Linear: SDK-107
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes `IndexModel` attribute resolution for
`spec`/`dimension`/`metric`/`vector_type`, which may affect callers
depending on prior `spec` parsing behavior when `deployment`/`schema`
are missing or shaped differently. The logic is straightforward and
covered by new unit tests, but it touches a commonly used wrapper.
>
> **Overview**
> Adds a new `CompatibilitySpec` wrapper (plus
`ServerlessSpecCompat`/`PodSpecCompat`/`ByocSpecCompat`) to recreate
legacy `.spec.serverless`/`.spec.pod`/`.spec.byoc` access from the alpha
API’s `deployment` object.
>
> Updates `IndexModel` to provide backward-compatible `dimension`,
`metric`, and `vector_type` by extracting vector field info from
`schema.fields` (including sparse-vector and FTS-only cases), and
replaces the previous complex `spec` deserialization logic with the new
deployment-based shim.
>
> Exports the new compatibility classes from
`pinecone.db_control.models` and expands unit tests to cover
serverless/pod/byoc deployments, sparse vectors, FTS-only indexes, and
dict-style access.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
8b4b59d. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->4 files changed
Lines changed: 574 additions & 174 deletions
File tree
- pinecone/db_control/models
- tests/unit/models
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
25 | 31 | | |
26 | 32 | | |
27 | 33 | | |
| |||
51 | 57 | | |
52 | 58 | | |
53 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
54 | 64 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
0 commit comments