Skip to content

Conversation

@jhamon
Copy link
Collaborator

@jhamon jhamon commented Nov 18, 2025

Problem

Response headers were being filtered to exclude timing-dependent headers (x-envoy-upstream-service-time, date, x-request-id) to avoid test flakiness. However, these headers can be useful for debugging, monitoring, and understanding request behavior in production environments.

Additionally, the extract_response_info function was importing modules on every request and performing unnecessary checks, creating performance overhead for a function that runs on every API call.

Solution

Remove header filtering so all response headers are preserved in _response_info for REST, asyncio, and gRPC requests. This provides complete header information while maintaining correct equality comparisons (response dataclasses already exclude _response_info from equality checks).

Also optimize extract_response_info performance by moving imports to module level and removing unnecessary conditional checks.

Changes

Response Info Extraction (response_info.py)

  • Removed filtering of timing-dependent headers (x-envoy-upstream-service-time, date, x-request-id)
  • Optimized value conversion to check string type first (most common case)
  • Updated documentation to reflect that all headers are now included

REST API Clients (api_client.py, asyncio_api_client.py)

  • Moved extract_response_info import to module level to eliminate import overhead on every request
  • Removed unnecessary if response_info: check since the function always returns a dict

Performance Improvements

  • Eliminated import overhead by moving imports to module level
  • Removed unnecessary conditional checks
  • Optimized type checking order for header value conversion (check string type first)

These optimizations are especially beneficial for high-throughput applications making many API calls.

Usage Example

No changes required for users - the API remains the same:

from pinecone import Pinecone

pc = Pinecone(api_key="your-api-key")
index = pc.Index("my-index")

# All response headers are now available in _response_info
upsert_response = index.upsert(vectors=[...])
print(upsert_response._response_info["raw_headers"])
# Now includes all headers: date, x-envoy-upstream-service-time, 
# x-request-id, x-pinecone-request-lsn, etc.

query_response = index.query(vector=[...])
print(query_response._response_info["raw_headers"])
# Includes all headers from query response

Testing

  • All existing unit tests pass (414+ tests)
  • Integration tests verify response info functionality with all headers included
  • LSN header extraction tests confirm all headers are preserved
  • Tests access headers flexibly using .get("raw_headers", {}), so they continue to work with additional headers

Breaking Changes

None. This is a transparent improvement with no API changes. Response object equality comparisons are unaffected since _response_info already has compare=False in all response dataclasses (QueryResponse, UpsertResponse, UpdateResponse, FetchResponse, FetchByMetadataResponse).

@jhamon jhamon marked this pull request as ready for review November 18, 2025 15:18
@jhamon jhamon merged commit a445f09 into release-candidate/2025-10 Nov 18, 2025
27 checks passed
@jhamon jhamon deleted the jhamon/preserve-all-headers branch November 18, 2025 15:18
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