pinecone-client.ts 650 B

1234567891011121314151617181920212223
  1. import { PineconeClient } from '@pinecone-database/pinecone';
  2. if (!process.env.PINECONE_ENVIRONMENT || !process.env.PINECONE_API_KEY) {
  3. throw new Error('Pinecone environment or api key vars missing');
  4. }
  5. async function initPinecone() {
  6. try {
  7. const pinecone = new PineconeClient();
  8. await pinecone.init({
  9. environment: process.env.PINECONE_ENVIRONMENT ?? '', //this is in the dashboard
  10. apiKey: process.env.PINECONE_API_KEY ?? '',
  11. });
  12. return pinecone;
  13. } catch (error) {
  14. console.log('error', error);
  15. throw new Error('Failed to initialize Pinecone Client');
  16. }
  17. }
  18. export const pinecone = await initPinecone();