Pinecone Database quickstart
This guide shows you how to set up and use Pinecone Database for high-performance similarity search.
To get started in your browser, use the Quickstart colab notebook. To try Pinecone Database locally before creating an account, use Pinecone Local.
1. Install an SDK
Pinecone provides SDKs in multiple languages. For this quickstart, install the Python SDK:
2. Get an API key
You need an API key to make calls to your Pinecone project.
Create a new API key in the Pinecone console, or use the widget below to generate a key. If you don’t have a Pinecone account, the widget will sign you up for the free Starter plan.
Your generated API key:
3. Generate vectors
enable similarity-based search in vector databases like Pinecone. To convert data into this format, you use an embedding model.
For this quickstart, use the multilingual-e5-large
embedding model hosted by Pinecone to convert four sentences about apples into vectors, three related to health, one related to cultivation.
The returned object looks like this:
4. Create an index
In Pinecone, you store data in an index.
Create a serverless index that matches the dimension (1024
) and similarity metric (cosine
) of the multilingual-e5-large
model you used in the previous step, and choose a cloud and region for hosting the index:
5. Upsert vectors
Target your index and use the upsert
operation to load your vectors into a new namespace. Namespaces let you partition records within an index and are essential for implementing multitenancy when you need to isolate the data of each customer/user.
To load large amounts of data, import from object storage or upsert in large batches.
Pinecone is eventually consistent, so there can be a delay before your upserted records are available to query. Use the describe_index_stats
operation to check if the current vector count matches the number of vectors you upserted (4):
The response looks like this:
6. Search the index
Now, let’s say you want to search your index for information related to “health risks”.
Use the multilingual-e5-large
embedding model hosted by Pinecone to convert your query into a vector, and then use the query
operation to search for the three vectors that are most semantically similar to the query vector:
The response includes only records related to health, not the cultivation of apples:
Add reranking
You can increase the accuracy of your search by reranking results based on their relevance to the query.
Use the rerank
operation and the bge-reranker-v2-m3
reranking model hosted by Pinecone to rerank the values of the documents.source_text
fields:
The two records specifically related to “health risks” (chronic disease and diabetes) are now ranked highest:
Add filtering
You can use a metadata filter to limit your search to records matching a filter expression.
Your upserted records contain a category
metadata field. Now use that field as a filter to search for records in the “digestive system” category:
The response includes only the one record in the “digestive system” category:
7. Clean up
When you no longer need your example-index
, delete it as follows:
For production indexes, consider enabling deletion protection.
Next steps
-
Learn more about key features to keep in mind as you start building with Pinecone.
-
Check out tutorials and sample apps for different use cases.
Was this page helpful?