Skip to content
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

Implement optional index tags in create_index and configure_index #426

Open
wants to merge 2 commits into
base: release-candidate/2025-01
Choose a base branch
from

Conversation

jhamon
Copy link
Collaborator

@jhamon jhamon commented Dec 19, 2024

Problem

Want to expose kwargs for setting and modifying index tags

Solution

The usual. The generated bits backing this feature already got created when I generated off the 2025-01 spec.

I added a small amount of logic to handle merging new and existing tags when using configure.

Usage

>>> from pinecone import Pinecone, ServerlessSpec
>>> pc = Pinecone(api_key='key')

# Create index with optional tags dictionary
>>> pc.create_index(
...   name='myindex',
...   dimension=10,
...   metric='cosine',
...   spec=ServerlessSpec(cloud='aws', region='us-west-2'),
...   vector_type='dense',
...   tags={'env': 'testing', 'author': 'jhamon'}
... )
>>> pc.describe_index(name='myindex')
{
    "name": "myindex",
    "metric": "cosine",
    "host": "myindex-dojoi3u.svc.apw5-4e34-81fa.pinecone.io",
    "spec": {
        "serverless": {
            "cloud": "aws",
            "region": "us-west-2"
        }
    },
    "status": {
        "ready": true,
        "state": "Ready"
    },
    "vector_type": "dense",
    "dimension": 10,
    "deletion_protection": "disabled",
    "tags": {
        "author": "jhamon",
        "env": "testing"
    }
}

# Update a tag value. This will be merged with existing tags.
>>> pc.configure_index(
...   name='myindex',
...   tags={'env': 'production'}
... )
>>> pc.describe_index(name='myindex')
{
    "name": "myindex",
    "metric": "cosine",
    "host": "myindex-dojoi3u.svc.apw5-4e34-81fa.pinecone.io",
    "spec": {
        "serverless": {
            "cloud": "aws",
            "region": "us-west-2"
        }
    },
    "status": {
        "ready": true,
        "state": "Ready"
    },
    "vector_type": "dense",
    "dimension": 10,
    "deletion_protection": "disabled",
    "tags": {
        "author": "jhamon",
        "env": "production"
    }
}

# Remove a tag by sending empty string value
>>> pc.configure_index(
...   name='myindex',
...   tags={'author': ''}
... )
>>> pc.describe_index(name='myindex')
{
    "name": "myindex",
    "metric": "cosine",
    "host": "myindex-dojoi3u.svc.apw5-4e34-81fa.pinecone.io",
    "spec": {
        "serverless": {
            "cloud": "aws",
            "region": "us-west-2"
        }
    },
    "status": {
        "ready": true,
        "state": "Ready"
    },
    "vector_type": "dense",
    "dimension": 10,
    "deletion_protection": "disabled",
    "tags": {
        "env": "production"
    }
}

Type of Change

  • New feature (non-breaking change which adds functionality)

@jhamon jhamon marked this pull request as ready for review December 19, 2024 15:51
@jhamon jhamon changed the title Implement index tags in create and configure index Implement optional index tags in create_index and configure_index Dec 19, 2024
Base automatically changed from jhamon/sparse-indexes to release-candidate/2025-01 December 19, 2024 16:27
Copy link
Contributor

@austin-denoble austin-denoble left a comment

Choose a reason for hiding this comment

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

LGTM

only nit is we may want to include a minimal amount of documentation about needing to use "" to delete / clear a tag

@@ -280,17 +288,31 @@ def configure_index(
replicas: Optional[int] = None,
pod_type: Optional[str] = None,
deletion_protection: Optional[Literal["enabled", "disabled"]] = None,
tags: Optional[Dict[str, str]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Should the docstring in the interface be updated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants