Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/fix-edge
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamon authored May 5, 2023
2 parents 7680a4f + 7ac4e15 commit dfa2935
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# For testing purposes only
API_KEY=""
ENVIRONMENT=""
PINECONE_API_KEY=""
PINECONE_ENVIRONMENT=""
38 changes: 38 additions & 0 deletions .github/workflows/PR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Pinecone CI

on:
pull_request: {}
push:
branches:
- main
workflow_dispatch:

jobs:
run-tests:
name: Run integration tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.20.0
- name: Cache NPM dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
- name: Install npm packages
run: |
npm install --ignore-scripts
- name: Build typescript
run: |
npm run build
- name: Run tests
env:
CI: true
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
PINECONE_ENVIRONMENT: ${{ secrets.PINECONE_ENVIRONMENT }}
run: |
npm run test
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

# Pinecone Node.js Client

This is the Node.js client for Pinecone, written in Typescript. It is a wrapper around the Pinecone OpenAPI spec.

[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/Naereen/StrapDown.js/graphs/commit-activity)
[![Tests](https://github.com/pinecone-io/pinecone-ts-client/actions/workflows/PR.yml/badge.svg?branch=main)](https://github.com/pinecone-io/pinecone-ts-client/actions/workflows/PR.yml)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/pinecone-io/pinecone-ts-client/graphs/commit-activity)
[![Npm package version](https://badgen.net/npm/v/pinecone-ts-client)](https://npmjs.com/package/@pinecone-database/pinecone)

> **_⚠️ Warning_**
Expand Down
95 changes: 39 additions & 56 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import { QueryRequest, CreateRequest, UpdateRequest, UpsertRequest, CreateCollectionRequest, IndexMeta } from '../dist/pinecone-generated-ts-fetch'
import { afterAll, beforeAll, describe, expect } from '@jest/globals';
import { uniqueNamesGenerator, adjectives, animals } from 'unique-names-generator';
import { generateVectors, getRandomVector, waitUntilCollectionIsReady, waitUntilCollectionIsTerminated, waitUntilIndexIsReady, waitUntilIndexIsTerminated } from '../utils/helpers'
import { cleanupEverything, generateVectors, getRandomVector, waitUntilCollectionIsReady, waitUntilCollectionIsTerminated, waitUntilIndexIsReady, waitUntilIndexIsTerminated } from '../utils/helpers'
import dotenv from 'dotenv'
import { PineconeClient } from '../dist';

dotenv.config()
const apiKey = process.env.API_KEY!
const environment = process.env.ENVIRONMENT!
const apiKey = process.env.PINECONE_API_KEY!
const environment = process.env.PINECONE_ENVIRONMENT!

if (!apiKey || !environment) {
throw new Error("You must set PINECONE_API_KEY and PINECONE_ENVIRONMENT environment variables before running tests")
}

jest.useRealTimers();

Expand All @@ -19,27 +23,34 @@ const quantity = 10
const metric = 'dotproduct'
const vectors = generateVectors(dimensions, quantity)
const vectorsWithSparseValues = generateVectors(dimensions, quantity, true)
const client: PineconeClient = new PineconeClient()

beforeEach(() => {
jest.setTimeout(100000)
})

beforeAll(async () => {
const configuration = {
environment,
apiKey
}
await client.init(configuration)

// Defensively clean up any resources that may have been left behind
// by a previous test run that did not cleanup properly.
await cleanupEverything(client)
})

describe('Pinecone Client Index Operations', () => {
const client: PineconeClient = new PineconeClient()
afterAll(async () => {
await cleanupEverything(client)
})

const indexName = uniqueNamesGenerator({
dictionaries: [adjectives, animals],
separator: '-',
});


beforeEach(() => {
jest.setTimeout(100000)
})

beforeAll(async () => {
const configuration = {
environment,
apiKey
}
await client.init(configuration)
})

it('should create index', async () => {
const createRequest: CreateRequest = {
name: indexName,
Expand All @@ -60,7 +71,6 @@ describe('Pinecone Client Index Operations', () => {
namespace
}
await index.upsert({ upsertRequest })

const queryRequest: QueryRequest = {
topK: 1,
vector: getRandomVector(vectors).values,
Expand All @@ -69,7 +79,6 @@ describe('Pinecone Client Index Operations', () => {

const queryResponse = await index.query({ queryRequest })
expect(queryResponse?.matches?.length).toBeGreaterThan(0)

})

it('should be able to upsert a vector with sparse values', async () => {
Expand All @@ -89,7 +98,6 @@ describe('Pinecone Client Index Operations', () => {

const queryResponse = await index.query({ queryRequest })
expect(queryResponse?.matches?.length).toBeGreaterThan(0)

})

it('should be able to query a vector', async () => {
Expand Down Expand Up @@ -176,18 +184,12 @@ describe('Pinecone Client Index Operations', () => {
})
expect(Object.keys(fetchResult.vectors as object).length).toBe(0)
})

afterAll(done => {
async () => {
await client.deleteIndex({ indexName })
}
done()
})
})


describe('Pinecone Client Control Plane operations', () => {
const client: PineconeClient = new PineconeClient()
afterAll(async () => {
await cleanupEverything(client)
})

const indexName = uniqueNamesGenerator({
dictionaries: [adjectives, animals],
Expand All @@ -196,19 +198,6 @@ describe('Pinecone Client Control Plane operations', () => {

const collectionName = `${indexName}-collection`


beforeEach(() => {
jest.setTimeout(1000000)
})

beforeAll(async () => {
const configuration = {
environment,
apiKey
}
await client.init(configuration)
})

it('should create index', async () => {
const createRequest: CreateRequest = {
name: indexName,
Expand All @@ -222,14 +211,12 @@ describe('Pinecone Client Control Plane operations', () => {
expect(list).toContain(indexName)
})


it('created index should be listed', async () => {
const list = await client.listIndexes()
expect(list).toContain(indexName)

})

it('should be able to describe and index ', async () => {
it('should be able to describe an index', async () => {
const indexDescriptionResult = await client.describeIndex({
indexName
})
Expand All @@ -246,39 +233,35 @@ describe('Pinecone Client Control Plane operations', () => {
await client.createCollection({
createCollectionRequest
})
waitUntilCollectionIsReady(client, collectionName)
await waitUntilCollectionIsReady(client, collectionName)
const list = await client.listCollections()
expect(list).toContain(collectionName)
})

it('should be able to list collections', async () => {
waitUntilCollectionIsReady(client, collectionName)
await waitUntilCollectionIsReady(client, collectionName)
const list = await client.listCollections()
expect(list).toContain(collectionName)
})

it('should be able to describe collection', async () => {
waitUntilCollectionIsReady(client, collectionName)
await waitUntilCollectionIsReady(client, collectionName)
const describeCollectionResult = await client.describeCollection({ collectionName })
expect(describeCollectionResult?.name).toEqual(collectionName)
})

xit('should be able to delete a collection', async () => {
waitUntilCollectionIsReady(client, collectionName)
it('should be able to delete a collection', async () => {
await waitUntilCollectionIsReady(client, collectionName)
await client.deleteCollection({ collectionName })
waitUntilCollectionIsTerminated(client, collectionName)
await waitUntilCollectionIsTerminated(client, collectionName)
const list = await client.listCollections()
expect(list).not.toContain(collectionName)
})

xit('should be able to delete an index', async () => {

it('should be able to delete an index', async () => {
await client.deleteIndex({ indexName })
await waitUntilIndexIsTerminated(client, indexName)
const list = await client.listIndexes()
expect(list).not.toContain(indexName)
})
})



14 changes: 14 additions & 0 deletions utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,18 @@ export const waitUntilCollectionIsTerminated = async (client: PineconeClient, co
else {
return
}
}

export const cleanupEverything = async (client: PineconeClient) => {
// Delete all indexes and collections
const listIndexes = await client.listIndexes()
for (const index of listIndexes) {
await client.deleteIndex({ indexName: index })
await waitUntilIndexIsTerminated(client, index)
}
const listCollections = await client.listCollections()
for (const collection of listCollections) {
await client.deleteCollection({ collectionName: collection })
await waitUntilCollectionIsTerminated(client, collection)
}
}

0 comments on commit dfa2935

Please sign in to comment.