Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
sourceTag
to PineconeConfiguration
and additionalHeaders
to…
… data plane calls (#197) ## Problem We want to provide the ability for consumers to include a `source_tag` to identify the source of requests while using the client. Additionally, there are debugging and development scenarios where being able to pass additional headers with network requests would be convenient. ## Solution - Add `sourceTag` to `PineconeConfiguration`. Update `buildUserAgent()` to take in `PineconeConfiguration`, which should be available at all the points we call to build the agent. If `sourceTag` is provided it will be normalized, and inserted into the `User-Agent` header for all network requests with this format: `source_tag=<normalizeSourceTag>`. - Normalization rules: - Lowercase - Limit to charset `[a-z0-9_ ]` - Trim left/right space - Condense all spaces to one space and replace with `_` - Add `additionalHeaders` to the `Index` constructor. Custom headers can now be provided when targeting a specific index. `Index` now passes these headers to `VectorOperationsProvider` when setting up the API. - Update `VectorOperationsProvider` to apply `additionalHeaders` to the API `Configuration` when provided. ## Type of Change New feature, but specific to developer / support usage. - [X] New feature (non-breaking change which adds functionality) ## Test Plan New unit test files: - `indexOperationsBuilder.test.ts` - `user-agent.test.ts` New unit test for validating `additionalHeaders` is passed as expected, a bit of refactoring in `index.test.ts` which appears messier than it is. Running locally with `PINECONE_DEBUG=true` to make sure the custom headers / `sourceTag` are passed on requests when provided. ### Passing `integrationId` ```typescript import { Pinecone } from '@pinecone-database/pinecone' const pc = new Pinecone({ apiKey: 'your-api-key', sourceTag: 'test source tag' }); const index = pc.Index('my-index'); // Test control + data plane operations await pc.listIndexes(); await index.upsert(...); ``` ### Passing `additionalHeaders` to `Index` ```typescript import { Pinecone } from '@pinecone-database/pinecone' const pc = new Pinecone({ apiKey: 'your-api-key', sourceTag: 'test source tag' }); const index = pc.Index('my-index', undefined, { 'x-custom-header': 'header-value' }); // Make requests await index.upsert(...); ```
- Loading branch information