Skip to content

[spruce] Bump @pinecone-database version to support global control plane - #4

Merged
austin-denoble merged 3 commits into
sprucefrom
adenoble/update-recommender-for-gcps
Jan 16, 2024
Merged

[spruce] Bump @pinecone-database version to support global control plane#4
austin-denoble merged 3 commits into
sprucefrom
adenoble/update-recommender-for-gcps

Conversation

@austin-denoble

Copy link
Copy Markdown
Contributor

Problem

We've been working to support the new global control plane service in the Pinecone clients. We need to update our sample apps to migrate to the new client versions, and update associated code paths as needed.

Solution

  • Update README.md, .env.example, and validateEnvironmentVariables() to remove PINECONE_ENVIRONMENT.
  • Update index.ts to handle the new listIndexes() response shape, and passing the proper config to createIndex(). Update relevant snippets in README.md.

I also took a pass at some minor cleanup not directly related to the upgrade:

  • Ran prettier across the codebase, some stuff was oddly formatted.
  • Using validateEnvironmentVariables() relevant code is run (index.ts, and recommend.ts). This is minor as getEnv() will throw in the same way, but the validation util wasn't used at all.
  • Removed duplicate sliceIntoChunks() function.
  • Fixed an apparent issue in chunkedUpsert() where chunks.map(async (chunk) => ...) was upserting vectors and not the specific chunk.

For now, I've created a spruce branch to merge this into as we probably don't want to release sample apps that aren't aligned with what's available publicly.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Test Plan

There are no unit tests associated with this project, so testing manually is required. I tested both the embedding and upsert path along with the recommendations path, and they seem to work as we'd expect. We should add some level of testing and validation to this app at some point.

Validate embedding and upsert

npm run index
Screenshot 2023-12-20 at 2 13 24 PM

Validate recommendations

npm run recommend -- --query="Xbox" --section="Games ![Screenshot 2023-12-20 at 2 14 04 PM](https://github.com/pinecone-io/recommender-example-typescript/assets/119623786/01fd23a8-4ce6-4acc-8ce5-bda9f7fc29b5) "

Comment thread src/index.ts
import { chunkedUpsert } from "./utils/chunkedUpsert.ts";

dotenv.config();
validateEnvironmentVariables();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added validation here.

Comment thread src/index.ts
const indexList = await pinecone.listIndexes();
if (indexList.indexOf({ name: indexName }) === -1) {
await pinecone.createIndex({ name: indexName, dimension: 384, waitUntilReady: true })
if (!indexList.indexes?.some((index) => index.name === indexName)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to handle listIndexes() response and the createIndex() call below now includes spec.

Comment thread src/recommend.ts
const description = await pinecone.describeIndex(indexName);
if (!description.status?.ready) {
throw `Index not ready, description was ${JSON.stringify(description)}`
throw new Error(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint was complaining about not throwing an Error here.

@@ -1,34 +1,29 @@
import type { Index, PineconeRecord } from '@pinecone-database/pinecone';
import type { Index, PineconeRecord } from "@pinecone-database/pinecone";
import { sliceIntoChunks } from "./util.ts";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sliceIntoChunks function below was a duplicate of what we have in utils.

await Promise.allSettled(
chunks.map(async (chunk) => {
try {
await index.namespace(namespace).upsert(chunk);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we were upserting vectors instead of the chunk itself.

@rschwabco rschwabco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the hard coded region/cloud - lgtm

@austin-denoble

Copy link
Copy Markdown
Contributor Author

Other than the hard coded region/cloud - lgtm

PINECONE_CLOUD and PINECONE_REGION have been added as env variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants