-
Notifications
You must be signed in to change notification settings - Fork 114
feat: add request translator for spec to deployment + schema #585
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
feat: add request translator for spec to deployment + schema #585
Conversation
af995df to
f8907ce
Compare
f8907ce to
82c2373
Compare
## Summary
Add deployment model classes for different index deployment
configurations.
Closes SDK-103
## Classes
| Class | Deployment Type | Key Parameters |
|-------|-----------------|----------------|
| `ServerlessDeployment` | `serverless` | `cloud`, `region` |
| `ByocDeployment` | `byoc` | `environment` |
| `PodDeployment` | `pod` | `environment`, `pod_type`, `replicas`,
`shards` |
## Usage Example
```python
from pinecone import ServerlessDeployment, ByocDeployment, PodDeployment
# Serverless deployment
pc.create_index(
name="my-index",
schema=schema,
deployment=ServerlessDeployment(cloud="aws", region="us-east-1"),
)
# BYOC deployment
pc.create_index(
name="my-index",
schema=schema,
deployment=ByocDeployment(environment="aws-us-east-1-b92"),
)
# Pod deployment
pc.create_index(
name="my-index",
schema=schema,
deployment=PodDeployment(
environment="us-east-1-aws",
pod_type="p1.x1",
replicas=2,
),
)
```
## Test Plan
- [x] Unit tests for ServerlessDeployment serialization
- [x] Unit tests for ByocDeployment serialization
- [x] Unit tests for PodDeployment with various options
- [x] mypy type checking passes
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Low risk: this PR only adds new model/dataclass types and exports
them; it doesn’t change existing request flows, but downstream code may
start relying on the new `to_dict` serialization format.
>
> **Overview**
> Adds new deployment configuration dataclasses (`ServerlessDeployment`,
`ByocDeployment`, `PodDeployment`) with `to_dict()` serialization and a
`Deployment` union type in `db_control/models/deployment.py`.
>
> Exports these types through `pinecone.db_control.models` and top-level
`pinecone` lazy imports, and adds unit tests validating constructor
defaults and `to_dict()` output across deployment variants.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
c2e965d. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Replace complex manual module loading with standard imports. The deployment classes are properly exported via pinecone/__init__.py, so standard imports work fine and are more maintainable.
aad1244 to
6b4360f
Compare
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.
| serverless_spec = spec["serverless"] | ||
| # Convert enum values to strings for consistency with __parse_index_spec | ||
| cloud = convert_enum_to_string(serverless_spec.get("cloud", "")) | ||
| region = convert_enum_to_string(serverless_spec.get("region", "")) |
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.
Dict specs with missing required fields return invalid data
Low Severity
When dict-based specs are missing required fields like cloud, region, or environment, the method silently defaults to empty strings instead of failing. This differs from __parse_index_spec which directly accesses these keys (raising KeyError if absent). A dict like {"serverless": {"region": "us-east-1"}} missing cloud would return a deployment with cloud: "", causing a confusing API error later instead of an immediate SDK error.
Summary
Adds
_translate_legacy_request()method toPineconeDBControlRequestFactorythat converts legacy spec-based index creation parameters to the new deployment + schema format required by the alpha API.Problem
The new Full-Text Search API uses a different structure for index creation:
spec(ServerlessSpec/PodSpec/ByocSpec) with top-leveldimensionandmetricparametersdeployment(withdeployment_type) andschema(with field definitions)To maintain backward compatibility while supporting the new API, we need translation logic that converts the old format to the new format.
Solution
Added
_translate_legacy_request()static method that:Converts spec types to deployment:
ServerlessSpec(cloud, region)→{"deployment_type": "serverless", "cloud": ..., "region": ...}PodSpec(environment, ...)→{"deployment_type": "pod", "environment": ..., ...}ByocSpec(environment)→{"deployment_type": "byoc", "environment": ...}Converts vector parameters to schema:
dimension+metric+vector_type="dense"→schema.fields._values(dense_vector field)vector_type="sparse"→schema.fields._sparse_values(sparse_vector field)Provides sensible defaults:
Validates inputs:
dimensionfor dense vector indexesUsage Example
Testing
Added comprehensive unit tests covering:
Related Issues
Value
This translation layer enables backward compatibility by allowing existing code using the legacy
spec-based API to work with the new schema-based API. It's a critical building block for the FTS feature set, as it allows the SDK to support both old and new index creation patterns seamlessly.Note
Medium Risk
Medium risk because it introduces new translation/validation logic that will shape index-creation payloads (including defaults and error conditions) and could affect backward-compatibility behavior if edge cases differ from the legacy format.
Overview
Adds
PineconeDBControlRequestFactory._translate_legacy_request()to convert legacy index creation inputs (specplusdimension/metric/vector_type) into the newdeploymentandschema.fieldsstructures, including enum-to-string normalization, sensible metric defaults (dense→cosine, sparse→dotproduct), and stricter validation (e.g., dense requiresdimension, invalidvector_typeerrors).Expands unit coverage for the translator across serverless/pod/BYOC (object and dict specs), defaulting behavior, zero-value preservation, and error cases; also simplifies
test_deployment.pyto import deployment models directly frompineconeinstead of dynamically loading the module.Written by Cursor Bugbot for commit 6b4360f. This will update automatically on new commits. Configure here.