Skip to content

Conversation

@jhamon
Copy link
Collaborator

@jhamon jhamon commented Jan 28, 2026

Summary

Adds _translate_legacy_request() method to PineconeDBControlRequestFactory that 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:

  • Old format: Uses spec (ServerlessSpec/PodSpec/ByocSpec) with top-level dimension and metric parameters
  • New format: Uses deployment (with deployment_type) and schema (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:

  1. 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": ...}
  2. 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)
  3. Provides sensible defaults:

    • Defaults to "cosine" metric for dense vectors
    • Defaults to "dotproduct" metric for sparse vectors
  4. Validates inputs:

    • Requires dimension for dense vector indexes
    • Raises clear errors for invalid spec types

Usage Example

from pinecone.db_control.request_factory import PineconeDBControlRequestFactory
from pinecone import ServerlessSpec

# Translate legacy request format
deployment, schema = PineconeDBControlRequestFactory._translate_legacy_request(
    spec=ServerlessSpec(cloud="aws", region="us-east-1"),
    dimension=1536,
    metric="cosine",
    vector_type="dense"
)

# Returns:
# deployment = {"deployment_type": "serverless", "cloud": "aws", "region": "us-east-1"}
# schema = {"fields": {"_values": {"type": "dense_vector", "dimension": 1536, "metric": "cosine"}}}

Testing

Added comprehensive unit tests covering:

  • All spec types (Serverless, Pod, BYOC)
  • Both object and dict-based spec formats
  • Dense and sparse vector translations
  • Default metric handling
  • Edge cases (missing dimension, invalid spec types)

Related Issues

  • Linear: SDK-104
  • Part of the Full-Text Search SDK implementation

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 (spec plus dimension/metric/vector_type) into the new deployment and schema.fields structures, including enum-to-string normalization, sensible metric defaults (dense→cosine, sparse→dotproduct), and stricter validation (e.g., dense requires dimension, invalid vector_type errors).

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.py to import deployment models directly from pinecone instead of dynamically loading the module.

Written by Cursor Bugbot for commit 6b4360f. This will update automatically on new commits. Configure here.

@jhamon jhamon force-pushed the jhamon/sdk-104-request-translator-spec-to-deployment-schema branch 2 times, most recently from af995df to f8907ce Compare January 28, 2026 19:49
@jhamon jhamon force-pushed the jhamon/sdk-104-request-translator-spec-to-deployment-schema branch from f8907ce to 82c2373 Compare January 28, 2026 19:55
## 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.
@jhamon jhamon force-pushed the jhamon/sdk-104-request-translator-spec-to-deployment-schema branch from aad1244 to 6b4360f Compare January 28, 2026 20:23
Copy link

@cursor cursor bot left a 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", ""))
Copy link

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.

Additional Locations (2)

Fix in Cursor Fix in Web

@jhamon jhamon merged commit cdf5cca into fts Jan 28, 2026
7 checks passed
@jhamon jhamon deleted the jhamon/sdk-104-request-translator-spec-to-deployment-schema branch January 28, 2026 20:34
@jhamon jhamon added the python Pull requests that update Python code label Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants