Expose LSN Header Information #539
Merged
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.
Expose LSN Header Information in API Responses
Overview
This PR implements exposure of LSN (Log Sequence Number) header information from Pinecone API responses through a new
_response_infoattribute on response objects. This enables faster test suite execution by using LSN-based freshness checks instead of pollingdescribe_index_stats().Motivation
Integration tests currently rely on polling
describe_index_stats()to verify data freshness, which is slow and inefficient. The Pinecone API includes LSN headers in responses that can be used to determine data freshness more efficiently:x-pinecone-request-lsn: Committed LSN from write operations (upsert, delete)x-pinecone-max-indexed-lsn: Reconciled LSN from read operations (query)By extracting and exposing these headers, tests can use LSN-based polling to reduce test execution time significantly. Testing so far shows this will cut the time needed to run db data plane integration times down by half or more.
Changes
Core Implementation
Response Info Module
pinecone/utils/response_info.pywith:ResponseInfoTypedDict for structured response metadataextract_response_info()function to extract and normalize raw headersraw_headers(dictionary of all response headers normalized to lowercase)lsn_utils) rather than inResponseInfoREST API Client Integration
api_client.pyandasyncio_api_client.pyto automatically attach_response_infoto db data plane response objects_response_infoto ensureraw_headersare always available, even when LSN fields are not presentgRPC Integration
grpc_runner.pyto capture initial metadata from gRPC callsgrpc/utils.pyto accept optionalinitial_metadataparameterindex_grpc.pyto pass initial metadata to parser functionsfuture.pyto extract initial metadata from gRPC futuresResponse Dataclasses
QueryResponseandUpsertResponsedataclasses inpinecone/db_data/dataclasses/_response_infofield toFetchResponse,FetchByMetadataResponse,QueryResponse, andUpsertResponseDictLikefor dictionary-style access_response_infois a required field (always present) with default{"raw_headers": {}}Index Classes
index.pyandindex_asyncio.pyto:_response_infoattachedasync_req=TruewithApplyResultwrapper for proper dataclass conversion_response_infofromupsert_records()responsesTest Infrastructure
LSN Utilities
tests/integration/helpers/lsn_utils.pywith helper functions for extracting LSN valuespinecone/utils/lsn_utils.py(deprecated)Polling Helpers
poll_until_lsn_reconciled()to use query operations for LSN-based freshness checkspoll_until_lsn_reconciled_async()for async testsIntegration Test Updates
test_query.py,test_upsert_dense.py,test_search_and_upsert_records.pytest_fetch.py,test_fetch_by_metadata.py,test_upsert_hybrid.pytest_query_namespaces.py,seed.pytest_query.py(async)_response_infois present when expectedDocumentation
docs/maintainers/lsn-headers-discovery.mddocumenting discovered headersscripts/inspect_lsn_headers.pyfor header discoveryUsage Examples
Accessing Response Info
The
_response_infoattribute is always available on all Index response objects:Dictionary-Style Access
All response dataclasses inherit from
DictLike, enabling dictionary-style access:Technical Details
Response Info Flow
REST API:
api_client.pyextracts → attaches_response_infoto OpenAPI model → Index classes convert to dataclassesgRPC:
grpc_runner.pycaptures → parser functions extract → attach_response_infoto response objectsBackward Compatibility
_response_infois always present on response objects (required field)raw_headersin_response_infoalways contains response headers (may be empty dict if no headers)poll_until_lsn_reconciled,poll_until_lsn_reconciled_async) accept_response_infodirectly and extract LSN internallyType Safety
_response_infofieldstype: ignorecomments where necessary (e.g.,ApplyResultwrapping)Dataclass Enhancements
DictLikefor dictionary-style accessQueryResponseandUpsertResponseare new dataclasses replacing OpenAPI models_response_infofield:ResponseInfo = field(default_factory=lambda: cast(ResponseInfo, {"raw_headers": {}}), repr=True, compare=False)repr=Truefor all response dataclasses to aid debuggingraw_headersalways contains response headers (may be empty dict)ResponseInfoonly containsraw_headersTesting
Unit Tests
extract_response_info()functionIntegration Tests
_response_infoassertions added to verify LSN data is presentBreaking Changes
None - This is a backward-compatible enhancement.
Response Type Changes
QueryResponseandUpsertResponseare now dataclasses instead of OpenAPI modelsDictLike)from pinecone import QueryResponse, UpsertResponse)isinstance()checks against OpenAPI models, they should still work when importing frompineconeNew Attribute
_response_infois added to all Index response objects (QueryResponse,UpsertResponse,FetchResponse,FetchByMetadataResponse)_response_infois always present and containsraw_headers.Compatibility Notes
DictLike, enabling dictionary-style access (response['matches'])response.matches,response.namespace, etc.)to_dict()were not part of the public APIRelated Issues