Add host validation and normalization to PineconeGRPC.Index() #573
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, whilePineconeGRPC.Index()did not, leading to inconsistent behavior and potential user errors.Changes Made
Core Implementation
PineconeGRPC.Index()usingcheck_realistic_host()to ensure provided hosts are valid URLs (not index names)PineconeGRPC.Index()usingnormalize_host()to automatically add thehttps://protocol prefix when missingPinecone.Index()Implementation Details
The changes ensure that when a host is provided to
PineconeGRPC.Index():.(dot) or islocalhost, preventing common mistakes where users accidentally pass an index name as the host parameterhttps://orhttp://), ensuring consistent URL formattingThe implementation reuses existing utility functions:
check_realistic_host()- Validates that the host string appears to be a valid hostnamenormalize_host()- Ensures the host has a protocol prefixTest Coverage
test_invalid_host()to verify that invalid hosts (like"invalid"or"my-index") raise appropriateValueErrorexceptionstest_config_passed_when_target_by_host_and_portto use a valid hostname (myhost.example.com:4343instead ofmyhost:4343) to comply with validation requirementsWhy 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()andPineconeGRPC.Index()now:.or arelocalhost)https://prefix if no protocol is presentThis PR was generated with Vibe Kanban and Cursor.