Quickstart
Pinecone is a managed, cloud-native vector database with a streamlined API and no infrastructure hassles that provides long-term memory for high-performance AI applications.
This guide shows you how to set up and use Pinecone in minutes.
To get started in your browser, use the “Pinecone quickstart” colab notebook.
1. Get an API key
You need an API key to make calls to your Pinecone project. Connect with Pinecone to generate a key:
If you don’t have a Pinecone account, this will also sign you up for the free Starter plan.
Copy your generated key:
PINECONE_API_KEY="{{YOUR_API_KEY}}"
Alternatively, you can create an new API key in the Pinecone console.
2. Install a Pinecone SDK
Pinecone exposes a simple REST API for interacting with your vector database. You can use the API directly or one of the official Pinecone SDKs:
3. Initialize a client
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
An index defines the dimension of vectors to be stored and the similarity metric to be used when querying them. Normally, you choose a dimension and similarity metric based on the embedding model used to create your vectors. For this quickstart, however, you’ll use a configuration that makes it easy to verify your query results.
Create a serverless index named example-index
that stores vectors of 2 dimensions and performs nearest-neighbor search using the cosine similarity metric:
In this Quickstart, you are creating a serverless index in the us-east-1
region of AWS (the default). Pinecone supports multiple cloud providers and regions.
5. Upsert vectors
Within an index, vectors are stored in namespaces, and all upserts, queries, and other data operations always target one namespace:
Now that you’ve created your index, target the example-index
index and use the upsert
operation to write six 2-dimensional vectors into 2 distinct namespaces:
When upserting larger amounts of data, it is recommended to upsert records in large batches. This should be as large as possible (up to 1000 records) without exceeding the maximum request size of 2MB.
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:
6. Run a similarity search
Query each namespace in your index for the 3 vectors that are most similar to an example 2-dimensional query vector:
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.
7. Clean up
When you no longer need the “example-index” index, use the delete_index
operation to delete it:
For production indexes, consider enabling deletion protection.
Next steps
Check out the following examples and sample apps to see how you can use your serverless index:
Was this page helpful?