Skip to content

Commit

Permalink
remove environment and projectId from PineconeConfiguration, update a…
Browse files Browse the repository at this point in the history
…ssociated unit tests and comments
  • Loading branch information
austin-denoble committed Oct 26, 2023
1 parent 1fbbf2b commit eb36f2b
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 313 deletions.
3 changes: 0 additions & 3 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ inputs:
pinecone_api_key:
description: 'API key'
required: true
pinecone_environment:
description: 'Environment/region to target'
required: true
runs:
using: 'composite'
steps:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ jobs:
run: npm run test:integration:cleanup
env:
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
PINECONE_ENVIRONMENT: ${{ secrets.PINECONE_ENVIRONMENT }}
5 changes: 0 additions & 5 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ on:
secrets:
PINECONE_API_KEY:
required: true
PINECONE_ENVIRONMENT:
required: true

jobs:
basic-hygiene:
Expand Down Expand Up @@ -53,7 +51,6 @@ jobs:
env:
CI: true
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
PINECONE_ENVIRONMENT: ${{ secrets.PINECONE_ENVIRONMENT }}
run: npm run test:integration:${{ matrix.jest_env }}

example-app-semantic-search:
Expand Down Expand Up @@ -86,7 +83,6 @@ jobs:
env:
CI: true
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
PINECONE_ENVIRONMENT: ${{ secrets.PINECONE_ENVIRONMENT }}
PINECONE_INDEX: 'semantic-search'
shell: bash
run: |
Expand Down Expand Up @@ -147,7 +143,6 @@ jobs:
shell: bash
env:
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
PINECONE_ENVIRONMENT: ${{ secrets.PINECONE_ENVIRONMENT }}
run: |
set -x
cd ..
Expand Down
48 changes: 5 additions & 43 deletions src/__tests__/pinecone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,17 @@ jest.mock('../data/upsert');
describe('Pinecone', () => {
describe('constructor', () => {
describe('required properties', () => {
test('should throw an error if no properties provided', () => {
test('should throw an error if apiKey is not provided', () => {
expect(() => {
new Pinecone({} as PineconeConfiguration);
}).toThrow(
'The client configuration must have required properties: environment, apiKey.'
);
});

test('should throw an error if required property not provided', () => {
expect(() => {
new Pinecone({ apiKey: 'test-key' } as PineconeConfiguration);
}).toThrow(
'The client configuration must have required property: environment.'
);

expect(() => {
new Pinecone({
environment: 'test-environment',
} as PineconeConfiguration);
}).toThrow(
'The client configuration must have required property: apiKey.'
);
});

test('should throw an error if required properties are blank', () => {
expect(() => {
new Pinecone({
environment: '',
projectId: '',
apiKey: 'test-key',
});
}).toThrow(
"The client configuration had validation errors: property 'environment' must not be blank, property 'projectId' must not be blank."
);

test('should throw an error if apiKey is blank', () => {
expect(() => {
const config = {
environment: 'test-env',
apiKey: '',
} as PineconeConfiguration;
new Pinecone(config);
Expand All @@ -69,9 +42,7 @@ describe('Pinecone', () => {
test('should throw an error if unknown property provided', () => {
expect(() => {
new Pinecone({
environment: 'test-env',
apiKey: 'test-key',
projectId: 'test-proj',
unknownProp: 'banana',
} as PineconeConfiguration);
}).toThrow(
Expand All @@ -81,50 +52,41 @@ describe('Pinecone', () => {
});

describe('optional properties', () => {
test('should not throw when optional properties provided: fetchAPI', () => {
test('should not throw when optional properties provided: fetchAPI, hostUrl', () => {
expect(() => {
new Pinecone({
environment: 'test-env',
apiKey: 'test-key',
fetchApi: utils.getFetch({} as PineconeConfiguration),
hostUrl: 'https://foo-bar.io',
} as PineconeConfiguration);
}).not.toThrow();
});
});

describe('configuration with environment variables', () => {
beforeEach(() => {
delete process.env.PINECONE_ENVIRONMENT;
delete process.env.PINECONE_API_KEY;
delete process.env.PINECONE_PROJECT_ID;
});

test('should read required properties from environment variables if no config object provided', () => {
process.env.PINECONE_ENVIRONMENT = 'test-env';
process.env.PINECONE_API_KEY = 'test-api';

const client = new Pinecone();

expect(client).toBeDefined();
expect(client.getConfig().environment).toEqual('test-env');
expect(client.getConfig().apiKey).toEqual('test-api');
expect(client.getConfig().projectId).toEqual(undefined);
});

test('config object should take precedence when both config object and environment variables are provided', () => {
process.env.PINECONE_ENVIRONMENT = 'test';
process.env.PINECONE_API_KEY = 'test';
const client = new Pinecone({
environment: 'test2',
apiKey: 'test2',
});
expect(client).toBeDefined();
expect(client.getConfig().environment).toEqual('test2');
expect(client.getConfig().apiKey).toEqual('test2');
});

test('should throw an error if required environment variable is not set', () => {
process.env.PINECONE_ENVIRONMENT = 'test';
delete process.env.PINECONE_API_KEY;
expect(() => new Pinecone()).toThrow(
"Since you called 'new Pinecone()' with no configuration object, we attempted to find client configuration in environment variables but the required environment variables were not set. Missing variables: PINECONE_API_KEY. You can find the configuration values for your project in the Pinecone developer console at https://app.pinecone.io"
Expand All @@ -140,7 +102,7 @@ describe('Pinecone', () => {
description: string;
};

const p = new Pinecone({ apiKey: 'foo', environment: 'bar' });
const p = new Pinecone({ apiKey: 'foo' });
const i = p.index<ProductMetadata>('product-embeddings');

const result = await i.fetch(['1']);
Expand Down
1 change: 0 additions & 1 deletion src/data/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('Index', () => {
beforeEach(() => {
config = {
apiKey: 'test-api-key',
environment: 'test-environment',
};
});

Expand Down
79 changes: 0 additions & 79 deletions src/data/__tests__/projectIdSingleton.test.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/data/__tests__/vectorOperationsProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('VectorOperationsProvider', () => {
test('makes no API calls on instantiation', async () => {
const config = {
apiKey: 'test-api-key',
environment: 'gcp-free',
};
new VectorOperationsProvider(config, 'index-name');
expect(HostUrlSingleton.getHostUrl).not.toHaveBeenCalled();
Expand All @@ -29,7 +28,6 @@ describe('VectorOperationsProvider', () => {
test('api calls occur only the first time the provide method is called', async () => {
const config = {
apiKey: 'test-api-key',
environment: 'gcp-free',
};
const provider = new VectorOperationsProvider(config, 'index-name');
expect(HostUrlSingleton.getHostUrl).not.toHaveBeenCalled();
Expand Down
108 changes: 0 additions & 108 deletions src/data/projectIdSingleton.ts

This file was deleted.

Loading

0 comments on commit eb36f2b

Please sign in to comment.