Skip to content

Conversation

@jhamon
Copy link
Collaborator

@jhamon jhamon commented Jan 28, 2026

Summary

Add SchemaBuilder class that provides a fluent, chainable API for building index schemas.

Closes SDK-102

API

Method Description
.text(name, ...) Add text field with filterable, full_text_searchable options
.integer(name, ...) Add integer field with filterable option
.float(name, ...) Add float field with filterable option
.dense_vector(name, dimension, metric, ...) Add dense vector field
.sparse_vector(name, ...) Add sparse vector field
.semantic_text(name, model, field_map, ...) Add semantic text field with inference
.build() Returns the final schema dictionary

Usage Example

from pinecone import SchemaBuilder

schema = (SchemaBuilder()
    .text("title", full_text_searchable=True)
    .integer("year", filterable=True)
    .dense_vector("embedding", dimension=1536, metric="cosine")
    .build())

pc.create_index(name="my-index", schema=schema, ...)

Test Plan

  • Unit tests for each field type method (18 tests)
  • Tests for method chaining
  • Tests for empty schema validation
  • Tests for field overwriting behavior
  • mypy type checking passes

Note

Low Risk
Low risk, additive change that introduces a new helper class and exports it via existing lazy-import/public-module surfaces without modifying request/serialization logic.

Overview
Introduces SchemaBuilder, a fluent, chainable helper for building index schema dictionaries from existing field types (TextField, DenseVectorField, SemanticTextField, etc.), including validation that prevents building an empty schema.

Exports SchemaBuilder via pinecone.db_control.models and the top-level pinecone lazy imports, and adds focused unit tests for each field type, option serialization, chaining behavior, and overwrite semantics.

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

Add SchemaBuilder class that provides a chainable API for building
index schemas:
- .text() - add text field with filterable/full_text_searchable options
- .integer() - add integer field with filterable option
- .float() - add float field with filterable option
- .dense_vector() - add dense vector field with dimension/metric
- .sparse_vector() - add sparse vector field
- .semantic_text() - add semantic text field with model configuration
- .build() - returns the final schema dictionary

Closes SDK-102
@jhamon jhamon marked this pull request as ready for review January 28, 2026 18:22
@jhamon jhamon added the enhancement New feature or request label Jan 28, 2026
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.

)
sys.modules[schema_fields_name] = schema_fields
with open(schema_fields.__file__) as f:
exec(compile(f.read(), schema_fields.__file__, "exec"), schema_fields.__dict__)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated module loading logic in test file

Low Severity

The _load_schema_builder_module() function duplicates the schema_fields loading logic (lines 12-27) that already exists in test_schema_fields.py as _load_schema_fields_module(). Both implementations create a module, set its file path, register it in sys.modules, and exec the file contents. This duplicated workaround code increases maintenance burden - if the loading approach needs to change, it must be updated in multiple places.

Fix in Cursor Fix in Web

@jhamon jhamon merged commit 578ec5c into fts Jan 28, 2026
7 checks passed
@jhamon jhamon deleted the jhamon/sdk-102-schemabuilder-fluent-api branch January 28, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants