This guide shows you how to set up a Pinecone vector database in minutes.

Before you begin

1. Install a Pinecone client

Pinecone exposes a simple REST API for interacting with its vector database. You can use the API directly, or you can use one of the official Python or Node.js clients:

2. Get your API key

You need an API key to make API calls to your Pinecone project. To get your key, follow these steps:

  1. Open the Pinecone Console.
  2. Go to API Keys.
  3. Copy your API key.

3. Initialize your client connection

Using your API key, initialize your client connection to Pinecone:

When using the API directly, each HTTP request must contain an Api-Key header that specifies your API key. You’ll see this in all subsequent curl examples.

4. Create a serverless index

In Pinecone, you store vector embeddings in indexes. The vectors in any index you create must share the same dimensionality and distance metric for measuring similarity.

Use the following code to create a serverless index named “quickstart” that performs nearest-neighbor search using the Euclidean distance similarity metric for vectors of 8 dimensions:

5. Upsert vectors

Now that you’ve created your index, upsert sample vectors into 2 distinct namespaces.

Namespaces let you partition vectors within a single index. Although optional, they are a best practice for speeding up queries, which can be filtered by namespace, and for complying with multi-tenancy requirements.

  1. Create a client instance that targets the “quickstart” index:

  2. Use the upsert operation to write 8 8-dimensional vectors into 2 distinct namespaces:

When upserting larger amounts of data, upsert data in batches of 100-500 vectors over multiple upsert requests.

6. Check the index

Pinecone is eventually consistent, so there can be a delay before your upserted vectors are available to query. Use the describe_index_stats operation to check if the current vector count matches the number of vectors you upserted:

Query each namespace in your index for the 3 vectors that are most similar to an example 8-dimensional vector using the Euclidean distance metric you specified for the index:

This is a simple example. As you put more demands on Pinecone, you’ll see it returning low-latency, accurate results at huge scales, with indexes of up to billions of vectors.

8. Clean up

When you no longer need the “quickstart” index, use the delete_index operation to delete it:

After you delete an index, you cannot use it again or recover it.

Next steps

Now that you have a serverless index and experience with basic Pinecone operations, check out our notebooks anbd sample applications using common AI patterns, tools, and algorithms, or start upserting your own vector embeddings.

Was this page helpful?