Skip to content

Conversation

@jhamon
Copy link
Collaborator

@jhamon jhamon commented Jan 6, 2026

Summary

This PR resolves a discrepancy in host handling between the REST (Pinecone) and gRPC (PineconeGRPC) clients. Previously, Pinecone.Index() validated and normalized host URLs, while PineconeGRPC.Index() did not, leading to inconsistent behavior and potential user errors.

Changes Made

Core Implementation

  • Added host validation to PineconeGRPC.Index() using check_realistic_host() to ensure provided hosts are valid URLs (not index names)
  • Added host normalization to PineconeGRPC.Index() using normalize_host() to automatically add the https:// protocol prefix when missing
  • Both validation and normalization now occur when a host is explicitly provided, matching the behavior of Pinecone.Index()

Implementation Details

The changes ensure that when a host is provided to PineconeGRPC.Index():

  1. Validation: The host is checked to ensure it contains a . (dot) or is localhost, preventing common mistakes where users accidentally pass an index name as the host parameter
  2. Normalization: The host is normalized to include a protocol prefix (https:// or http://), ensuring consistent URL formatting

The implementation reuses existing utility functions:

  • check_realistic_host() - Validates that the host string appears to be a valid hostname
  • normalize_host() - Ensures the host has a protocol prefix

Test Coverage

  • Added test_invalid_host() to verify that invalid hosts (like "invalid" or "my-index") raise appropriate ValueError exceptions
  • Updated existing test test_config_passed_when_target_by_host_and_port to use a valid hostname (myhost.example.com:4343 instead of myhost:4343) to comply with validation requirements

Why This Change Was Made

This change ensures consistency between both client implementations. Without host validation, users could accidentally pass index names as hosts, leading to cryptic DNS resolution errors later. The normalization ensures that hosts are properly formatted regardless of whether users include the protocol prefix, making the API more user-friendly and consistent.

Result

Both Pinecone.Index() and PineconeGRPC.Index() now:

  • Validate that provided hosts are valid (contain a . or are localhost)
  • Normalize hosts by adding https:// prefix if no protocol is present
  • Handle hosts consistently whether provided directly or fetched by index name

This PR was generated with Vibe Kanban and Cursor.

jhamon added 2 commits January 5, 2026 13:29
Resolved the host handling discrepancy between `Pinecone.Index()` and `PineconeGRPC.Index()`.

### Changes Made:

1. **Updated `pinecone/grpc/pinecone.py`**:
   - Added imports for `normalize_host` from `pinecone.utils` and `check_realistic_host` from `pinecone.pinecone`
   - Updated the `Index()` method to validate and normalize the host when provided, matching `Pinecone.Index()`:
     - Validates the host using `check_realistic_host()` to ensure it's a valid host URL (not an index name)
     - Normalizes the host using `normalize_host()` to ensure it has a protocol prefix (`https://` or `http://`)

2. **Added test coverage** in `tests/unit_grpc/test_grpc_index_initialization.py`:
   - Added `test_invalid_host()` to verify that invalid hosts raise appropriate errors, matching the test for the regular Pinecone client

### Result:

Both `Pinecone.Index()` and `PineconeGRPC.Index()` now:
- Validate that provided hosts are valid (contain a "." or "localhost")
- Normalize hosts by adding "https://" prefix if no protocol is present
- Handle hosts consistently whether provided directly or fetched by index name

The implementation is now consistent between both clients, ensuring proper host validation and normalization in all cases.
## Summary

Fixed a test failure found during CI checks:

### Issue Found:
The test `test_config_passed_when_target_by_host_and_port` was failing because it used `host="myhost:4343"`, which doesn't pass the `check_realistic_host` validation (it requires a "." in the hostname or "localhost").

### Fix Applied:
Updated the test to use a valid hostname: `myhost.example.com:4343` instead of `myhost:4343`. This maintains the test's intent (testing hosts with port numbers) while using a valid hostname.

### Test Results:
- All 8 tests in `test_grpc_index_initialization.py` pass
- Linting passes
- Type checking passes

### Current Status:
- No PR exists for branch `vk/e239-resolve-descrepa` yet
- All local checks pass
- Code is ready for PR creation

The changes are committed and ready. If you want, I can help create a PR or check for any other issues.
@jhamon jhamon changed the title Resolve descrepancy in host handling (vibe-kanban) Add host validation and normalization to PineconeGRPC.Index() Jan 6, 2026
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