Commit a445f09
authored
Preserve all headers in response info (#559)
## 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:
```python
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`).1 parent d391c9a commit a445f09
File tree
4 files changed
+43
-48
lines changed- pinecone
- openapi_support
- utils
4 files changed
+43
-48
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
208 | 209 | | |
209 | 210 | | |
210 | 211 | | |
211 | | - | |
212 | | - | |
213 | 212 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
221 | 218 | | |
222 | 219 | | |
223 | 220 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
173 | 174 | | |
174 | 175 | | |
175 | 176 | | |
176 | | - | |
177 | | - | |
178 | 177 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
186 | 183 | | |
187 | 184 | | |
188 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
498 | 498 | | |
499 | 499 | | |
500 | 500 | | |
501 | | - | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
502 | 507 | | |
503 | | - | |
| 508 | + | |
| 509 | + | |
504 | 510 | | |
505 | 511 | | |
506 | 512 | | |
| |||
653 | 659 | | |
654 | 660 | | |
655 | 661 | | |
656 | | - | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
657 | 668 | | |
658 | | - | |
| 669 | + | |
| 670 | + | |
659 | 671 | | |
660 | 672 | | |
661 | 673 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | 5 | | |
16 | 6 | | |
17 | 7 | | |
| |||
26 | 16 | | |
27 | 17 | | |
28 | 18 | | |
29 | | - | |
30 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
31 | 22 | | |
32 | 23 | | |
33 | 24 | | |
| |||
47 | 38 | | |
48 | 39 | | |
49 | 40 | | |
50 | | - | |
51 | | - | |
| 41 | + | |
| 42 | + | |
52 | 43 | | |
53 | 44 | | |
54 | 45 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
66 | 55 | | |
67 | 56 | | |
0 commit comments